|
|
|
@@ -0,0 +1,65 @@ |
|
|
|
"use strict"; |
|
|
|
|
|
|
|
let belongings = {} |
|
|
|
|
|
|
|
let resources = { |
|
|
|
"food": 0 |
|
|
|
} |
|
|
|
|
|
|
|
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() { |
|
|
|
let productivity = 0; |
|
|
|
for (const [key, value] of Object.entries(belongings)) { |
|
|
|
productivity += productivityOf(key); |
|
|
|
} |
|
|
|
return productivity; |
|
|
|
} |
|
|
|
|
|
|
|
// here's where upgrades will go :3 |
|
|
|
|
|
|
|
function productivityOf(type) { |
|
|
|
let baseProd = buildings[type].prod; |
|
|
|
|
|
|
|
return baseProd * belongings[type].count; |
|
|
|
} |
|
|
|
|
|
|
|
// update stuff |
|
|
|
|
|
|
|
function updateResources() { |
|
|
|
addResources(); |
|
|
|
displayResources(); |
|
|
|
|
|
|
|
setTimeout(updateResources, 1000/updateRate); |
|
|
|
} |
|
|
|
|
|
|
|
function addResources() { |
|
|
|
resources.food += calculateProductivity() * 1 / updateRate; |
|
|
|
} |
|
|
|
|
|
|
|
function displayResources() { |
|
|
|
document.getElementById("resource-food").innerText = "Food: " + render(resources.food); |
|
|
|
} |
|
|
|
|
|
|
|
window.onload = function() { |
|
|
|
setup(); |
|
|
|
|
|
|
|
setTimeout(updateResources, 1000/updateRate); |
|
|
|
} |