| |
| <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
| <div class="container">
|
| <h2 style="text-align: center;">Nation Details</h2>
|
| <table id="nationDetails" style="width: 100%; border-collapse: collapse; margin: 20px 0;">
|
| <thead>
|
| <tr>
|
| <th style="padding: 15px; text-align: center; border: 1px solid #ddd;">Industry</th>
|
| <th style="padding: 15px; text-align: center; border: 1px solid #ddd;">Output</th>
|
| <th style="padding: 15px; text-align: center; border: 1px solid #ddd;">Upgrade Level</th>
|
| <th style="padding: 15px; text-align: center; border: 1px solid #ddd;">Income from Industry</th>
|
| <th style="padding: 15px; text-align: center; border: 1px solid #ddd;">Percentage Contribution to Exports</th>
|
| <th style="padding: 15px; text-align: center; border: 1px solid #ddd;">Investment Cost</th>
|
| <th style="padding: 15px; text-align: center; border: 1px solid #ddd;">Divestment Yield</th>
|
| </tr>
|
| </thead>
|
| <tbody>
|
|
|
| </tbody>
|
| </table>
|
| <div>
|
| <p><strong>Cash:</strong> <span id="nationCash"></span></p>
|
| <p><strong>Total Income (This Round):</strong> <span id="nationIncome"></span></p>
|
| <p><strong>Debt:</strong> <span id="nationDebt"></span></p>
|
| </div>
|
|
|
| <div style="width: 50%; margin: 20px auto;">
|
| <canvas id="pieChart"></canvas>
|
| </div>
|
|
|
|
|
| <div class="wp-block-jetpack-contact-form" style="margin-top: 20px;">
|
| <div class="wp-block-jetpack-field-select">
|
| <label for="investDropdown">Select the Industry to invest in:</label>
|
| <select id="investDropdown">
|
| <option value="IT">IT</option>
|
| <option value="Agriculture">Agriculture</option>
|
| <option value="Auto">Auto</option>
|
| <option value="Defense">Defense</option>
|
| <option value="FinancialServices">Financial Services</option>
|
| </select>
|
| </div>
|
| <div class="wp-block-jetpack-button">
|
| <button id="investButton" class="wp-block-button__link wp-element-button">Invest</button>
|
| </div>
|
| </div>
|
|
|
|
|
| <div class="wp-block-jetpack-contact-form" style="margin-top: 20px;">
|
| <div class="wp-block-jetpack-field-select">
|
| <label for="divestDropdown">Select the Industry to divest from:</label>
|
| <select id="divestDropdown">
|
| <option value="IT">IT</option>
|
| <option value="Agriculture">Agriculture</option>
|
| <option value="Auto">Auto</option>
|
| <option value="Defense">Defense</option>
|
| <option value="FinancialServices">Financial Services</option>
|
| </select>
|
| </div>
|
| <div class="wp-block-jetpack-button">
|
| <button id="divestButton" class="wp-block-button__link wp-element-button">Divest</button>
|
| </div>
|
| </div>
|
| </div>
|
|
|
|
|
| <h2 style="text-align: center;">Debt Schedule</h2>
|
| <table id="debtSchedule" style="width: 100%; border-collapse: collapse; margin: 20px 0;">
|
| <thead>
|
| <tr>
|
| <th style="padding: 15px; text-align: center; border: 1px solid #ddd;">Round</th>
|
| <th style="padding: 15px; text-align: center; border: 1px solid #ddd;">Debt Amount</th>
|
| <th style="padding: 15px; text-align: center; border: 1px solid #ddd;">Debt Coverage</th>
|
| </tr>
|
| </thead>
|
| <tbody>
|
|
|
| </tbody>
|
| </table>
|
|
|
| <script>
|
| const nationName = "Zephyria";
|
| const SAVE_KEY = "game_save";
|
|
|
|
|
| function calculateInvestmentCost(currentLevel) {
|
| return Math.floor(1000 * Math.pow(1.5, currentLevel));
|
| }
|
|
|
|
|
| function calculateDivestmentYield(currentLevel) {
|
| return Math.floor(500 * Math.pow(1.2, currentLevel));
|
| }
|
|
|
|
|
| function loadGameState() {
|
| const savedGame = localStorage.getItem(SAVE_KEY);
|
| if (savedGame) {
|
| return JSON.parse(savedGame);
|
| }
|
| return null;
|
| }
|
|
|
|
|
| function saveGameState(gameState) {
|
| localStorage.setItem(SAVE_KEY, JSON.stringify(gameState));
|
| }
|
|
|
|
|
| function displayNationDetails(gameState) {
|
| if (!gameState || !gameState.nations[nationName]) {
|
| alert("Game state or nation not found!");
|
| return;
|
| }
|
|
|
| const nation = gameState.nations[nationName];
|
| const marketPrices = gameState.marketPrices;
|
|
|
|
|
| document.getElementById("nationName").textContent = nationName;
|
|
|
|
|
| const totalIncome = Object.entries(nation.output).reduce((total, [industry, output]) => {
|
| return total + output * marketPrices[industry];
|
| }, 0);
|
|
|
|
|
| const industries = [];
|
| const percentages = [];
|
|
|
|
|
| const tableBody = document.querySelector("#nationDetails tbody");
|
| tableBody.innerHTML = "";
|
|
|
| Object.entries(nation.output).forEach(([industry, output]) => {
|
| const row = document.createElement("tr");
|
|
|
|
|
| const industryCell = document.createElement("td");
|
| industryCell.textContent = industry;
|
| industryCell.style.padding = "15px";
|
| industryCell.style.textAlign = "center";
|
| industryCell.style.border = "1px solid #ddd";
|
| row.appendChild(industryCell);
|
|
|
|
|
| const outputCell = document.createElement("td");
|
| outputCell.textContent = output;
|
| outputCell.style.padding = "15px";
|
| outputCell.style.textAlign = "center";
|
| outputCell.style.border = "1px solid #ddd";
|
| row.appendChild(outputCell);
|
|
|
|
|
| const upgradeCell = document.createElement("td");
|
| upgradeCell.textContent = nation.upgrades[industry];
|
| upgradeCell.style.padding = "15px";
|
| upgradeCell.style.textAlign = "center";
|
| upgradeCell.style.border = "1px solid #ddd";
|
| row.appendChild(upgradeCell);
|
|
|
|
|
| const incomeFromIndustry = output * marketPrices[industry];
|
| const incomeCell = document.createElement("td");
|
| incomeCell.textContent = incomeFromIndustry.toLocaleString();
|
| incomeCell.style.padding = "15px";
|
| incomeCell.style.textAlign = "center";
|
| incomeCell.style.border = "1px solid #ddd";
|
| row.appendChild(incomeCell);
|
|
|
|
|
| const percentageContribution = ((incomeFromIndustry / totalIncome) * 100).toFixed(2);
|
| const percentageCell = document.createElement("td");
|
| percentageCell.textContent = `${percentageContribution}%`;
|
| percentageCell.style.padding = "15px";
|
| percentageCell.style.textAlign = "center";
|
| percentageCell.style.border = "1px solid #ddd";
|
| row.appendChild(percentageCell);
|
|
|
|
|
| const investmentCost = calculateInvestmentCost(nation.upgrades[industry]);
|
| const investmentCostCell = document.createElement("td");
|
| investmentCostCell.textContent = investmentCost.toLocaleString();
|
| investmentCostCell.style.padding = "15px";
|
| investmentCostCell.style.textAlign = "center";
|
| investmentCostCell.style.border = "1px solid #ddd";
|
| row.appendChild(investmentCostCell);
|
|
|
|
|
| const divestmentYield = calculateDivestmentYield(nation.upgrades[industry]);
|
| const divestmentYieldCell = document.createElement("td");
|
| divestmentYieldCell.textContent = divestmentYield.toLocaleString();
|
| divestmentYieldCell.style.padding = "15px";
|
| divestmentYieldCell.style.textAlign = "center";
|
| divestmentYieldCell.style.border = "1px solid #ddd";
|
| row.appendChild(divestmentYieldCell);
|
|
|
| tableBody.appendChild(row);
|
|
|
|
|
| industries.push(industry);
|
| percentages.push(parseFloat(percentageContribution));
|
| });
|
|
|
|
|
| document.getElementById("nationCash").textContent = nation.cash.toLocaleString();
|
| document.getElementById("nationIncome").textContent = totalIncome.toLocaleString();
|
| document.getElementById("nationDebt").textContent = nation.debt.toLocaleString();
|
|
|
|
|
| renderPieChart(industries, percentages);
|
|
|
|
|
| const debtScheduleBody = document.querySelector("#debtSchedule tbody");
|
| debtScheduleBody.innerHTML = "";
|
|
|
| const debtSchedule = [
|
| { round: 1, debtAmount: 1000, debtCoverage: 200 },
|
| { round: 2, debtAmount: 800, debtCoverage: 200 },
|
| { round: 3, debtAmount: 600, debtCoverage: 200 },
|
| { round: 4, debtAmount: 400, debtCoverage: 200 },
|
| { round: 5, debtAmount: 200, debtCoverage: 200 },
|
| ];
|
|
|
| debtSchedule.forEach(({ round, debtAmount, debtCoverage }) => {
|
| const row = document.createElement("tr");
|
|
|
|
|
| const roundCell = document.createElement("td");
|
| roundCell.textContent = round;
|
| roundCell.style.padding = "15px";
|
| roundCell.style.textAlign = "center";
|
| roundCell.style.border = "1px solid #ddd";
|
| row.appendChild(roundCell);
|
|
|
|
|
| const debtAmountCell = document.createElement("td");
|
| debtAmountCell.textContent = debtAmount.toLocaleString();
|
| debtAmountCell.style.padding = "15px";
|
| debtAmountCell.style.textAlign = "center";
|
| debtAmountCell.style.border = "1px solid #ddd";
|
| row.appendChild(debtAmountCell);
|
|
|
|
|
| const debtCoverageCell = document.createElement("td");
|
| debtCoverageCell.textContent = debtCoverage.toLocaleString();
|
| debtCoverageCell.style.padding = "15px";
|
| debtCoverageCell.style.textAlign = "center";
|
| debtCoverageCell.style.border = "1px solid #ddd";
|
| row.appendChild(debtCoverageCell);
|
|
|
| debtScheduleBody.appendChild(row);
|
| });
|
| }
|
|
|
|
|
| function handleInvest() {
|
| const gameState = loadGameState();
|
| if (!gameState || !gameState.nations[nationName]) {
|
| alert("Game state or nation not found!");
|
| return;
|
| }
|
|
|
| const nation = gameState.nations[nationName];
|
| const selectedIndustry = document.getElementById("investDropdown").value;
|
| if (selectedIndustry && nation.upgrades[selectedIndustry] !== undefined) {
|
| const investmentCost = calculateInvestmentCost(nation.upgrades[selectedIndustry]);
|
| if (nation.cash >= investmentCost) {
|
| nation.cash -= investmentCost;
|
| nation.upgrades[selectedIndustry] += 1;
|
| saveGameState(gameState);
|
| alert(`Successfully invested in ${selectedIndustry}!`);
|
| displayNationDetails(gameState);
|
| } else {
|
| alert("Not enough cash to invest!");
|
| }
|
| } else {
|
| alert("Invalid industry selected.");
|
| }
|
| }
|
|
|
|
|
| function handleDivest() {
|
| const gameState = loadGameState();
|
| if (!gameState || !gameState.nations[nationName]) {
|
| alert("Game state or nation not found!");
|
| return;
|
| }
|
|
|
| const nation = gameState.nations[nationName];
|
| const selectedIndustry = document.getElementById("divestDropdown").value;
|
| if (selectedIndustry && nation.upgrades[selectedIndustry] !== undefined && nation.upgrades[selectedIndustry] > 1) {
|
| const divestmentYield = calculateDivestmentYield(nation.upgrades[selectedIndustry]);
|
| nation.cash += divestmentYield;
|
| nation.upgrades[selectedIndustry] -= 1;
|
| saveGameState(gameState);
|
| alert(`Successfully divested from ${selectedIndustry}!`);
|
| displayNationDetails(gameState);
|
| } else {
|
| alert("Invalid industry selected or industry level is already at minimum.");
|
| }
|
| }
|
|
|
|
|
| function renderPieChart(labels, data) {
|
| const ctx = document.getElementById("pieChart").getContext("2d");
|
| new Chart(ctx, {
|
| type: "pie",
|
| data: {
|
| labels: labels,
|
| datasets: [{
|
| data: data,
|
| backgroundColor: [
|
| "rgba(255, 99, 132, 0.6)",
|
| "rgba(54, 162, 235, 0.6)",
|
| "rgba(255, 206, 86, 0.6)",
|
| "rgba(75, 192, 192, 0.6)",
|
| "rgba(153, 102, 255, 0.6)",
|
| ],
|
| borderWidth: 1,
|
| }],
|
| },
|
| options: {
|
| responsive: true,
|
| plugins: {
|
| legend: {
|
| position: "bottom",
|
| },
|
| tooltip: {
|
| callbacks: {
|
| label: (context) => {
|
| const label = context.label || "";
|
| const value = context.raw || 0;
|
| return `${label}: ${value}%`;
|
| },
|
| },
|
| },
|
| },
|
| },
|
| });
|
| }
|
|
|
|
|
| window.addEventListener("storage", (event) => {
|
| if (event.key === SAVE_KEY) {
|
| const gameState = JSON.parse(event.newValue);
|
| displayNationDetails(gameState);
|
| }
|
| });
|
|
|
|
|
| document.addEventListener("DOMContentLoaded", () => {
|
| const gameState = loadGameState();
|
| if (gameState) {
|
| displayNationDetails(gameState);
|
| } else {
|
| alert("Game state not loaded. Please start or load a game first.");
|
| }
|
|
|
|
|
| document.getElementById("investButton").addEventListener("click", handleInvest);
|
| document.getElementById("divestButton").addEventListener("click", handleDivest);
|
| });
|
| </script>
|
| |
| |
Comments