#game-board {
width: 500px;
height: 500px;
border: 1px solid black;
}
// Get the game board element
var board = document.getElementById("game-board");
// Get the 2D rendering context
var ctx = board.getContext("2d");
// Define the snake as an array of blocks
var snake = [{x: 150, y: 150}, {x: 140, y: 150}, {x: 130, y: 150}];
// Draw the snake on the board
for (var i = 0; i < snake.length; i++) {
ctx.fillStyle = "green";
ctx.fillRect(snake[i].x, snake[i].y, 10, 10);
}
// Define the food as a single block
var food = {x: 300, y: 300};
// Draw the food on the board
ctx.fillStyle = "red";
ctx.fillRect(food.x, food.y, 10, 10);
0 Comments