UNPKG

sandhill-road

Version:

A narrative-driven startup simulation game where you guide a founder from garage to exit

222 lines 9.1 kB
#!/usr/bin/env node "use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const chalk_1 = __importDefault(require("chalk")); const figlet_1 = __importDefault(require("figlet")); const inquirer_1 = __importDefault(require("inquirer")); const gameState_1 = require("../core/gameState"); const narrativeEngine_1 = require("../core/narrativeEngine"); // ASCII art banner const showBanner = () => { console.clear(); console.log(chalk_1.default.yellowBright(figlet_1.default.textSync('Sandhill Road', { font: 'ANSI Shadow', horizontalLayout: 'default', verticalLayout: 'default' }))); console.log(chalk_1.default.greenBright('A Startup Simulation Game')); console.log('-------------------------------------------\n'); }; // Show game stats const showStats = () => { const state = (0, gameState_1.getGameState)(); console.log(chalk_1.default.cyan('\n=== FOUNDER STATS ===')); console.log(`${chalk_1.default.bold('Health:')} ${state.founderStats.health}`); console.log(`${chalk_1.default.bold('Morale:')} ${state.founderStats.morale}`); console.log(`${chalk_1.default.bold('Hustle:')} ${state.founderStats.hustle}`); console.log(`${chalk_1.default.bold('Tech:')} ${state.founderStats.tech}`); console.log(`${chalk_1.default.bold('Luck:')} ${state.founderStats.luck}`); console.log(`${chalk_1.default.bold('Stamina:')} ${state.founderStats.stamina}/${state.founderStats.maxStamina}`); console.log(`${chalk_1.default.bold('Personal Cash:')} $${state.founderStats.personalCash.toLocaleString()}`); console.log(chalk_1.default.magenta('\n=== COMPANY STATS ===')); console.log(`${chalk_1.default.bold('Company Cash:')} $${state.companyStats.companyCash.toLocaleString()}`); console.log(`${chalk_1.default.bold('Burn Rate:')} $${state.companyStats.burnRate.toLocaleString()}/week`); console.log(`${chalk_1.default.bold('Runway:')} ${state.companyStats.runway} weeks`); console.log(`${chalk_1.default.bold('Users:')} ${state.companyStats.users.toLocaleString()}`); console.log(`${chalk_1.default.bold('Product Progress:')} ${state.companyStats.productProgress}%`); console.log(`${chalk_1.default.bold('Revenue:')} $${state.companyStats.revenue.toLocaleString()}/week`); console.log(chalk_1.default.yellow('\n=== PROGRESS ===')); console.log(`${chalk_1.default.bold('Current Stage:')} ${state.stageProgress.currentStage}`); console.log(`${chalk_1.default.bold('Week:')} ${state.stageProgress.week}`); console.log(`${chalk_1.default.bold('Events Completed:')} ${state.stageProgress.completedEvents.length}`); console.log('\n-------------------------------------------\n'); }; // Main game loop const gameLoop = async () => { let gameRunning = true; while (gameRunning) { const state = (0, gameState_1.getGameState)(); if (state.gameOver) { console.log(chalk_1.default.red('\n=== GAME OVER ===')); console.log(chalk_1.default.red(state.gameOverReason || 'Your startup journey has ended.')); console.log('\n'); const { playAgain } = await inquirer_1.default.prompt({ type: 'confirm', name: 'playAgain', message: 'Would you like to play again?', default: false }); if (playAgain) { await startNewGame(); } else { gameRunning = false; console.log(chalk_1.default.yellowBright('Thanks for playing Sandhill Road!')); } continue; } // Get or start a new event let currentEvent = (0, narrativeEngine_1.getCurrentEvent)(); if (!currentEvent) { currentEvent = (0, narrativeEngine_1.startEvent)(); if (!currentEvent) { console.log(chalk_1.default.yellow('No available events for the current stage.')); console.log(chalk_1.default.yellow('Progressing to the next stage...')); const nextStage = (0, narrativeEngine_1.progressToNextStage)(); console.log(chalk_1.default.green(`\nYou've reached the ${nextStage} stage!`)); console.log(chalk_1.default.green((0, narrativeEngine_1.getStageDescription)(nextStage))); await inquirer_1.default.prompt({ type: 'input', name: 'continue', message: 'Press ENTER to continue...' }); continue; } } console.clear(); showBanner(); showStats(); // Display the event console.log(chalk_1.default.cyan(`\n=== ${currentEvent.title} ===`)); console.log(`${currentEvent.description}\n`); // Display choices const choices = currentEvent.choices.map(choice => ({ name: choice.text, value: choice.id })); choices.push({ name: 'Save Game', value: 'save' }); const { choice } = await inquirer_1.default.prompt({ type: 'list', name: 'choice', message: 'What will you do?', choices }); if (choice === 'save') { (0, gameState_1.saveGame)(); console.log(chalk_1.default.green('Game saved!')); await inquirer_1.default.prompt({ type: 'input', name: 'continue', message: 'Press ENTER to continue...' }); continue; } // Handle the choice const result = (0, narrativeEngine_1.makeChoice)(choice); console.log('\n' + chalk_1.default.yellow(result.resultText) + '\n'); await inquirer_1.default.prompt({ type: 'input', name: 'continue', message: 'Press ENTER to continue...' }); (0, narrativeEngine_1.clearCurrentEvent)(); // If there's a next event specified, start it if (result.nextEvent) { (0, narrativeEngine_1.startEvent)(result.nextEvent); } } }; // Character creation const createCharacter = async () => { console.clear(); showBanner(); console.log(chalk_1.default.yellowBright('Welcome to Sandhill Road!\n')); console.log('You are about to embark on a journey to build a startup.'); console.log('Make tough decisions, manage your resources, and try to survive the startup life.\n'); const answers = await inquirer_1.default.prompt([ { type: 'input', name: 'founderName', message: 'What is your name?', default: 'Founder' }, { type: 'input', name: 'companyName', message: 'What is your company name?', default: 'Startup Inc.' }, { type: 'list', name: 'initialCash', message: 'How much personal cash do you start with?', choices: [ { name: 'Bootstrapped ($10,000)', value: 10000 }, { name: 'Some Savings ($30,000)', value: 30000 }, { name: 'Rich Parents ($100,000)', value: 100000 } ], default: 30000 } ]); return answers; }; // Start a new game const startNewGame = async () => { const { founderName, companyName, initialCash } = await createCharacter(); // Initialize the game state (0, gameState_1.initGame)(founderName, companyName, initialCash); // Load events await (0, narrativeEngine_1.loadEvents)(); // Start the game loop await gameLoop(); }; // Main menu const mainMenu = async () => { showBanner(); const { action } = await inquirer_1.default.prompt({ type: 'list', name: 'action', message: 'Welcome to Sandhill Road!', choices: [ { name: 'New Game', value: 'new' }, { name: 'Load Game', value: 'load' }, { name: 'Exit', value: 'exit' } ] }); switch (action) { case 'new': await startNewGame(); break; case 'load': const savedGame = (0, gameState_1.loadGame)(); if (savedGame) { console.log(chalk_1.default.green('Game loaded successfully!')); await (0, narrativeEngine_1.loadEvents)(); await gameLoop(); } else { console.log(chalk_1.default.red('No saved game found.')); await mainMenu(); } break; case 'exit': console.log(chalk_1.default.yellow('Thanks for playing Sandhill Road!')); process.exit(0); } }; // Start the game (async () => { try { await mainMenu(); } catch (error) { console.error('An error occurred:', error); } })(); //# sourceMappingURL=index.js.map