Check for a game over after each score.

In case the home team just came from behind in the bottom of the final inning.
This commit is contained in:
Sage Vaillancourt 2025-02-23 18:17:09 -05:00
parent aa72d2a19f
commit 687bf74979
1 changed files with 11 additions and 5 deletions

View File

@ -241,8 +241,7 @@ function Game:pitcherIsReady()
) )
end end
function Game:nextHalfInning() function Game:checkForGameOver()
pitchTracker:reset()
local homeScore, awayScore = utils.totalScores(self.state.stats) local homeScore, awayScore = utils.totalScores(self.state.stats)
local isFinalInning = self.state.inning >= self.settings.finalInning local isFinalInning = self.state.inning >= self.settings.finalInning
local gameOver = isFinalInning and self.state.battingTeam == "home" and awayScore ~= homeScore local gameOver = isFinalInning and self.state.battingTeam == "home" and awayScore ~= homeScore
@ -254,6 +253,15 @@ function Game:nextHalfInning()
playdate.timer.new(3000, function() playdate.timer.new(3000, function()
transitionTo(BoxScore.new(self.state.stats)) transitionTo(BoxScore.new(self.state.stats))
end) end)
return true
end
return false
end
function Game:nextHalfInning()
pitchTracker:reset()
if self:checkForGameOver() then
return return
end end
@ -291,11 +299,9 @@ end
---@param scoredRunCount number ---@param scoredRunCount number
function Game:score(scoredRunCount) function Game:score(scoredRunCount)
-- TODO: end the game when it's the bottom of the ninth the home team is now in the lead.
-- outRunners/scoredRunners split
self:battingTeamCurrentInning().score = self:battingTeamCurrentInning().score + scoredRunCount self:battingTeamCurrentInning().score = self:battingTeamCurrentInning().score + scoredRunCount
self.announcer:say("SCORE!") self.announcer:say("SCORE!")
self:checkForGameOver()
end end
---@param throwFlyMs number ---@param throwFlyMs number