-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameEndMessagesCreator.java
57 lines (50 loc) · 1.59 KB
/
GameEndMessagesCreator.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
package messages;
import game.model.WinCheckerThread;
import messages.fields_names.GameFields;
import messages.fields_names.ServicesFields;
import org.json.JSONException;
import org.json.JSONObject;
/**
* Provides a builder for messages that the server has to send while the game is over.
*
* @author Micieli
* @date 2015/05/21
* @see WinCheckerThread
*/
public class GameEndMessagesCreator {
/**
* Generates message to inform about players who lose the game.
*
* @return the message to send
*/
public JSONObject generateLoseMessage() {
return generateEndMessage(GameFields.GAME_LOSE.toString());
}
/**
* Generates message to inform about players who win the game.
*
* @return the message to send
*/
public JSONObject generateWinMessage() {
return generateEndMessage(GameFields.GAME_WIN.toString());
}
/**
* Generates message to inform about players who draw the game.
*
* @return the message to send
*/
public JSONObject generateDrawMessage() {
return generateEndMessage(GameFields.GAME_DRAW.toString());
}
private JSONObject generateEndMessage(String status) {
JSONObject message = new JSONObject();
try {
message.put(ServicesFields.SERVICE.toString(), ServicesFields.GAME.toString());
message.put(ServicesFields.SERVICE_TYPE.toString(), GameFields.GAME_STATUS.toString());
message.put(GameFields.GAME_END.toString(), status);
} catch (JSONException e) {
e.printStackTrace();
}
return message;
}
}