简体   繁体   English

蛇游戏结束

[英]Game over on Snake Game

I'm doing a snake game and I want to display a game over when the spaceship crashes. 我正在做蛇游戏,我想在飞船坠毁时重新展示游戏 I want that the Game Over image appears and does something like floating on the center of the boardgame. 我希望出现游戏结束图像,并像在棋盘游戏的中心浮动一样。

I think that I have to place here but don't know how to do it. 我认为我必须放在这里,但不知道该怎么做。

var makeAStep = function() {
if (snake.detectCollision(snake.velocity) === true) {
    var explosion = $('<div id="explosion"><img src="images/explosion.gif"></div>');
    var newcss = {
        top: parseInt($("#head").css("top").substring(0, $("#head").css("top").length - 2)) - 90 + 'px',
        left: parseInt($("#head").css("left").substring(0, $("#head").css("left").length - 2)) - 61 + 'px',
        position: 'absolute'
    };
    explosion.css(newcss);
    $('#box').append(explosion);
    var alertInterval = setInterval(function() {
        clearInterval(alertInterval);
        $('#explosion').remove();
    }, 800);

    clearInterval(intervalHandler);
    intervalHandler == null;
    return;
}

var lastItemPosition = snake.body[snake.body.length - 1].position.copy();

snake.move();

var iJustAteSomeFood = snake.getHead().isOnPosition(food.position);

if (iJustAteSomeFood == true) {
    food.updateScore();
    generateFood();
    snake.body.push(new snakeItem(lastItemPosition));
}

snake.screenUpdate({updateFireballs: iJustAteSomeFood});

}; };

The complete code 完整的代码

Since you are using jQuery, you can call modal dialog 由于您使用的是jQuery,因此可以调用模式对话框

if (snake.detectCollision(snake.velocity) === true) {
  $("#dialog").dialog("open"); // here
  ...
}

after you create the <div id="dialog">...</div> , see the link example. 创建<div id="dialog">...</div> ,请参见链接示例。

Note: Nice game. 注意:不错的游戏。 You should disable 180° rotation, ie spaceship moving to the left should not react to right arrow. 您应该禁用180°旋转,即飞船向左移动不应对向右箭头做出反应。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM