Compare commits

...

4 Commits

Author SHA1 Message Date
j fde47b0025 session thoughts 2024-03-29 00:26:48 -04:00
j 0f73d3520c further enum on phases 2024-03-29 00:26:36 -04:00
j 0165d9212b phaseManagement Skeleton 2024-03-29 00:26:14 -04:00
j a95240a1b0 !!Oregon Logic 2024-03-29 00:25:47 -04:00
4 changed files with 81 additions and 84 deletions

View File

@ -1,4 +1,4 @@
import GameState from './gameState' import GameState, { PHASE_ENUM } from './gameState'
class GameFlow { class GameFlow {
gameState: GameState gameState: GameState
@ -7,19 +7,22 @@ class GameFlow {
this.gameState = gameState; this.gameState = gameState;
} }
executeCurrentPhase() { async executeCurrentPhase(userInput?: any) {
switch (this.gameState.currentPhase) { switch (this.gameState.phase) {
case 'initialChoice': case PHASE_ENUM.SETUP:
// Handle initial choice // Handle the setup phase, e.g., initial purchases
break; break;
case 'fort': case PHASE_ENUM.RIDERS_ATTACK:
// Handle fort logic
break; break;
// Other cases for each phase // Additional cases for other phases...
case PHASE_ENUM.TRAVEL:
// Handle travel logic
break;
case PHASE_ENUM.FORT:
// Handle fort or hunt choices
break;
// Include other phases as necessary
} }
// After phase logic, advance to next phase
this.gameState.advancePhase();
} }
// Other methods as needed // Other methods as needed

View File

@ -1,74 +1,72 @@
import GameState from './gameState'; import GameState from './gameState';
import GameFlow from './gameFlow'; import GameFlow from './gameFlow';
import { Comment } from '../rdrama/models/Comment';
import { CommentParser } from '../rdrama/services/CommentParser';
class GameSession { class GameSession {
private gameState: GameState; private gameState: GameState;
private gameManager: GameFlow; private gameFlow: GameFlow;
private authorId: string; private authorId: number;
constructor(authorId: string) { private constructor(authorId: number, gameState: GameState) {
this.authorId = authorId; this.authorId = authorId;
// Initialize GameState. If there's saved data for this authorId, load it; otherwise, start with default values. this.gameState = gameState;
this.gameState = new GameState(authorId); this.gameFlow = new GameFlow(gameState);
// Initialize the GameManager with the current game state.
this.gameManager = new GameFlow(this.gameState);
} }
async handleUserInput(userId: string, input: string): Promise<void> { /**
const gameState = await this.loadGameState(userId); * Loads an existing game session for the given author or creates a new one if none exists.
* @param authorId The ID of the author for whom to load or create the game session.
* @returns A GameSession instance for the given author.
*/
public static async loadSession(authorId: number): Promise<GameSession> {
const gameState = await GameState.load(authorId);
return new GameSession(authorId, gameState);
}
switch (input.split(' ')[0].toLowerCase()) { /**
case "!!oregon": * Handles user input by parsing the command and executing the corresponding action.
await this.processCommand(gameState, input); * @param comment The comment containing the user input.
*/
public async handleUserInput(comment: Comment): Promise<void> {
const { command, args } = CommentParser.parseCommand(comment);
// Process the command
switch (command) {
case 'startover':
// Example of resetting the game
this.gameState.reset();
break;
case 'buysupplies':
// Example of handling a purchase command
// Logic to handle buying supplies
break;
// Add additional cases for other commands
default:
console.error('Unrecognized command:', command);
break; break;
// Additional commands as necessary
} }
await this.saveGameState(gameState); // After processing the command, save any changes to the game state
} await this.gameState.save();
private async processCommand(gameState: GameState, command: string): Promise<void> {
const args = command.split(' ');
// Process different game setup commands (e.g., "start over", "buy supplies")
if (args[1].toLowerCase() === "startover") {
gameState.reset(); // Resets game state to initial values
} else if (args[1].toLowerCase() === "buysupplies") {
// Transition to handling purchases
// This would involve setting the next expected action in the game state
// And possibly sending a prompt for the first purchase
}
// Handle other commands and shopping logic
} }
/** /**
* Saves the current game state. * Generates a status update message based on the current state of the game.
* This method would serialize the GameState object and save it to a database or file system. * @returns A string representing the current game status, formatted for display.
*/
private saveGameState(): void {
// Implementation for saving the game state.
console.log('Saving game state...');
// Serialize and save the GameState object here.
}
/**
* Loads a saved game state.
* This method would deserialize a saved GameState object and update the current game state with it.
*/
private loadGameState(): void {
// Implementation for loading a saved game state.
console.log('Loading game state...');
// Deserialize and load the GameState object here.
// Update this.gameState with the loaded state.
}
/**
* Retrieves the current game status update for the player.
* This could include information about the player's progress, inventory, and available actions.
* @returns A string representing the current game status.
*/ */
public getStatusUpdate(): string { public getStatusUpdate(): string {
// Generate a status update message based on the current game state. // Use the GameFlow instance to generate a status message
// This message could be formatted with Markdown for better presentation. return this.gameFlow.generateStatusMessage();
return this.gameManager.generateStatusMessage(); }
/**
* Resets the game to its initial state and saves the updated state.
*/
private async reset(): Promise<void> {
this.gameState.reset();
await this.gameState.save();
} }
} }
export { GameSession };

View File

@ -76,12 +76,14 @@ class GameState {
export default GameState export default GameState
// Enumeration for different phases of the game. // Enumeration for different phases of the game.
enum PHASE_ENUM { export enum PHASE_ENUM {
SETUP = 'SETUP', SETUP = 'SETUP',
TRAVEL = 'TRAVEL', TRAVEL = 'TRAVEL',
FORT_HUNT = 'FORT_HUNT', FORT = 'FORT',
HUNT = 'HUNT',
ENCOUNTER = 'ENCOUNTER', ENCOUNTER = 'ENCOUNTER',
EVENT = 'EVENT', EVENT = 'EVENT',
MOUNTAIN = 'MOUNTAIN', MOUNTAIN = 'MOUNTAIN',
DEATH_CHECK = 'DEATH_CHECK', DEATH_CHECK = 'DEATH_CHECK',
RIDERS_ATTACK = 'RIDERS_ATTACK',
} }

View File

@ -2,27 +2,21 @@ import { Comment } from '../models/Comment';
export class CommentParser { export class CommentParser {
/** /**
* Extracts Reddit usernames from the body of a single comment. * Parses commands from the body of a single comment triggered by !!Oregon.
* @param comment A single Comment object to be processed. * @param comment A single Comment object to be processed.
* @returns An array of unique Reddit usernames found in the comment. * @returns An object containing the command and its arguments, if any.
*/ */
public static extractUsernames(comment: Comment): string[] { public static parseCommand(comment: Comment): { command: string, args: string[] } {
const regexPattern: RegExp = /(^|\s|\\r\\n|\\t|[".,;(){}\[\]!?@#])(\/?u\/[a-zA-Z0-9_]+)/g; const commandTrigger: RegExp = /!!Oregon\s+(\w+)(?:\s+(.*))?/i;
const foundUsernames: Set<string> = new Set(); const match = comment.body.match(commandTrigger);
const matches = comment.body.match(regexPattern); if (match) {
if (matches) { const command = match[1].toLowerCase();
matches.forEach(match => { const args = match[2] ? match[2].split(' ').map(arg => arg.trim()) : [];
// Ensure the username is captured in a standardized format return { command, args };
const usernameMatch = match.trim().match(/\/?u\/([a-zA-Z0-9_]+)/);
if (usernameMatch) {
// Standardize to "username" format
const username = `${usernameMatch[1].toLowerCase()}`;
foundUsernames.add(username);
}
});
} }
return Array.from(foundUsernames); // No command found
return { command: '', args: [] };
} }
} }