UNPKG

claude-arcade

Version:

Add classic arcade games to your Claude Code workflow with Ctrl+G

113 lines (112 loc) 3.66 kB
#!/usr/bin/env node "use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); // Suppress deprecation warnings from dependencies process.removeAllListeners('warning'); process.on('warning', (warning) => { if (warning.name === 'DeprecationWarning') return; console.warn(warning); }); const readline = __importStar(require("readline")); const dino_1 = require("./games/dino"); const game = new dino_1.DinoGame(); let gameLoop = null; // Hide cursor process.stdout.write('\x1b[?25l'); function startGame() { game.start(); if (gameLoop) clearInterval(gameLoop); gameLoop = setInterval(() => { game.update(); if (game.isGameOver()) { if (gameLoop) clearInterval(gameLoop); process.stdout.write(game.drawGameOver()); process.stdout.write('\n\n\x1b[32mPress P to play again | Press Q to quit\x1b[0m\n'); return; } process.stdout.write(game.draw()); }, 50); } function cleanup() { if (gameLoop) clearInterval(gameLoop); process.stdout.write('\x1b[?25h'); // Show cursor if (process.stdin.isTTY) { process.stdin.setRawMode(false); } } // Show welcome screen process.stdout.write(game.drawWelcome()); // Set up keyboard input if (process.stdin.isTTY) { process.stdin.setRawMode(true); readline.emitKeypressEvents(process.stdin); process.stdin.on('keypress', (_str, key) => { if (!key) return; if (key.name === 'q' || (key.ctrl && key.name === 'c')) { cleanup(); process.exit(0); } if (key.name === 'p' && !game.isPlaying()) { startGame(); } if (game.isPlaying() && !game.isGameOver()) { if (key.name === 'up' || key.name === 'space') { game.jump(); } else if (key.name === 'down' || key.name === 's') { game.duck(true); } else { game.duck(false); } } }); } process.on('SIGINT', () => { cleanup(); process.exit(0); }); process.on('exit', cleanup); process.on('uncaughtException', (err) => { cleanup(); console.error('Uncaught exception:', err); process.exit(1); });