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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
package game
import (
"image/color"
)
const (
MAX_DRAW int = 3
)
type Player struct {
Id int
Name string
Turn int
Resource int
DrawPerTurn int
Hand *Hand
DiscardPile *DiscardPile
Deck *Deck
Store *Store
gameState *State
Color color.Color
Ctrl PlayerControl
}
func NewPlayer(id int, name string, deck *Deck,
gameState *State, color color.Color,
) *Player {
store := NewStore()
deck.MoveInto(store)
p := Player{
Id: id,
Name: name,
Turn: 0,
Resource: 0,
DrawPerTurn: MAX_DRAW,
Hand: NewHand(),
DiscardPile: NewDiscardPile(),
Deck: NewDeckFromDeckList(gameState.Map.StartDeckList),
Store: store,
gameState: gameState,
Color: color,
Ctrl: nil,
}
return &p
}
func (p *Player) resourceGain() int {
if p.Name == "The kraken" {
return p.gameState.Map.ResourceGain * (len(p.gameState.Players) - 1)
} else {
return p.gameState.Map.ResourceGain
}
}
func (p *Player) Upkeep() {
p.Resource += p.resourceGain()
// TODO: handle upkeep triggers
for _, unit := range p.gameState.Units {
if unit.Controller != p {
continue
}
// TODO: let players decide if they want to pay the upkeep
p.Resource -= unit.Upkeep
// TODO: better refresh unit actions
unit.AvailAttackActions = 1
unit.AvailMoveActions = 1
}
}
func (p *Player) ActionPhase() {
for {
a := promptAction(p.Ctrl)
if _, ok := a.(*PassPriorityAction); ok {
return
}
p.gameState.DeclareAction(a)
p.gameState.Stack.Resolve()
}
}
func (p *Player) buy(c *Card) {
p.Resource -= c.BuyCost
p.DiscardPile.AddCard(c)
}
func (p *Player) BuyPhase() {
a := promptBuy(p.Ctrl)
if _, ok := a.(*PassPriorityAction); ok {
return
}
p.gameState.DeclareAction(a)
p.gameState.Stack.Resolve()
// TODO: select card to buy
}
func (p *Player) DiscardCard(c *Card) {
p.Hand.MoveCard(c, p.DiscardPile)
}
func (p *Player) DiscardPhase() {
// TODO: select cards to discard
}
func (p *Player) Draw() {
toDraw := p.DrawPerTurn - p.Hand.Size()
if toDraw < 1 {
return
}
p.DrawN(toDraw)
}
func (p *Player) DrawN(n int) {
drawnCards := p.Deck.Draw(n)
p.Hand.AddCards(drawnCards)
}
|