forked from kodestan/tank-ops
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessages.go
82 lines (61 loc) · 1.97 KB
/
messages.go
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
75
76
77
78
79
80
81
82
package main
type ServerMessageType int
const (
ServerStartGame ServerMessageType = 1
ServerTurnResults ServerMessageType = 2
ServerRoomJoined ServerMessageType = 3
ServerRoomDisconnected ServerMessageType = 4
ServerGameFinished ServerMessageType = 5
)
type ServerMessage interface {
isServerMessage()
}
type StartGameMessage struct {
Type ServerMessageType `json:"type"`
Config ClientConfig `json:"config"`
}
func (m StartGameMessage) isServerMessage() {}
type TurnResultsMessage struct {
Type ServerMessageType `json:"type"`
TurnResults []TurnResult `json:"turnResults"`
}
func (m TurnResultsMessage) isServerMessage() {}
type RoomJoinedMessage struct {
Type ServerMessageType `json:"type"`
}
func (m RoomJoinedMessage) isServerMessage() {}
type RoomDisconnectedMessage struct {
Type ServerMessageType `json:"type"`
}
func (m RoomDisconnectedMessage) isServerMessage() {}
type GameFinishedMessage struct {
Type ServerMessageType `json:"type"`
Result GameResult `json:"result"`
}
func (m GameFinishedMessage) isServerMessage() {}
func newStartGameMessage(config ClientConfig) StartGameMessage {
return StartGameMessage{ServerStartGame, config}
}
func newTurnResultsMessage(results []TurnResult) TurnResultsMessage {
return TurnResultsMessage{ServerTurnResults, results}
}
func newRoomJoinedMessage() RoomJoinedMessage {
return RoomJoinedMessage{ServerRoomJoined}
}
func newRoomDisconnectedMessage() RoomDisconnectedMessage {
return RoomDisconnectedMessage{ServerRoomDisconnected}
}
func newGameFinishedMessage(result GameResult) GameFinishedMessage {
return GameFinishedMessage{ServerGameFinished, result}
}
type ClientMessageType int
const (
ClientJoinRoom ClientMessageType = 1
ClientSendTurn ClientMessageType = 2
ClientQuitRoom ClientMessageType = 3
)
type ClientMessage struct {
Type ClientMessageType `json:"type"`
Actions []TankAction `json:"Actions"`
RoomCode string `json:"roomCode"`
}