aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2025-07-24 12:12:13 -0400
committerFlorian Fischer <florian.fischer@muhq.space>2025-07-28 18:03:10 +0200
commitce875a8454265ac4a17be25eeaa6e0b136936a56 (patch)
treee8f5127d9ace8fabf22bf2d67efc93ceae88174c
parentc679ff0252eb9b8aebf448100fc39b82be8cf092 (diff)
downloadmuhqs-game-ce875a8454265ac4a17be25eeaa6e0b136936a56.tar.gz
muhqs-game-ce875a8454265ac4a17be25eeaa6e0b136936a56.zip
show the winner after the game is done
-rw-r--r--go/client/game.go32
1 files changed, 30 insertions, 2 deletions
diff --git a/go/client/game.go b/go/client/game.go
index 5718371b..71fa6b4c 100644
--- a/go/client/game.go
+++ b/go/client/game.go
@@ -8,6 +8,7 @@ import (
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
+ "muhq.space/muhqs-game/go/activities"
"muhq.space/muhqs-game/go/game"
"muhq.space/muhqs-game/go/ui"
"muhq.space/muhqs-game/go/utils"
@@ -55,6 +56,8 @@ type Game struct {
ui.Collection
activePlayerId int
+ winners []*game.Player
+ done bool
playerCtrl *game.ChanPlayerControl
hasPriority bool
@@ -198,6 +201,23 @@ func (g *Game) initPlayerUi(player *game.Player) *Game {
return g
}
+func (g *Game) showWinners() {
+ g.done = true
+ msg := g.winners[0].Name
+ for _, p := range g.winners[1:] {
+ msg = msg + fmt.Sprintf(", %s", p.Name)
+ }
+ msg = msg + " won"
+ g.AddWidget(ui.NewFixedTextBox(0, g.Height/2, g.Width, ui.PROMPT_HEIGHT, msg).Centering(true))
+
+ g.passButton.Bg = ui.HighlightSelectionColor
+ g.passButton.UpdateLabel("back")
+ g.passButton.RegisterHandler("click", func(int, int) {
+ activities.PopActivity()
+ })
+
+}
+
func (g *Game) showStore() {
if g.storeVisible {
return
@@ -627,6 +647,15 @@ func (g *Game) Update() error {
return err
}
+ // We are done. Skip the rest.
+ // Especially updating the button resetting the new passButton label.
+ if g.done {
+ return nil
+ } else if len(g.winners) > 0 {
+ g.showWinners()
+ return nil
+ }
+
g.handlePlayerNotifications()
if err := g.handleKeyBindings(g.keyBindings); err != nil {
@@ -649,8 +678,7 @@ func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
func (g *Game) Start() *Game {
go func() {
- w := g.gameState.Loop()
- log.Println("Winners are", w)
+ g.winners = g.gameState.Loop()
}()
return g