From 04f3f8a0a78de68a09ef14b0daddab575eedc54d Mon Sep 17 00:00:00 2001 From: j Date: Sun, 14 Apr 2024 21:22:17 -0400 Subject: [PATCH] Action Choice Logic Update --- src/game/gameFlow.ts | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/game/gameFlow.ts b/src/game/gameFlow.ts index bd95456..4650cc8 100644 --- a/src/game/gameFlow.ts +++ b/src/game/gameFlow.ts @@ -18,7 +18,7 @@ class GameFlow { await this.handleSetupPhase(userInput); break; case PHASE_ENUM.START_TURN: - this.startTurn(); + await this.startTurn(); break; case PHASE_ENUM.ACTION_CHOICE: await this.actionChoice(userInput) @@ -261,6 +261,7 @@ class GameFlow { //Advance Phase this.gameState.subPhase = 0; this.gameState.phase = PHASE_ENUM.START_TURN + await this.gameState.save() this.executeCurrentPhase() break; default: @@ -372,7 +373,7 @@ class GameFlow { this.gameState.cashLeftAfterInitialPurchases = Math.floor(this.gameState.cashLeftAfterInitialPurchases * 100) / 100; } - private startTurn(): void { + private async startTurn(): Promise { // Update total mileage up through the previous turn this.gameState.totalMileageUpThroughPreviousTurn = this.gameState.totalMileageWholeTrip; @@ -380,6 +381,7 @@ class GameFlow { this.gameState.fortOptionFlag = !this.gameState.fortOptionFlag; this.gameState.phase = PHASE_ENUM.ACTION_CHOICE; + await this.gameState.save() this.executeCurrentPhase() } @@ -390,17 +392,23 @@ class GameFlow { console.log("userInput", userInput); switch (userInput) { case "1": // Hunt - responseMessage += "You have decided to hunt.\n\n"; this.gameState.phase = PHASE_ENUM.HUNT; + await this.gameState.save() + this.executeCurrentPhase() + return; break; case "2": // Continue - responseMessage += "You have decided to continue on your journey.\n\n"; this.gameState.phase = PHASE_ENUM.TRAVEL; + await this.gameState.save() + this.executeCurrentPhase() + return; break; case "3": // Stop at the Next Fort (if applicable) if (this.gameState.fortOptionFlag) { - responseMessage += "You have decided to stop at the next fort.\n\n"; this.gameState.phase = PHASE_ENUM.FORT; + await this.gameState.save() + this.executeCurrentPhase() + return; } else { responseMessage += "⚠️ There is no fort option available at this time.\n\n" responseMessage += `Do you want to:\n1. Hunt\n2. Continue\n\n` @@ -424,7 +432,7 @@ class GameFlow { // Warn the player if food is low if (this.gameState.amountSpentOnFood < 13) { - responseMessage += `YOU'D BETTER DO SOME HUNTING OR BUY FOOD AND SOON!!!!\n\n`; + responseMessage += `You only have ${this.gameState.amountSpentOnFood} pounds of food.\n\n YOU'D BETTER DO SOME HUNTING OR BUY FOOD AND SOON!!!!\n\n`; } if (this.gameState.fortOptionFlag) { @@ -432,11 +440,10 @@ class GameFlow { } else { responseMessage += `Do you want to:\n1. Hunt\n2. Continue\n\n` } + await this.statusUpdate(responseMessage) break; } - await this.statusUpdate(responseMessage) - this.executeCurrentPhase() return; }