108 lines
2.9 KiB
JavaScript
108 lines
2.9 KiB
JavaScript
import { GAME_PHASES, GAME_EVENTS } from './GameConstants.js';
|
|
|
|
export class TurnManager {
|
|
constructor() {
|
|
this.currentTurn = 0;
|
|
this.currentPhase = GAME_PHASES.SETUP;
|
|
this.listeners = {}; // Simple event system
|
|
|
|
// Power Phase State
|
|
this.currentPowerRoll = 0;
|
|
this.eventsTriggered = [];
|
|
}
|
|
|
|
get power() {
|
|
return this.currentPowerRoll;
|
|
}
|
|
|
|
startGame() {
|
|
this.currentTurn = 1;
|
|
console.log(`--- TURN ${this.currentTurn} START ---`);
|
|
this.startPowerPhase();
|
|
}
|
|
|
|
nextPhase() {
|
|
// Simple sequential flow
|
|
switch (this.currentPhase) {
|
|
case GAME_PHASES.POWER:
|
|
this.setPhase(GAME_PHASES.HERO);
|
|
break;
|
|
case GAME_PHASES.HERO:
|
|
// Move to Monster Phase
|
|
this.setPhase(GAME_PHASES.MONSTER);
|
|
break;
|
|
case GAME_PHASES.MONSTER:
|
|
// Move to Exploration Phase
|
|
this.setPhase(GAME_PHASES.EXPLORATION);
|
|
break;
|
|
case GAME_PHASES.EXPLORATION:
|
|
// End Turn and restart
|
|
this.endTurn();
|
|
break;
|
|
}
|
|
}
|
|
|
|
setPhase(phase) {
|
|
if (this.currentPhase !== phase) {
|
|
console.log(`Phase Switch: ${this.currentPhase} -> ${phase}`);
|
|
this.currentPhase = phase;
|
|
this.emit(GAME_EVENTS.PHASE_CHANGED, phase);
|
|
}
|
|
}
|
|
|
|
startPowerPhase() {
|
|
this.setPhase(GAME_PHASES.POWER);
|
|
this.rollPowerDice();
|
|
}
|
|
|
|
rollPowerDice() {
|
|
const roll = Math.floor(Math.random() * 6) + 1;
|
|
this.currentPowerRoll = roll;
|
|
console.log(`Power Roll: ${roll}`);
|
|
|
|
let message = "The dungeon is quiet...";
|
|
let eventTriggered = false;
|
|
|
|
if (roll === 1) {
|
|
message = "UNEXPECTED EVENT! (Roll of 1)";
|
|
eventTriggered = true;
|
|
this.triggerRandomEvent();
|
|
}
|
|
|
|
this.emit('POWER_RESULT', { roll, message, eventTriggered });
|
|
|
|
// Auto-advance to Hero phase after short delay (game feel)
|
|
setTimeout(() => {
|
|
this.nextPhase();
|
|
}, 2000);
|
|
}
|
|
|
|
triggerRandomEvent() {
|
|
console.warn("TODO: TRIGGER EVENT CARD DRAW");
|
|
}
|
|
|
|
triggerExploration() {
|
|
this.setPhase(GAME_PHASES.EXPLORATION);
|
|
// Logic to return to HERO phase would handle elsewhere
|
|
}
|
|
|
|
endTurn() {
|
|
console.log(`--- TURN ${this.currentTurn} END ---`);
|
|
this.emit('turn_ended', this.currentTurn);
|
|
this.currentTurn++;
|
|
this.startPowerPhase();
|
|
}
|
|
|
|
// -- Simple Observer Pattern --
|
|
on(event, callback) {
|
|
if (!this.listeners[event]) this.listeners[event] = [];
|
|
this.listeners[event].push(callback);
|
|
}
|
|
|
|
emit(event, data) {
|
|
if (this.listeners[event]) {
|
|
this.listeners[event].forEach(cb => cb(data));
|
|
}
|
|
}
|
|
}
|