function resetGame() {
  for (var y = 0; y < HEIGHT; y++) {
    for (var x = 0; x < WIDTH; x++) {
      clearCell(getCell([x, y]));
    }
  }
  snakes.length = 0;
  var snake = new Snake(1);
  snake.direction = directions.RIGHT;
  snakes.push(snake);
  snake.setHead(Math.floor(WIDTH / 2) - 2, Math.floor(HEIGHT / 2) - 1);

  if (player2) {
    snake = new Snake(2);
    snake.direction = directions.LEFT;
    snakes.push(snake);
    snake.setHead(Math.floor(WIDTH / 2) + 2, Math.floor(HEIGHT / 2) + 1);
  }
  // Start snake with a length of three (one head, plus two steps),
  for (var i = 0; i < snakes.length; i++) {
    snakes[i].step(true);
    snakes[i].step(true);
    snakes[i].step(false);
  }
  // Start with two foods on the board.
  addFood();
  addFood();
}
// Clear any existing data, and configure a new game.
Clear any existing data, and configure a new game.
Clear any existing data and configure a new game .
function resetGame() {
  for (var y = 0; y < HEIGHT; y++) {
    for (var x = 0; x < WIDTH; x++) {
      clearCell(getCell([x, y]));
    }
  }
  snakes.length = 0;
  var snake = new Snake(1);
  snake.direction = directions.RIGHT;
  snakes.push(snake);
  snake.setHead(Math.floor(WIDTH / 2) - 2, Math.floor(HEIGHT / 2) - 1);
  if (player2) {
    snake = new Snake(2);
    snake.direction = directions.LEFT;
    snakes.push(snake);
    snake.setHead(Math.floor(WIDTH / 2) + 2, Math.floor(HEIGHT / 2) + 1);
  }
  for (var i = 0; i < snakes.length; i++) {
    snakes[i].step(true);
    snakes[i].step(true);
    snakes[i].step(false);
  }
  addFood();
  addFood();
}
function resetGame ( ) { for ( var y = 0 ; y < HEIGHT ; y ++ ) { for ( var x = 0 ; x < WIDTH ; x ++ ) { clearCell ( getCell ( [ x , y ] ) ) ; } } snakes . length = 0 ; var snake = new Snake ( 1 ) ; snake . direction = directions . RIGHT ; snakes . push ( snake ) ; snake . setHead ( Math . floor ( WIDTH / 2 ) - 2 , Math . floor ( HEIGHT / 2 ) - 1 ) ; if ( player2 ) { snake = new Snake ( 2 ) ; snake . direction = directions . LEFT ; snakes . push ( snake ) ; snake . setHead ( Math . floor ( WIDTH / 2 ) + 2 , Math . floor ( HEIGHT / 2 ) + 1 ) ; } for ( var i = 0 ; i < snakes . length ; i ++ ) { snakes [ i ] . step ( true ) ; snakes [ i ] . step ( true ) ; snakes [ i ] . step ( false ) ; } addFood ( ) ; addFood ( ) ; }
Clear any existing data, and configure a new game.
Clear any existing data and configure a new game .
// Start snake with a length of three (one head, plus two steps), // Start with two foods on the board.