Skip to content

Define object for food

game ={ board: [][] cell, snakes: [] snake, update: function(),
newGame: function(), spawnFood: function(food), }

where newGame returns a new game object with empty board and snake array

spawnFood returns a new food object with random x and y coordinates

update moves snakes, checks for collisions, spawns food, consumes food,

cell = { x: int, y: int, item: (snake, food, empty), }

cell can be empty, contain a snake, or contain food

snake = {
id: int,
body: [] cell,
direction: (up, down, left, right),
updateDirection: function(direction), }

snake has an id, a body array of cells, and a direction

updateDirection changes the direction of the snake - can be any direction except the opposite of the current direction

food = {
x: int, y: int, lengthParam: int, widthParam: int, otherParam: any, }

food has x and y coordinates, and a length, width, and other parameter

we should implement this as separate json objects for different types of food that give different effects