From 11e5bd952e2567999e915366518b9358775afa38 Mon Sep 17 00:00:00 2001 From: Vladimir V Maksimov Date: Tue, 12 May 2026 11:04:19 +0300 Subject: [PATCH] feat(game): implement MatchManager for game rules and state --- internal/game/match_manager.go | 66 ++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 internal/game/match_manager.go diff --git a/internal/game/match_manager.go b/internal/game/match_manager.go new file mode 100644 index 0000000..a8f293b --- /dev/null +++ b/internal/game/match_manager.go @@ -0,0 +1,66 @@ +package game + +import ( + "github.com/soer/football/internal/entities" +) + +type GameState int + +const ( + Playing GameState = iota + GoalPause + MatchEnded +) + +type MatchManager struct { + World *World + ScoreRed int + ScoreBlue int + State GameState + MatchDuration float64 + CurrentTime float64 + PauseDuration float64 + PauseTimer float64 +} + +func NewMatchManager(world *World, matchDuration, pauseDuration float64) *MatchManager { + return &MatchManager{ + World: world, + State: Playing, + MatchDuration: matchDuration, + PauseDuration: pauseDuration, + } +} + +func (m *MatchManager) Update() { + switch m.State { + case Playing: + team, scored := m.World.CheckGoal() + if scored { + if team == entities.TeamRed { + m.ScoreRed++ + } else { + m.ScoreBlue++ + } + m.State = GoalPause + m.PauseTimer = m.PauseDuration + } else { + m.World.Update() + m.CurrentTime += 1.0 + } + + if m.CurrentTime >= m.MatchDuration { + m.State = MatchEnded + } + + case GoalPause: + m.PauseTimer -= 1.0 + if m.PauseTimer <= 0 { + m.World.ResetPositions() + m.State = Playing + } + + case MatchEnded: + // Do nothing + } +}