class Intersection { constructor() { this.trafficFlow = 0; this.safety = 100; this.emissions = 50; this.score = 0; } updateMetrics(flowChange, safetyChange, emissionsChange) { this.trafficFlow = Math.max(0, Math.min(100, this.trafficFlow + flowChange)); this.safety = Math.max(0, Math.min(100, this.safety + safetyChange)); this.emissions = Math.max(0, Math.min(100, this.emissions + emissionsChange)); this.updateScore(); } updateScore() { this.score = this.trafficFlow + this.safety + (100 - this.emissions); } } class Game { constructor() { this.intersection = new Intersection(); this.turn = 1; this.maxTurns = 10; } start() { console.log("Welcome to Intersection - Smart City Traffic Adventure!"); console.log("You are Oren, working with NoTraffic to optimize this intersection."); this.playTurn(); } playTurn() { if (this.turn > this.maxTurns) { this.endGame(); return; } console.log(`\n--- Turn ${this.turn}/${this.maxTurns} ---`); console.log(`Traffic Flow: ${this.intersection.trafficFlow}`); console.log(`Safety: ${this.intersection.safety}`); console.log(`Emissions: ${this.intersection.emissions}`); console.log(`Score: ${this.intersection.score}`); this.getPlayerAction(); } getPlayerAction() { console.log("\nChoose an action:"); console.log("1. Use Radar to optimize signal timing"); console.log("2. Use Cameras to improve safety"); console.log("3. Use V2X to reduce emissions"); console.log("4. Access Mobility OS Store"); // In a real implementation, we'd use a proper input method. // For this example, we'll simulate a random choice. const action = Math.floor(Math.random() * 4) + 1; console.log(`Chosen action: ${action}`); this.processAction(action); } processAction(action) { switch(action) { case 1: console.log("Using Radar to optimize signal timing..."); this.intersection.updateMetrics(10, 0, -5); break; case 2: console.log("Using Cameras to improve safety..."); this.intersection.updateMetrics(5, 15, 0); break; case 3: console.log("Using V2X to reduce emissions..."); this.intersection.updateMetrics(5, 5, -15); break; case 4: console.log("Accessing Mobility OS Store..."); this.intersection.updateMetrics(5, 5, -5); break; } this.turn++; this.playTurn(); } endGame() { console.log("\n--- Game Over ---"); console.log(`Final Score: ${this.intersection.score}`); console.log("Thanks for playing Intersection!"); } } // Start the game const game = new Game(); game.start();
 
Your cart

We value your privacy

We use cookies to customize your browsing experience, serve personalized ads or content, and analyze traffic to our site.