| |
| </head>
|
| <body>
|
| <div id="gameState">
|
| <h1>Game State</h1>
|
| <p>Round: <span id="round">0</span>/10</p>
|
| <p>Cash: $<span id="cash">0</span></p>
|
| <p>Automobile Production: <span id="production">0</span> units</p>
|
| <p>Industry Level: <span id="level">0</span></p>
|
| </div>
|
|
|
| <div class="wp-block-button is-style-outline">
|
| <button id="startButton" class="wp-block-button__link wp-element-button">Start New Game</button>
|
| </div>
|
| <div class="wp-block-button is-style-outline">
|
| <button id="saveButton" class="wp-block-button__link wp-element-button">Save Game</button>
|
| </div>
|
| <div class="wp-block-button is-style-outline">
|
| <button id="loadButton" class="wp-block-button__link wp-element-button">Load Game</button>
|
| </div>
|
| <div class="wp-block-button is-style-outline">
|
| <button id="restartButton" class="wp-block-button__link wp-element-button">Restart Game</button>
|
| </div>
|
| <div class="wp-block-button is-style-outline">
|
| <button id="progressButton" class="wp-block-button__link wp-element-button">Progress to Next Round</button>
|
| </div>
|
|
|
| <script>
|
|
|
| let gameData = {
|
| round: 0,
|
| cash: 0,
|
| production: 0,
|
| level: 0,
|
| };
|
|
|
|
|
| function updateDisplay() {
|
| document.getElementById('round').textContent = gameData.round;
|
| document.getElementById('cash').textContent = gameData.cash;
|
| document.getElementById('production').textContent = gameData.production;
|
| document.getElementById('level').textContent = gameData.level;
|
| }
|
|
|
|
|
| function startGame() {
|
| gameData = {
|
| round: 1,
|
| cash: 10000,
|
| production: 10,
|
| level: 1,
|
| };
|
| updateDisplay();
|
| alert('New game started!');
|
| }
|
|
|
|
|
| function saveGame() {
|
| localStorage.setItem('gameState', JSON.stringify(gameData));
|
| alert('Game saved!');
|
| }
|
|
|
|
|
| function loadGame() {
|
| const savedGame = localStorage.getItem('gameState');
|
| if (savedGame) {
|
| gameData = JSON.parse(savedGame);
|
| updateDisplay();
|
| alert('Game loaded!');
|
| } else {
|
| alert('No saved game found.');
|
| }
|
| }
|
|
|
|
|
| function restartGame() {
|
| startGame();
|
| alert('Game restarted!');
|
| }
|
|
|
|
|
| function progressRound() {
|
| if (gameData.round < 10) {
|
| gameData.round += 1;
|
| gameData.cash += gameData.production * 5000;
|
| updateDisplay();
|
| alert(`Round ${gameData.round - 1} ended. Starting round ${gameData.round}.`);
|
| } else {
|
| alert('Game over!');
|
| }
|
| }
|
|
|
|
|
| document.getElementById('startButton').addEventListener('click', startGame);
|
| document.getElementById('saveButton').addEventListener('click', saveGame);
|
| document.getElementById('loadButton').addEventListener('click', loadGame);
|
| document.getElementById('restartButton').addEventListener('click', restartGame);
|
| document.getElementById('progressButton').addEventListener('click', progressRound);
|
|
|
|
|
| updateDisplay();
|
| </script>
|
| </body>
|
| |
| |
Comments