Start turn Logic

master
j 2024-04-10 01:07:40 -04:00
parent 96ad73a3eb
commit 2de4f357de
1 changed files with 68 additions and 4 deletions

View File

@ -9,13 +9,14 @@ class GameFlow {
this.gameState = gameState;
}
async executeCurrentPhase(userInput?: string) {
async executeCurrentPhase(userInput?: string, previousTurnText: string = "") {
switch (this.gameState.phase) {
case PHASE_ENUM.SETUP:
// Handle the setup phase, e.g., initial purchases
await this.handleSetupPhase(userInput);
break;
case PHASE_ENUM.START_TURN:
await this.startTurn();
break;
case PHASE_ENUM.ACTION_CHOICE:
break;
@ -45,9 +46,9 @@ class GameFlow {
// Handle mountain traversal challenges
await this.handleMountain();
break;
case PHASE_ENUM.DEATH_CHECK:
case PHASE_ENUM.DEATH:
// Check if conditions leading to the player's death have been met
await this.handleDeathCheck();
await this.handleDeath(previousTurnText);
break;
default:
console.error("Unknown game phase:", this.gameState.phase);
@ -350,6 +351,68 @@ class GameFlow {
};
}
startTurn(): void {
let responseMessage = ""
// Ensure all expenditures are non-negative
this.gameState.amountSpentOnFood = Math.max(0, this.gameState.amountSpentOnFood);
this.gameState.amountSpentOnAmmunition = Math.max(0, this.gameState.amountSpentOnAmmunition);
this.gameState.amountSpentOnClothing = Math.max(0, this.gameState.amountSpentOnClothing);
this.gameState.amountSpentOnMiscellaneousSupplies = Math.max(0, this.gameState.amountSpentOnMiscellaneousSupplies);
// Round expenditures and cash to integers
this.gameState.amountSpentOnFood = Math.floor(this.gameState.amountSpentOnFood);
this.gameState.amountSpentOnAmmunition = Math.floor(this.gameState.amountSpentOnAmmunition);
this.gameState.amountSpentOnClothing = Math.floor(this.gameState.amountSpentOnClothing);
this.gameState.amountSpentOnMiscellaneousSupplies = Math.floor(this.gameState.amountSpentOnMiscellaneousSupplies);
this.gameState.cashLeftAfterInitialPurchases = Math.floor(this.gameState.cashLeftAfterInitialPurchases);
this.gameState.totalMileageWholeTrip = Math.floor(this.gameState.totalMileageWholeTrip);
// Update total mileage up through the previous turn
this.gameState.totalMileageUpThroughPreviousTurn = this.gameState.totalMileageWholeTrip;
// Handle illness and injury
if (this.gameState.illnessFlag || this.gameState.injuryFlag) {
if (this.gameState.illnessFlag && this.gameState.injuryFlag) {
responseMessage += `You were sick and and injured `
} else if (this.gameState.illnessFlag) {
responseMessage += `You were sick and `
} else {
responseMessage += `You were injured and `
}
this.gameState.cashLeftAfterInitialPurchases -= 20;
if (this.gameState.cashLeftAfterInitialPurchases < 0) {
responseMessage += `You've run out of money for the doctor\n\n`;
if (this.gameState.illnessFlag && this.gameState.injuryFlag) {
responseMessage += `You died of dysentery.\n\n`
} else {
responseMessage += `${MessageService.getRandomMessage(
MessageFileName.Oregon_SickInjuredDeath,
{}
)}`
}
this.gameState.phase = PHASE_ENUM.DEATH;
this.executeCurrentPhase(undefined, responseMessage)
return;
// Consider adding logic to handle game over state
} else {
responseMessage += `The Doctors bill was $20\n\n`
}
this.gameState.injuryFlag = false;
this.gameState.illnessFlag = false;
}
// 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`;
}
// Toggle fort option flag
this.gameState.fortOptionFlag = !this.gameState.fortOptionFlag;
this.gameState.phase = PHASE_ENUM.ACTION_CHOICE;
this.executeCurrentPhase(undefined, responseMessage)
}
private async handleRidersAttack(userInput?: string | number): Promise<void> {
@ -380,7 +443,8 @@ class GameFlow {
// Logic for traversing the mountains, may affect gameState
}
private async handleDeathCheck(): Promise<void> {
private async handleDeath(previousTurnText: string): Promise<void> {
console.log(previousTurnText)
// Check gameState conditions and determine if the player has died
}