在我的游戏中,如果汽车发生碰撞,推土机运行间隔应该在 jquery 上的 1700 之后停止。但是,我的朋友告诉我,推土机不会停在每台计算机的同一个地方。尽管每个相关元素的位置都设置为绝对位置,但每台计算机对 1700 的处理都是相同的。这是为什么?
$(document).ready(function () {
var jump = new Audio("jump.wav");
var bulldozer = new Audio("bulldozer.wav");
var warning = new Audio("warning.wav");
var fireworks = new Audio("fireworks.wav");
$('.restart').click(function () {
location.reload();
});
$('.homepage').click(function () {
window.location.href = 'index.html';
});
$(".textbox").focus();
setTimeout(areyouready, 2000);
function areyouready()
{
throwdice();
function throwdice()
{
var random1 = Math.floor(Math.random() * 150);
var random2 = Math.floor(Math.random() * 150);
$(".firstnumber").text(random1);
$(".secondnumber").text(random2);
}
var movingbulldozer;
movingbulldozer = setInterval(function () {
var bulldozerright = parseInt($(".bulldozer").css("right"))
if (bulldozerright < 1100) {
$(".bulldozer").css("right", "+=2");
}
else {
$(".bulldozer").css("right", "-=1500");
}
}, 5);
var winpoint;
winpoint = setInterval(function ()
{
var num1 = parseInt($(".firstnumber").html());
var num2 = parseInt($(".secondnumber").html());
var total = num1 + num2;
var entry = parseInt($(".textbox").val());
var cartop = parseInt($(".car2").css("top"))
if (entry == total && cartop == 121)
{
$(".car2").css("top", "-=150");
function gobacksoil() {
$(".car2").css("top", "+=150");
}
setTimeout(gobacksoil, 1000);
jump.play();
$(".textbox").val("");
throwdice();
var oldscore = parseInt($(".expertscoreboard").html());
var newscore = oldscore + 15;
$(".expertscoreboard").html(newscore);
if (newscore == 150)
{
clearInterval(movingbulldozer);
$('.bulldozer').hide();
$('.firstnumber').hide();
$('.secondnumber').hide();
$(".car2").css("top", "+=150");
$(".textbox").val("YOU WON THE GAME!");
fireworks.play();
$('.fireworks').fadeIn(3000);
$('.textbox').attr("disabled", true);
}
}
else if (entry == total && cartop != 121)
{
warning.play();
$(".textbox").val("");
}
}, 50);
var gameover;
gameover = setInterval(function () {
var bulldozerdistance = parseInt($(".bulldozer").css("right"))
var cartop = parseInt($(".car2").css("top"))
if (bulldozerdistance == 350 && cartop == 121)
{
$(".car2").addClass("crashedcar");
bulldozer.play();
$('.textbox').attr("disabled", true);
$('.textbox').val("game over");
endinggame = setTimeout(function ()
{
clearInterval(movingbulldozer);
}, 1700);
}
}, 1);
}
});