简体   繁体   English

如何为内置JavaScript的蛇游戏创建重启按钮?

[英]How to create a restart button for my snake game built in javascript?

var game = "play"; //This is the game variable   

$("#Restart").click(function() { //Using the buttons        
            console.log("Restart Works"); 
            gamerestart();
            ctx.fill
    });    

function gamerestart(){
        game = gamerestart;
        ctx.fillStyle = '#00008b';
        ctx.fillRect(0,0, canvas.width, canvas.height);
    }

Used this method to make the other buttons work but restart one is not working? 使用此方法使其他按钮正常工作,但重新启动一个按钮无效吗?

function gamerestart(){
    game = gamerestart; //quotes?
    ctx.fillStyle = '#00008b';
    ctx.fillRect(0,0, canvas.width, canvas.height);
}

Shouldn't it be "gamerestart"? 不应该是“ gamerestart”吗?

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

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