如何为我用javascript构建的蛇游戏创建一个重启按钮?

时间:2017-04-25 15:07:01

标签: javascript html

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);
    }

使用此方法使其他按钮工作但重启一个按钮不起作用?

1 个答案:

答案 0 :(得分:0)

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

不应该是" gamerestart"?