From 687bf749796a321a9d0a78e585c05e064fae0002 Mon Sep 17 00:00:00 2001 From: Sage Vaillancourt Date: Sun, 23 Feb 2025 18:17:09 -0500 Subject: [PATCH] Check for a game over after each score. In case the home team just came from behind in the bottom of the final inning. --- src/main.lua | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main.lua b/src/main.lua index e63349e..499dd17 100644 --- a/src/main.lua +++ b/src/main.lua @@ -241,8 +241,7 @@ function Game:pitcherIsReady() ) end -function Game:nextHalfInning() - pitchTracker:reset() +function Game:checkForGameOver() local homeScore, awayScore = utils.totalScores(self.state.stats) local isFinalInning = self.state.inning >= self.settings.finalInning local gameOver = isFinalInning and self.state.battingTeam == "home" and awayScore ~= homeScore @@ -254,6 +253,15 @@ function Game:nextHalfInning() playdate.timer.new(3000, function() transitionTo(BoxScore.new(self.state.stats)) end) + return true + end + + return false +end + +function Game:nextHalfInning() + pitchTracker:reset() + if self:checkForGameOver() then return end @@ -291,11 +299,9 @@ end ---@param scoredRunCount number 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.announcer:say("SCORE!") + self:checkForGameOver() end ---@param throwFlyMs number