feat(game): implement MatchManager for game rules and state

This commit is contained in:
Vladimir V Maksimov
2026-05-12 11:04:19 +03:00
parent aece34fe73
commit 11e5bd952e

View File

@@ -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
}
}