diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2023-02-08 17:50:10 +0100 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2023-02-08 17:50:10 +0100 |
| commit | 23ecef83b28e9b51187fe34032e9558cf0eb5e05 (patch) | |
| tree | c55d54dd209509e376a4965782b9161243c1fd7d /go/game/playerControl.go | |
| parent | bd558df11dbe60c0bd310b95b26bf17ba06cab35 (diff) | |
| download | muhqs-game-rework-targets.tar.gz muhqs-game-rework-targets.zip | |
intermediate commitrework-targets
Diffstat (limited to 'go/game/playerControl.go')
| -rw-r--r-- | go/game/playerControl.go | 80 |
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()) } |
