Created Shooting Logic class and refactored to use it
parent
0df30cce57
commit
c5743a4a79
|
@ -531,43 +531,6 @@ class GameFlow {
|
|||
// Logic for traversing the mountains, may affect gameState
|
||||
}
|
||||
|
||||
// Shooting word variations
|
||||
private shootingWordVariations: string[] = [
|
||||
"BANG", "BLAM", "POW", "WHAM", "BOOM", "ZAP", "PEW", "BAM", "CRACK", "POP",
|
||||
"BOFF", "SMACK", "KABOOM", "ZOOM", "WHOOSH", "BLOOP", "SPLAT", "SPLASH", "CRASH", "BANG!"
|
||||
];
|
||||
|
||||
// Simulating the shooting subroutine
|
||||
handleShooting(userInput?: string): string {
|
||||
|
||||
let responseMessage = ''
|
||||
|
||||
if (!userInput) {
|
||||
// Select a random shooting word
|
||||
const shootingWordSelector = Math.floor(Math.random() * this.shootingWordVariations.length);
|
||||
this.gameState.shootingWordSelector = this.shootingWordVariations[shootingWordSelector];
|
||||
this.gameState.clockTimeAtStartOfBang = Math.floor(new Date().getTime() / 1000);
|
||||
//prompt the user to type !!Oregon shootingWord
|
||||
responseMessage += `\nQuick! TYPE !!Oregon ${this.gameState.shootingWordSelector} within the next few minutes. Hurry, time is ticking!\n\n`;
|
||||
return responseMessage;
|
||||
} else {
|
||||
// Check user input against shooting word
|
||||
if (userInput.toUpperCase() === this.gameState.shootingWordSelector) {
|
||||
const clockTimeAtEndOfBang = this.gameState.comment.created_utc;
|
||||
let actualResponseTimeForBang = ((clockTimeAtEndOfBang - this.gameState.clockTimeAtStartOfBang) / 60000);
|
||||
actualResponseTimeForBang += (this.gameState.shootingExpertiseLevelChoice - 1)
|
||||
if (actualResponseTimeForBang < 0) {
|
||||
actualResponseTimeForBang = 0;
|
||||
}
|
||||
// Update the game state with the actual response time
|
||||
this.gameState.shootResponseTime = actualResponseTimeForBang;
|
||||
} else {
|
||||
responseMessage += `Your Word was ${this.gameState.shootingWordSelector}. Better luck next time!\n\n`
|
||||
this.gameState.shootResponseTime = 9; // Set a high time to indicate a miss
|
||||
}
|
||||
return responseMessage;
|
||||
}
|
||||
}
|
||||
|
||||
private handleDoctor(): string {
|
||||
let responseMessage: string = ""
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import GameState, { PHASE_ENUM } from '../gameState';
|
||||
import GameFlow from '../gameFlow';
|
||||
import { HandleShooting } from './shooting';
|
||||
|
||||
export class HuntPhase {
|
||||
static async handleHunt(gameState: GameState, gameFlow: GameFlow, userInput?: string): Promise<void> {
|
||||
|
@ -22,7 +23,7 @@ export class HuntPhase {
|
|||
|
||||
static async initialLogic(gameState: GameState, gameFlow: GameFlow,): Promise<void> {
|
||||
let responseMessage = '';
|
||||
responseMessage += gameFlow.handleShooting();
|
||||
responseMessage += HandleShooting.handleShooting(gameState);
|
||||
gameState.subPhase = 1;
|
||||
gameState.lastPrompt = responseMessage;
|
||||
await gameFlow.statusUpdate(responseMessage);
|
||||
|
@ -42,7 +43,7 @@ export class HuntPhase {
|
|||
await gameFlow.statusUpdate(responseMessage);
|
||||
return;
|
||||
}
|
||||
responseMessage += gameFlow.handleShooting(userInput.toString());
|
||||
responseMessage += HandleShooting.handleShooting(gameState, userInput.toString());
|
||||
gameState.lastPrompt = responseMessage;
|
||||
gameState.subPhase = 2;
|
||||
await gameState.save();
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
import GameState, { PHASE_ENUM } from '../gameState';
|
||||
import GameFlow from '../gameFlow';
|
||||
import { HandleShooting } from './shooting';
|
||||
|
||||
export class RidersPhase {
|
||||
static async handleRidersAttack(gameState: GameState, gameFlow: GameFlow, userInput?: string): Promise<void> {
|
||||
let responseMessage = '';
|
||||
|
@ -13,7 +15,7 @@ export class RidersPhase {
|
|||
break;
|
||||
case 2: //Fight Logic
|
||||
responseMessage = gameState.lastPrompt
|
||||
responseMessage += gameFlow.handleShooting()
|
||||
responseMessage += HandleShooting.handleShooting(gameState);
|
||||
gameState.lastPrompt = responseMessage
|
||||
gameState.subPhase = 3
|
||||
await gameFlow.statusUpdate(responseMessage)
|
||||
|
@ -26,7 +28,7 @@ export class RidersPhase {
|
|||
await gameFlow.statusUpdate(responseMessage)
|
||||
return;
|
||||
}
|
||||
responseMessage += gameFlow.handleShooting(userInput.toString());
|
||||
responseMessage += HandleShooting.handleShooting(gameState, userInput.toString());
|
||||
if (gameState.shootResponseTime <= 1) {
|
||||
responseMessage += `NICE SHOOTING---YOU DROVE THEM OFF!!!\n\n`
|
||||
await gameFlow.statusUpdate(responseMessage)
|
||||
|
@ -44,7 +46,7 @@ export class RidersPhase {
|
|||
return;
|
||||
case 4: // wagon fight logic
|
||||
responseMessage = gameState.lastPrompt
|
||||
responseMessage += gameFlow.handleShooting()
|
||||
responseMessage += HandleShooting.handleShooting(gameState);
|
||||
gameState.lastPrompt = responseMessage
|
||||
gameState.subPhase = 5
|
||||
await gameFlow.statusUpdate(responseMessage)
|
||||
|
@ -57,7 +59,7 @@ export class RidersPhase {
|
|||
await gameFlow.statusUpdate(responseMessage)
|
||||
return;
|
||||
}
|
||||
responseMessage += gameFlow.handleShooting(userInput.toString());
|
||||
responseMessage += HandleShooting.handleShooting(gameState, userInput.toString());
|
||||
gameState.amountSpentOnAmmunition -= gameState.shootResponseTime * 30 - 80
|
||||
gameState.totalMileageWholeTrip -= 25
|
||||
gameState.lastPrompt = responseMessage;
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
import GameState from '../gameState';
|
||||
import GameFlow from '../gameFlow';
|
||||
|
||||
export class HandleShooting {
|
||||
private static shootingWordVariations: string[] = [
|
||||
"BANG", "BLAM", "POW", "WHAM", "BOOM", "ZAP", "PEW", "BAM", "CRACK", "POP",
|
||||
"BOFF", "SMACK", "KABOOM", "ZOOM", "WHOOSH", "BLOOP", "SPLAT", "SPLASH", "CRASH", "BANG!"
|
||||
];
|
||||
|
||||
static async handleShooting(gameState: GameState, userInput?: string): Promise<string> {
|
||||
if (!gameState.shootingWordSelector) {
|
||||
return await HandleShooting.initialLogic(gameState);
|
||||
} else {
|
||||
return await HandleShooting.shootingLogic(gameState, userInput);
|
||||
}
|
||||
}
|
||||
|
||||
private static async initialLogic(gameState: GameState): Promise<string> {
|
||||
const shootingWordSelector = Math.floor(Math.random() * HandleShooting.shootingWordVariations.length);
|
||||
gameState.shootingWordSelector = HandleShooting.shootingWordVariations[shootingWordSelector];
|
||||
gameState.clockTimeAtStartOfBang = Math.floor(new Date().getTime() / 1000);
|
||||
|
||||
const responseMessage = `\nQuick! TYPE !!Oregon ${gameState.shootingWordSelector} within the next few minutes. Hurry, time is ticking!\n\n`;
|
||||
await gameState.save();
|
||||
return responseMessage;
|
||||
}
|
||||
|
||||
private static async shootingLogic(gameState: GameState, userInput?: string): Promise<string> {
|
||||
let responseMessage = '';
|
||||
if (!userInput) {
|
||||
responseMessage = "Invalid input.\n\n";
|
||||
responseMessage += `Quick! TYPE !!Oregon ${gameState.shootingWordSelector} within the next few minutes. Hurry, time is ticking!\n\n`;
|
||||
return responseMessage;
|
||||
}
|
||||
|
||||
if (userInput.toUpperCase() === gameState.shootingWordSelector.toUpperCase()) {
|
||||
const clockTimeAtEndOfBang = gameState.comment.created_utc;
|
||||
let actualResponseTimeForBang = ((clockTimeAtEndOfBang - gameState.clockTimeAtStartOfBang) / 60000);
|
||||
actualResponseTimeForBang += (gameState.shootingExpertiseLevelChoice - 1);
|
||||
if (actualResponseTimeForBang < 0) {
|
||||
actualResponseTimeForBang = 0;
|
||||
}
|
||||
gameState.shootResponseTime = actualResponseTimeForBang;
|
||||
} else {
|
||||
responseMessage += `Your Word was ${gameState.shootingWordSelector}. Better luck next time!\n\n`;
|
||||
gameState.shootResponseTime = 9; // Set a high time to indicate a miss
|
||||
}
|
||||
|
||||
gameState.shootingWordSelector = ''; // Reset the shooting word selector
|
||||
await gameState.save();
|
||||
return responseMessage;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue