diff options
Diffstat (limited to 'go/game/action.go')
| -rw-r--r-- | go/game/action.go | 59 |
1 files changed, 34 insertions, 25 deletions
diff --git a/go/game/action.go b/go/game/action.go index f3b242b5..a2ca038e 100644 --- a/go/game/action.go +++ b/go/game/action.go @@ -6,7 +6,7 @@ import ( ) type ActionPrototype interface { - Specialize(...interface{}) Action + Specialize(*State, ...interface{}) Action String() string } @@ -16,12 +16,21 @@ type Action interface { String() string } -type PassPriorityAction struct{ Source *Player } +type PassPriority struct{ Source *Player } -func (*PassPriorityAction) Resolve(*State) {} -func (*PassPriorityAction) PayCosts(*State) bool { return true } -func (*PassPriorityAction) String() string { return "pass" } -func NewPassPriorityAction(p *Player) Action { return &PassPriorityAction{p} } +func (*PassPriority) Resolve(*State) {} +func (*PassPriority) PayCosts(*State) bool { return true } +func (*PassPriority) String() string { return "pass" } +func NewPassPriority(p *Player) Action { return &PassPriority{p} } + +type HandCardSelection struct { + cards []*Card +} + +func (*HandCardSelection) Resolve(*State) {} +func (*HandCardSelection) PayCosts(*State) bool { return true } +func (*HandCardSelection) String() string { return "hand card selection" } +func NewHandCardSelection(cards []*Card) Action { return &HandCardSelection{cards} } type ActionBase struct { Source interface{} @@ -44,7 +53,7 @@ func (a *ActionBase) String() string { switch source := a.Source.(type) { case Permanent: p := source - return fmt.Sprintf("%s: %s %s", p.GetController().Name, p.GetTile().Position.String(), a.desc) + return fmt.Sprintf("%s: %s %s", p.Controller().Name, p.Tile().Position.String(), a.desc) case *Player: return fmt.Sprintf("%s %s", source.Name, a.desc) default: @@ -58,7 +67,7 @@ type PlayAction struct { func NewPlayAction(p *Player, c *Card, targets interface{}) Action { costFunc := func(*State) bool { - cost := c.GetPlayCosts() + cost := c.PlayCosts() if p.Resource < cost { return false @@ -98,7 +107,7 @@ func (proto *MoveActionPrototype) String() string { return fmt.Sprintf("move %s", proto.Unit.Movement.String()) } -func (proto *MoveActionPrototype) Specialize(args ...interface{}) Action { +func (proto *MoveActionPrototype) Specialize(s *State, args ...interface{}) Action { target := args[0].(*Tile) u := proto.Unit @@ -115,7 +124,7 @@ func (proto *MoveActionPrototype) Specialize(args ...interface{}) Action { } desc := fmt.Sprintf("-> %s", target.Position.String()) - return &MoveAction{ActionBase{u, u.GetCard(), target, resolveFunc, costFunc, desc}} + return &MoveAction{ActionBase{u, u.Card(), target, resolveFunc, costFunc, desc}} } type AttackAction struct { @@ -134,7 +143,7 @@ func (proto *AttackActionPrototype) String() string { return fmt.Sprintf("attack %s", proto.Unit.Attack.String()) } -func (proto *AttackActionPrototype) Specialize(args ...interface{}) Action { +func (proto *AttackActionPrototype) Specialize(s *State, args ...interface{}) Action { target := args[0].(Permanent) u := proto.Unit @@ -150,25 +159,26 @@ func (proto *AttackActionPrototype) Specialize(args ...interface{}) Action { return true } - desc := fmt.Sprintf("x %s", target.GetTile().Position.String()) - return &AttackAction{ActionBase{u, u.GetCard(), target, resolveFunc, costFunc, desc}} + desc := fmt.Sprintf("x %s", target.Tile().Position.String()) + return &AttackAction{ActionBase{u, u.Card(), target, resolveFunc, costFunc, desc}} } type FullActionPrototype struct { - Unit *Unit + Unit *Unit + resolveFuncPrototype func(*State, *Unit) func(*State) } -func NewFullActionPrototype(u *Unit) *FullActionPrototype { - return &FullActionPrototype{u} +func NewFullActionPrototype(u *Unit, proto func(*State, *Unit) func(*State)) *FullActionPrototype { + return &FullActionPrototype{u, proto} } func (proto *FullActionPrototype) String() string { return "full_action" } -func (proto *FullActionPrototype) Specialize(args ...interface{}) Action { +func (proto *FullActionPrototype) Specialize(s *State, args ...interface{}) Action { u := proto.Unit - resolveFunc := args[0].(func(s *State)) + resolveFunc := proto.resolveFuncPrototype(s, u) costFunc := func(*State) bool { if u.AvailAttackActions < 1 && u.AvailMoveActions < 1 { return false @@ -178,24 +188,23 @@ func (proto *FullActionPrototype) Specialize(args ...interface{}) Action { return true } desc := "full_action" - return &ActionBase{u, u.GetCard(), nil, resolveFunc, costFunc, desc} + return &ActionBase{u, u.Card(), nil, resolveFunc, costFunc, desc} } type FreeActionPrototype struct { - Permanent Permanent - canPayFunc func(s *State) bool + Permanent Permanent } func (proto *FreeActionPrototype) String() string { return "free_action" } -func (proto *FreeActionPrototype) Specialize(args ...interface{}) Action { +func (proto *FreeActionPrototype) Specialize(s *State, args ...interface{}) Action { p := proto.Permanent resolveFunc := args[0].(func(s *State)) costFunc := args[1].(func(s *State) bool) desc := "free_action" - return &FreeAction{ActionBase{p, p.GetCard(), nil, resolveFunc, costFunc, desc}} + return &FreeAction{ActionBase{p, p.Card(), nil, resolveFunc, costFunc, desc}} } type FreeAction struct { @@ -252,10 +261,10 @@ func (a *UpkeepAction) PayCosts(*State) bool { func (a *UpkeepAction) String() string { if a.pay { - return fmt.Sprintf("%s keep %s", a.player.Name, a.unit.Tile.Position.String()) + return fmt.Sprintf("%s keep %s", a.player.Name, a.unit.Tile().Position.String()) } - return fmt.Sprintf("%s disband %s", a.player.Name, a.unit.Tile.Position.String()) + return fmt.Sprintf("%s disband %s", a.player.Name, a.unit.Tile().Position.String()) } func NewUpkeepAction(p *Player, u *Unit, pay bool) *UpkeepAction { |
