我正在制作一个新的“打地鼠”样式的游戏,孩子们需要按照问题的要求击打正确的数字。目前进展顺利,我已经设置了计时器、记录正确和错误答案,当游戏开始时,我会在容器中随机出现一些名为“characters”的div。
我去掉了“播放”按钮,用“简单”、“中等”和“困难”替代。当点击模式时,我希望速度发生变化。这三个按钮共享“game_settings”类。
以下是处理动画的代码。
我去掉了“播放”按钮,用“简单”、“中等”和“困难”替代。当点击模式时,我希望速度发生变化。这三个按钮共享“game_settings”类。
以下是处理动画的代码。
function randomFromTo(from, to) {
return Math.floor(Math.random() * (to - from + 1) + from);
}
function scramble() {
var children = $('#container').children();
var randomId = randomFromTo(1, children.length);
moveRandom("char" + randomId);
}
var currentMoving = [];
function moveRandom(id) {
// If this one's already animating, skip it
if ($.inArray(id, currentMoving) !== -1) {
return;
}
// Mark this one as animating
currentMoving.push(id);
var cPos = $('#container').offset();
var cHeight = $('#container').height();
var cWidth = $('#container').width();
var bWidth = $('#' + id).width();
var bHeight = $('#' + id).css('top', '395px').fadeIn(100).animate({
'top': '-55px'
}, 6000).fadeOut(100);
maxWidth = cPos.left + cWidth - bWidth;
minWidth = cPos.left;
newWidth = randomFromTo(minWidth, maxWidth);
$('#' + id).css({
left: newWidth
}).fadeIn(1000, function () {
setTimeout(function () {
$('#' + id).fadeOut(1000);
// Mark this as no longer animating
var ix = $.inArray(id, currentMoving);
if (ix !== -1) {
currentMoving.splice(ix, 1);
}
window.cont++;
}, 1000);
});
}
我该如何使这些设置根据一开始选择的难度进行更改?