-
Notifications
You must be signed in to change notification settings - Fork 3
/
CardGameMessage.java
74 lines (73 loc) · 3.02 KB
/
CardGameMessage.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/**
* This class is used to model the message for a network card game.
*
* @author Kenneth Wong
*
*/
public class CardGameMessage extends GameMessage {
private static final long serialVersionUID = -4847411748052026276L;
/**
* Sent by the server to a client when a connection is established. In this
* message, playerID specifies the playerID of the local player, and data is
* a reference to a regular array of strings specifying the names of the
* players
*/
public static final int PLAYER_LIST = 0;
/**
* Sent by a client to the server when a connection is established. In this
* message, playerID specifies the playerID of the player, and data is
* simply null (not being used).
*/
public static final int JOIN = 1;
/**
* Sent by the server to a client after a connection is established but the
* server is not able to serve this client because it is full. In this
* message, playerID is -1 (not being used) and data is simply null (not
* being used).
*/
public static final int FULL = 2;
/**
* Broadcast by a server when a client loses connection to the server. In this message,
* playerID specifies the player who loses the connection to the server, and data is a string
* representation of the IP address and TCP port of this player.
*/
public static final int QUIT = 3;
/**
* Sent by a client to the server to indicate it is ready for a new game. The server will also
* broadcast this message upon receiving it. In this message, playerID specifies the player who
* becomes ready for a new game (for the message broadcast by the server) or -1 (for the message
* sent by a client), and data is simply null (not being used).
*/
public static final int READY = 4;
/**
* Broadcast by the server when all clients are ready for a new game. In this message, playerID is
* -1 (no being used), and data is a reference to a Deck object (a shuffled deck for the new game).
*/
public static final int START = 5;
/**
* Sent by a client when the local player makes a move. The server will broadcast this message upon
* receiving it. In this message, playerID specifies the player who makes the move, and data is a
* reference to an array of int specifying the indices of the cards being played.
*/
public static final int MOVE = 6;
/**
* Sent by a client to the server when the local player press [ENTER] in the chat input field.
* The server will first add the name, IP address and TCP port of the player into the chat
* message, and then broadcast the message. In this message, playerID specifies the player who
* sent this chat message, and data is a reference to a string containing a formated chat message.
*/
public static final int MSG = 7;
/**
* Creates and returns an instance of CardGameMessage.
*
* @param type
* the message type of this message
* @param playerID
* the playerID of this message
* @param data
* the data of this message
*/
public CardGameMessage(int type, int playerID, Object data) {
super(type, playerID, data);
}
}