<script>
// import declarations
import { onMount } from 'svelte';
// variable declarations
let money = 20;
let numberOfBuilding = 0;
let buildingProduction = 1; // $ produced per building per tick
let tickSpeed = 1000;
// reactive declarations
$: cantBuy = cost > money;
$: cost = (numberOfBuilding + 1) * 5;
$: productionPerTick = numberOfBuilding * buildingProduction;
// function declarations
// update the values of `money` and `numberBuildings`
function updateNumbers(){
money -= cost;
numberOfBuilding += 1
}
// update `money` with `productionPerTick` and set a timeout to call itself after `tickSpeed` ms
function updateMoney(){
money += productionPerTick;
setTimeout(updateMoney, tickSpeed);
}
// lifecycle functions
onMount(() => {
updateMoney();
});
</script>
<style>