aboutsummaryrefslogtreecommitdiff
path: root/go/ui/stateBar.go
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2024-12-27 12:40:19 +0100
committerFlorian Fischer <florian.fischer@muhq.space>2025-01-27 16:43:58 +0100
commit4e2ab55d345fd5e5c5d2d5bc56948611b15564d5 (patch)
treec6998ac54687c442ad0baa541edd0fbf917b1308 /go/ui/stateBar.go
parent5aa8e7ddbc41aed55e7918e6afaec0b5c07fa510 (diff)
downloadmuhqs-game-4e2ab55d345fd5e5c5d2d5bc56948611b15564d5.tar.gz
muhqs-game-4e2ab55d345fd5e5c5d2d5bc56948611b15564d5.zip
introduce game.State interface abstraction
This allows to not use the internal game state directly from client code.
Diffstat (limited to 'go/ui/stateBar.go')
-rw-r--r--go/ui/stateBar.go15
1 files changed, 8 insertions, 7 deletions
diff --git a/go/ui/stateBar.go b/go/ui/stateBar.go
index 1686b5e1..6f7aa986 100644
--- a/go/ui/stateBar.go
+++ b/go/ui/stateBar.go
@@ -10,24 +10,25 @@ import (
type StateBar struct {
X, Y int
Width, Height int
- gameState *game.State
- activePlayer *game.Player
+ gameState game.State
+ activePlayerId int
resourceView *TextBox
phaseView *TextBox
}
-func NewStateBar(x, y int, width, height int, s *game.State, p *game.Player) *StateBar {
- sb := &StateBar{x, y, width, height, s, p, nil, nil}
+func NewStateBar(x, y int, width, height int, s game.State, p *game.Player) *StateBar {
+ sb := &StateBar{x, y, width, height, s, p.Id, nil, nil}
return sb
}
func (sb *StateBar) resourceLabel() string {
- return fmt.Sprintf("%d/%+d", sb.activePlayer.Resource, sb.activePlayer.UpkeepGain())
+ activePlayer := sb.gameState.PlayerById(sb.activePlayerId)
+ return fmt.Sprintf("%d/%+d", activePlayer.Resource, activePlayer.UpkeepGain())
}
func (sb *StateBar) phaseLabel() string {
- return fmt.Sprintf("%s: %s", sb.gameState.ActivePlayer.Name,
- sb.gameState.ActivePhase.String())
+ return fmt.Sprintf("%s: %s", sb.gameState.ActivePlayer().Name,
+ sb.gameState.ActivePhase().String())
}
func (sb *StateBar) Draw(screen *ebiten.Image) {