I was looking up on how to build a snake game in Javascript and upon looking up some code i came across this function that creates the map for the snake to roam on. I'm not exactly sure how it works but i tested it and it works. Thank you for your time.
function createMap(){
document.write("<table>");
for(var y = 0; y < height; y++){
document.write("<tr>");
for(var x = 0; x < width; x++){
if(y == 0 || y == height-1 || x == 0 || x == width-1)
document.write("<td class='wall' id='"+ x + "-" + y + "'>
</td>");
else
document.write("<td class='blank' id='"+ x + "-" + y + "'>
</td>");
}
document.write("</tr>");
}
document.write("</table>");
document.write("<h1 id='score'>Score: </h1>");
}
Aucun commentaire:
Enregistrer un commentaire