|
|
@@ -8,23 +8,6 @@ let resources = { |
|
|
|
|
|
|
|
|
let updateRate = 60; |
|
|
let updateRate = 60; |
|
|
|
|
|
|
|
|
// setup stuff lol |
|
|
|
|
|
|
|
|
|
|
|
// we'll initialize the dict of buildings we can own |
|
|
|
|
|
|
|
|
|
|
|
function setup() { |
|
|
|
|
|
for (const [key, value] of Object.entries(buildings)) { |
|
|
|
|
|
belongings[key] = {}; |
|
|
|
|
|
belongings[key].count = 0; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
console.log(belongings) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function price(type) { |
|
|
|
|
|
return buildings[type].cost * Math.pow(1.02, belongings[type].count) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function calculateProductivity() { |
|
|
function calculateProductivity() { |
|
|
let productivity = 0; |
|
|
let productivity = 0; |
|
|
for (const [key, value] of Object.entries(belongings)) { |
|
|
for (const [key, value] of Object.entries(belongings)) { |
|
|
@@ -41,11 +24,29 @@ function productivityOf(type) { |
|
|
return baseProd * belongings[type].count; |
|
|
return baseProd * belongings[type].count; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function costOf(type) { |
|
|
|
|
|
let baseCost = buildings[type].cost |
|
|
|
|
|
|
|
|
|
|
|
let countCost = baseCost * Math.pow(1.02, belongings[type].count); |
|
|
|
|
|
|
|
|
|
|
|
return countCost; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function buyBuilding(type) { |
|
|
|
|
|
let cost = costOf(type); |
|
|
|
|
|
|
|
|
|
|
|
if (resources.food > cost) { |
|
|
|
|
|
belongings[type].count += 1; |
|
|
|
|
|
resources.food -= cost; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
// update stuff |
|
|
// update stuff |
|
|
|
|
|
|
|
|
function updateResources() { |
|
|
function updateResources() { |
|
|
addResources(); |
|
|
addResources(); |
|
|
displayResources(); |
|
|
displayResources(); |
|
|
|
|
|
displayBuildings(); |
|
|
|
|
|
|
|
|
setTimeout(updateResources, 1000/updateRate); |
|
|
setTimeout(updateResources, 1000/updateRate); |
|
|
} |
|
|
} |
|
|
@@ -58,6 +59,42 @@ function displayResources() { |
|
|
document.getElementById("resource-food").innerText = "Food: " + render(resources.food); |
|
|
document.getElementById("resource-food").innerText = "Food: " + render(resources.food); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function displayBuildings() { |
|
|
|
|
|
for (const [key, value] of Object.entries(belongings)) { |
|
|
|
|
|
document.getElementById("building-" + key).innerText = buildings[key].name + ": " + belongings[key].count; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function eatMicro() { |
|
|
|
|
|
resources.food += 1; |
|
|
|
|
|
} |
|
|
|
|
|
// setup stuff lol |
|
|
|
|
|
|
|
|
|
|
|
// we'll initialize the dict of buildings we can own |
|
|
|
|
|
|
|
|
|
|
|
function setup() { |
|
|
|
|
|
initializeData(); |
|
|
|
|
|
registerListeners(); |
|
|
|
|
|
|
|
|
|
|
|
console.log(belongings) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function initializeData() { |
|
|
|
|
|
for (const [key, value] of Object.entries(buildings)) { |
|
|
|
|
|
belongings[key] = {}; |
|
|
|
|
|
belongings[key].count = 0; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function registerListeners() { |
|
|
|
|
|
document.querySelectorAll(".building-button").forEach(function(button) { |
|
|
|
|
|
let id = button.id.replace("building-", ""); |
|
|
|
|
|
button.addEventListener("click", function() { buyBuilding(id); }); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
document.querySelector("#tasty-micro").addEventListener("click", eatMicro); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
window.onload = function() { |
|
|
window.onload = function() { |
|
|
setup(); |
|
|
setup(); |
|
|
|
|
|
|
|
|
|