简体   繁体   中英

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"?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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