JSFiddle - React, Tailwind, and code Playground
JavaScript
var time_multi = 1;
income_done = 0;
var buildings = 0;
var inhabitants = parseInt($('.people').text());
var work = 0;
var people = 0;
var product = 0;
//counts time
setInterval(function(){
var time = parseInt($('.time').text())
$('.time').text(time + 1);
},1000);
function grid(){ //select the cells
cell = 1 + Math.floor(Math.random() * 10);
row = 0 + Math.floor(Math.random() * -10);
}
forest = 4 + Math.floor(Math.random() * 15);
forest_new = 1;
function mapGen(){
if(forest_new <= forest){
grid();
if($('.'+row).find('.'+cell).empty()){
$('.'+row).find('.'+cell).append('<img data-income="0" data-mat="0" class="forest" src="assets/forest.png"/>');
forest_new = forest_new + 1;
if(forest_new > forest){
newBuilding();
}else{
setTimeout(function(){
mapGen();
},10);
}
}else{
}
}
}
function build(){ //build the new selected building if it is possible
mon = parseInt($('.money').text());
mat = parseInt($('.materials').text());
pop = parseInt($('.people').text());
if(mon >= new_money){
if(mat >= new_mat){
grid();
if($('.'+row).find('.'+cell).empty()){
$('.'+row).find('.'+cell).append('<img class=" '+clas +'" src="'+next +'" data-income="'+ income +'" data-mat="'+ materials + '" data-inh="'+inhabitants+'"/>');
$('.money').text(mon - new_money);
$('.materials').text(mat - new_mat);
$('.people').text(pop + inhabitants);
buildings();
}else{
//console.log('filled');
setTimeout(function(){
build();
},100 );
}
}
}
}
function buildings(){ //
next = 1 + Math.floor(Math.random() * 10);
if(next == 1){
newBuilding();
}
setTimeout(function(){
buildings();
},100);
}
next_row = - 1;
next_cell = 1;
max_row = $('.game .row').length;
max_cell = $('.-1 .cell').length;
function Income(){ //income loop
//checks if selected cell is empty
if($('.' + next_row).find('.' + next_cell).find('img').length > 0 ){
console.log('filled');
mon =...