cleanup
parent
67615fc839
commit
46abc5ba68
|
@ -1,72 +0,0 @@
|
||||||
import GameState from './gameState';
|
|
||||||
import GameFlow from './gameFlow';
|
|
||||||
import { Comment } from '../rdrama/models/Comment';
|
|
||||||
import { CommentParser } from '../rdrama/services/CommentParser';
|
|
||||||
|
|
||||||
class GameSession {
|
|
||||||
private gameState: GameState;
|
|
||||||
private gameFlow: GameFlow;
|
|
||||||
private authorId: number;
|
|
||||||
|
|
||||||
private constructor(authorId: number, gameState: GameState) {
|
|
||||||
this.authorId = authorId;
|
|
||||||
this.gameState = gameState;
|
|
||||||
this.gameFlow = new GameFlow(gameState);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles user input by parsing the command and executing the corresponding action.
|
|
||||||
* @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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// After processing the command, save any changes to the game state
|
|
||||||
await this.gameState.save();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generates a status update message based on the current state of the game.
|
|
||||||
* @returns A string representing the current game status, formatted for display.
|
|
||||||
*/
|
|
||||||
public getStatusUpdate(): string {
|
|
||||||
// Use the GameFlow instance to generate a status message
|
|
||||||
return this.gameFlow.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 };
|
|
Loading…
Reference in New Issue