blob: 169c8cb322fe889d022a39deb8c375ad2696b6dc (
plain)
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
|
package game
type Hand struct {
Cards []*Card
}
func NewHand() *Hand {
h := Hand{[]*Card{}}
return &h
}
func (h *Hand) Size() int {
return len(h.Cards)
}
func (h *Hand) AddCards(cards []*Card) {
h.Cards = append(h.Cards, cards...)
}
func (h *Hand) AddCard(card *Card) {
h.Cards = append(h.Cards, card)
}
func (h *Hand) RemoveCard(card *Card) {
ncards := len(h.Cards)
for i, c := range h.Cards {
if c != card {
continue
}
h.Cards[i] = h.Cards[ncards-1]
h.Cards = h.Cards[:ncards-1]
return
}
}
|