| |
| <div class="container">
|
| <div class="wp-block-button is-style-outline">
|
| <button id="startButton" class="button">Start New Game</button>
|
| <button id="loadButton" class="button">Load Game</button>
|
| </div>
|
| <div id="gameControls" style="display: none;">
|
| <h2>Round: <span id="roundNumber">1</span></h2>
|
| <button id="progressButton" class="button">Progress to Next Round</button>
|
| <button id="saveButton" class="button">Save Game</button>
|
| <div class="output">
|
| <h3>Market Prices</h3>
|
| <pre id="marketPrices"></pre>
|
| <h3>Nation Data</h3>
|
| <pre id="nationData"></pre>
|
| </div>
|
| </div>
|
| </div>
|
|
|
| <script>
|
|
|
| const NATIONS = Array.from({ length: 15 }, (_, i) => `Nation${i + 1}`);
|
| const INDUSTRIES = {
|
| IT: 1000,
|
| Auto: 2000,
|
| Agriculture: 500,
|
| Defense: 5000,
|
| FinancialServices: 4000,
|
| };
|
| const ROUNDS = 10;
|
| const SAVE_KEY = "game_save";
|
|
|
|
|
| let gameState = null;
|
|
|
|
|
| function initializeGame() {
|
| gameState = {
|
| round: 1,
|
| marketPrices: { ...INDUSTRIES },
|
| nations: NATIONS.reduce((acc, nation) => {
|
| acc[nation] = { ...INDUSTRIES };
|
| return acc;
|
| }, {}),
|
| };
|
| updateUI();
|
| }
|
|
|
|
|
| function saveGame() {
|
| localStorage.setItem(SAVE_KEY, JSON.stringify(gameState));
|
| alert("Game saved!");
|
| }
|
|
|
|
|
| function loadGame() {
|
| const savedGame = localStorage.getItem(SAVE_KEY);
|
| if (savedGame) {
|
| gameState = JSON.parse(savedGame);
|
| updateUI();
|
| alert("Game loaded!");
|
| } else {
|
| alert("No saved game found.");
|
| }
|
| }
|
|
|
|
|
| function progressRound() {
|
| if (gameState.round < ROUNDS) {
|
| gameState.round += 1;
|
|
|
| for (const industry in gameState.marketPrices) {
|
| gameState.marketPrices[industry] *= 1 + (Math.random() * 0.2 - 0.1);
|
| }
|
| updateUI();
|
| } else {
|
| alert("Game over! You've reached the final round.");
|
| }
|
| }
|
|
|
|
|
| function updateUI() {
|
| document.getElementById("roundNumber").textContent = gameState.round;
|
| document.getElementById("marketPrices").textContent = JSON.stringify(gameState.marketPrices, null, 2);
|
| document.getElementById("nationData").textContent = JSON.stringify(gameState.nations, null, 2);
|
| }
|
|
|
|
|
| document.getElementById("startButton").addEventListener("click", () => {
|
| initializeGame();
|
| document.getElementById("gameControls").style.display = "block";
|
| });
|
|
|
| document.getElementById("loadButton").addEventListener("click", () => {
|
| loadGame();
|
| document.getElementById("gameControls").style.display = "block";
|
| });
|
|
|
| document.getElementById("progressButton").addEventListener("click", progressRound);
|
| document.getElementById("saveButton").addEventListener("click", saveGame);
|
| </script>
|
| |
| |
Comments