-
Notifications
You must be signed in to change notification settings - Fork 2
/
player.go
45 lines (39 loc) · 871 Bytes
/
player.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
package main
// Player represents connected to a game client which can have cards.
type Player struct {
Name string `json:"name"`
IsActive bool `json:"is_active"`
IsCompleted bool
client ClientSender
cards []*Card
}
func (p *Player) sendEvent(event interface{}) {
p.client.sendEvent(event)
}
func (p *Player) sendMessage(message []byte) {
p.client.sendMessage(message)
}
func newPlayer(client ClientSender, isActive bool) *Player {
return &Player{
Name: client.Nickname(),
IsActive: isActive,
client: client,
}
}
func (p *Player) removeCard(card *Card) {
cards := make([]*Card, 0)
for _, c := range p.cards {
if !c.equals(card) {
cards = append(cards, c)
}
}
p.cards = cards
}
func (p *Player) hasCard(card *Card) bool {
for _, c := range p.cards {
if c.equals(card) {
return true
}
}
return false
}