我试图在HTML5,javascript和css中制作闲置游戏。到目前为止,我认为我已经很好了,但是当我测试它时,它并没有像我希望的那样工作。不是让一个资源一次增加1,而是等待一秒钟,然后直接跳到101 ...
HTML:
<!DOCTYPE html>
<html>
<head>
<link rel='stylesheet' href='style.css'/>
<script src='script.js'></script>
</head>
<body>
<div class='Main'>
<script>
var ResourceManager = {
Re1: {
Food: {
unlocked: true,
quantity: 100,
max_quantity: 100,
re_ps: 1,
workers: 1
},
Wood: {
unlocked: true,
quantity: 0,
max_quantity: 10,
re_ps: 0,
workers: 0
},
Stone: {
unlocked: false,
quantity: 0,
max_quantity: 10,
re_ps: 0,
workers: 0
}
}
}
var RE1 = ResourceManager.Re1;
var Food_ps = RE1.Food.re_ps * RE1.Food.workers;
setInterval(function() {
if(RE1.Food.quantity <= RE1.Food.max_quantity) {
RE1.Food.quantity += Food_ps;
}
document.getElementById('RE1-Food').innerHTML = RE1.Food.quantity;
}, 1000);
</script>
<div class='Main-ResourceShow'>
<p id='MRS_Re1-Food'>Food: <span id='RE1-Food'></span> - <span id='MaxRE1-Food'></p>
<p id='MRS_Re1-Wood'>Wood: <span id='RE1-Wood'></span> - <span id='MaxRE1-Wood'></span></p>
<p id='MRS-Re1-Stone'>Stone: <span id='RE1-Stone'></span> - <span id='MaxRE1-Stone'></p>
</div>
</div>
</body>
</html>
答案 0 :(得分:2)
您可能希望RE1.Food.quantity
从0
而不是100
开始?
e.g。
Food: {
unlocked: true,
quantity: 0,
max_quantity: 100,
re_ps: 1,
workers: 1
},
答案 1 :(得分:1)
quantity
需要从0
var ResourceManager = {
Re1: {
Food: {
unlocked: true,
quantity: 0,
max_quantity: 100,
re_ps: 1,
workers: 1
},
Wood: {
unlocked: true,
quantity: 0,
max_quantity: 10,
re_ps: 0,
workers: 0
},
Stone: {
unlocked: false,
quantity: 0,
max_quantity: 10,
re_ps: 0,
workers: 0
}
}
}