期待通りに動作しない場合:gold.health
はplayer.ATK
によって減算される条件は、私がここにこのコードを持っ
は
var player = {
ATK: 30
}
function start(place) {
\t if (place == 'goldMine') {
\t \t canvas = document.getElementById('canvas');
\t \t ctx = canvas.getContext('2d');
\t \t var player = {
\t \t \t x: 0,
\t \t \t y: 197.5
\t \t };
\t \t var slope = {
\t \t \t x: 159,
\t \t \t y: 198.5,
\t \t \t up: false
\t \t };
\t \t var gold = {
\t \t \t x: 240,
\t \t \t y: 188,
\t \t \t mined: false,
health: 20,
\t \t \t x1: 200,
\t \t \t y1: 188,
\t \t \t mined1: false
\t \t };
\t \t ctx.font = '15px Monospace';
\t \t var move = setInterval(function(){player.x += 7;},50)
\t \t var draw = setInterval(function() {
\t \t \t ctx.clearRect(0, 0, canvas.width, canvas.height)
\t \t \t ctx.fillText('\\o/',player.x,player.y);
\t \t \t ctx.fillText("__________________",0,195.5);
\t \t \t ctx.fillText("/",slope.x,slope.y);
\t \t \t ctx.fillText("______________________________________________________",165.5,184.5);
\t \t \t ctx.fillText("/0\\",gold.x,gold.y);
\t \t \t ctx.fillText("/0\\",gold.x1,gold.y1);
\t \t \t if (player.x >= slope.x - 23 && !slope.up) {
\t \t \t \t player.y -= 10;
\t \t \t \t slope.up = true;
\t \t \t }
\t \t \t if (player.x >= gold.x - 23 && gold.mined == false) {
\t \t \t \t clearInterval(move)
console.log(gold.health)
dam = setInterval(function(){gold.health -= player.ATK}, 1000)
console.log(gold.health)
\t \t \t }
\t \t \t if (gold.health <= 0) {
\t \t \t \t \t gold.mined = true; gold.y = 210; move = setInterval(function(){player.x += 7;},50)
\t \t \t }
\t \t \t if (player.x >= gold.x1 - 23.99 && gold.mined == false) {
\t \t \t \t gold.y1 = 250;
\t \t \t \t gold.mined1 = true;
\t \t \t }
\t \t }, 50)
\t }
}
start('goldMine')
<canvas id='canvas' width='985' height='200'></canvas>
player.ATK
で1000msごとに引くべきです。しかし、なぜそれは未定義に戻るのでしょうか?私はちょうどJavaScriptを使用してこれを解決することはできますか?
https://stackoverflow.com/help/mcve – Isaac