-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.go
58 lines (50 loc) · 942 Bytes
/
game.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
package desert
import (
"fmt"
)
type Game struct {
Id GameId
Name string
StormDeck *Deck
StormDiscard *Deck
GearDeck *Deck
GearDiscard *Deck
}
type GameAction struct {
Action string
}
func NewGame(id GameId, name string) *Game {
g := &Game{
Id: id,
Name: name,
StormDeck: NewStormDeck(),
GearDeck: NewGearDeck(),
StormDiscard: &Deck{},
GearDiscard: &Deck{},
}
g.StormDeck.Shuffle()
g.GearDeck.Shuffle()
return g
}
func (g *Game) HandleAction(a GameAction) error {
switch a.Action {
case "stormdraw":
g.DrawStormCard()
return nil
case "geardraw":
g.DrawGearCard()
return nil
default:
return fmt.Errorf("Unable to handle %s action", a.Action)
}
}
func (g *Game) DrawStormCard() Card {
c, _ := g.StormDeck.Draw()
g.StormDiscard.Add(c)
return c
}
func (g *Game) DrawGearCard() Card {
c, _ := g.GearDeck.Draw()
g.GearDiscard.Add(c)
return c
}