Compare commits
4 Commits
96ad73a3eb
...
648b8146ba
Author | SHA1 | Date |
---|---|---|
j | 648b8146ba | |
j | b52917b7d9 | |
j | cb85900a64 | |
j | 2de4f357de |
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -101,5 +101,5 @@ export enum PHASE_ENUM {
|
|||
RIDERS_ATTACK = 'RIDERS_ATTACK',
|
||||
EVENT = 'EVENT',
|
||||
MOUNTAIN = 'MOUNTAIN',
|
||||
DEATH_CHECK = 'DEATH_CHECK',
|
||||
DEATH = 'DEATH',
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
You died of a snakebite.
|
||||
---END---
|
||||
You died of cholera.
|
||||
---END---
|
||||
You died of typhoid fever.
|
||||
---END---
|
||||
You died of pneumonia.
|
||||
---END---
|
||||
You died of scurvy.
|
||||
---END---
|
||||
You died of tuberculosis.
|
||||
---END---
|
||||
You died of starvation.
|
||||
---END---
|
||||
You died of smallpox.
|
||||
---END---
|
||||
You died of a broken leg that became infected.
|
||||
---END---
|
||||
You died of exposure to extreme cold.
|
||||
---END---
|
||||
You died of heatstroke.
|
||||
---END---
|
||||
You died of accidental poisoning from misidentified plants.
|
||||
---END---
|
|
@ -9,6 +9,7 @@ export enum MessageFileName {
|
|||
Oregon_AmmoPurchase = 'oregon_AmmoPurchase.txt',
|
||||
Oregon_ClothingPurchase = 'oregon_ClothingPurchase.txt',
|
||||
Oregon_MiscSuppliesPurchase = 'oregon_MiscSuppliesPurchase.txt',
|
||||
Oregon_SickInjuredDeath = 'oregon_SickInjuredDeath.txt',
|
||||
Oregon_Template = 'oregon_Template.txt',
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue