aboutsummaryrefslogtreecommitdiff
path: root/go/game/playerControl.go
diff options
context:
space:
mode:
Diffstat (limited to 'go/game/playerControl.go')
-rw-r--r--go/game/playerControl.go80
1 files changed, 52 insertions, 28 deletions
diff --git a/go/game/playerControl.go b/go/game/playerControl.go
index e62d91b3..dda1a736 100644
--- a/go/game/playerControl.go
+++ b/go/game/playerControl.go
@@ -1,14 +1,17 @@
package game
+import (
+ "fmt"
+ "log"
+)
+
type PlayerNotificationType int
const (
DeclaredActionNotification = iota
ResolvedActionNotification
PriorityNotification
- UpkeepPrompt
- BuyPrompt
- HandCardSelectionPrompt
+ TargetSelectionPrompt
)
func (n PlayerNotification) IsPriorityNotification() bool {
@@ -21,72 +24,93 @@ type PlayerNotification struct {
Error error
}
-func NewPriorityNotification() PlayerNotification {
+func (n *PlayerNotification) String() string {
+ if n.Error != nil {
+ return fmt.Sprintf("error %v: %v", n.Notification, n.Error)
+ }
+
+ return fmt.Sprintf("%v: %v", n.Notification, n.Context)
+}
+
+type TargetSelectionCtx struct {
+ Action Action
+ Prompt string
+}
+
+func newPriorityNotification() PlayerNotification {
return PlayerNotification{PriorityNotification, nil, nil}
}
-func NewDeclaredActionNotification(a Action, err error) PlayerNotification {
+func newDeclaredActionNotification(a Action, err error) PlayerNotification {
return PlayerNotification{DeclaredActionNotification, a, err}
}
-func NewResolvedActionNotification(a Action, err error) PlayerNotification {
+func newResolvedActionNotification(a Action, err error) PlayerNotification {
return PlayerNotification{ResolvedActionNotification, a, err}
}
-func NewUpkeepPrompt(u *Unit) PlayerNotification {
- return PlayerNotification{ResolvedActionNotification, u, nil}
+func newTargetSelectionPrompt(a Action, desc string) PlayerNotification {
+ return PlayerNotification{TargetSelectionPrompt, TargetSelectionCtx{a, desc}, nil}
+}
+
+func newUpkeepPrompt(p *Player) PlayerNotification {
+ a := newUpkeepAction(p)
+ return newTargetSelectionPrompt(a, "Select units to disband")
}
-func NewBuyPrompt() PlayerNotification {
- return PlayerNotification{BuyPrompt, nil, nil}
+func newBuyPrompt(p *Player) PlayerNotification {
+ a := newBuyAction(p)
+ prompt := newTargetSelectionPrompt(a, "Select a card to buy")
+ log.Println("sending buy prompt with ctx", prompt)
+ return prompt
}
-func NewHandCardSelectionPrompt(min, max int) PlayerNotification {
- return PlayerNotification{HandCardSelectionPrompt, []int{min, max}, nil}
+func newHandCardSelectionPrompt(p *Player, min, max int) PlayerNotification {
+ a := newHandCardSelection(p, min, max)
+ desc := fmt.Sprintf("Select between %d and %d hand cards", min, max)
+ return newTargetSelectionPrompt(a, desc)
}
type PlayerControl interface {
+ Player() *Player
RecvAction() Action
SendNotification(PlayerNotification)
}
-type DummyPlayerControl struct{ P *Player }
-
-func (c *DummyPlayerControl) RecvAction() Action { return NewPassPriority(c.P) }
-func (*DummyPlayerControl) SendNotification(PlayerNotification) {}
-
type ChanPlayerControl struct {
- Actions chan Action
- Notifications chan PlayerNotification
+ player *Player
+ actions chan Action
+ notifications chan PlayerNotification
}
-func (c *ChanPlayerControl) SendAction(a Action) { c.Actions <- a }
-func (c *ChanPlayerControl) RecvAction() Action { return <-c.Actions }
-func (c *ChanPlayerControl) SendNotification(n PlayerNotification) { c.Notifications <- n }
+func (c *ChanPlayerControl) Player() *Player { return c.player }
+func (c *ChanPlayerControl) SendAction(a Action) { c.actions <- a }
+func (c *ChanPlayerControl) RecvAction() Action { return <-c.actions }
+func (c *ChanPlayerControl) SendNotification(n PlayerNotification) { c.notifications <- n }
func (c *ChanPlayerControl) RecvNotification() *PlayerNotification {
select {
- case n := <-c.Notifications:
+ case n := <-c.notifications:
return &n
default:
return nil
}
}
-func NewChanPlayerControl() *ChanPlayerControl {
+func NewChanPlayerControl(p *Player) *ChanPlayerControl {
a := make(chan Action)
n := make(chan PlayerNotification)
- return &ChanPlayerControl{a, n}
+ return &ChanPlayerControl{p, a, n}
}
func prompt(ctrl PlayerControl, notification PlayerNotification) Action {
- ctrl.SendNotification(NewPriorityNotification())
+ ctrl.SendNotification(notification)
return ctrl.RecvAction()
}
func promptBuy(ctrl PlayerControl) Action {
- return prompt(ctrl, NewBuyPrompt())
+ return prompt(ctrl, newBuyPrompt(ctrl.Player()))
}
func promptAction(ctrl PlayerControl) Action {
- return prompt(ctrl, NewPriorityNotification())
+ return prompt(ctrl, newPriorityNotification())
}