function keydown(e) {
  if (e.repeat || !isRunning) {
    return;
  }
  switch (e.key) {
    case 'ArrowLeft':
      snakes[0].pushDirection(directions.LEFT);
      break;
    case 'ArrowRight':
      snakes[0].pushDirection(directions.RIGHT);
      break;
    case 'ArrowUp':
      snakes[0].pushDirection(directions.UP);
      break;
    case 'ArrowDown':
      snakes[0].pushDirection(directions.DOWN);
      break;
    case 'a':
    case 'A':
      if (player2) {
        snakes[1].pushDirection(directions.LEFT);
      }
      break;
    case 'd': // Qwerty
    case 'D':
    case 'e': // Dvorak
    case 'E':
      if (player2) {
        snakes[1].pushDirection(directions.RIGHT);
      }
      break;
    case 'w': // Qwerty
    case 'W':
    case ',': // Dvorak
    case '<':
      if (player2) {
        snakes[1].pushDirection(directions.UP);
      }
      break;
    case 's': // Qwerty
    case 'S':
    case 'o': // Dvorak
    case 'O':
      if (player2) {
        snakes[1].pushDirection(directions.DOWN);
      }
      break;
    default:
      return;
  }
  e.preventDefault();
}
// Player is changing directions using the keyboard.
Player is changing directions using the keyboard.
Player is changing directions using the keyboard .
function keydown(e) {
  if (e.repeat || !isRunning) {
    return;
  }
  switch (e.key) {
    case 'ArrowLeft':
      snakes[0].pushDirection(directions.LEFT);
      break;
    case 'ArrowRight':
      snakes[0].pushDirection(directions.RIGHT);
      break;
    case 'ArrowUp':
      snakes[0].pushDirection(directions.UP);
      break;
    case 'ArrowDown':
      snakes[0].pushDirection(directions.DOWN);
      break;
    case 'a':
    case 'A':
      if (player2) {
        snakes[1].pushDirection(directions.LEFT);
      }
      break;
    case 'd': 
    case 'D':
    case 'e': 
    case 'E':
      if (player2) {
        snakes[1].pushDirection(directions.RIGHT);
      }
      break;
    case 'w': 
    case 'W':
    case ',': 
    case '<':
      if (player2) {
        snakes[1].pushDirection(directions.UP);
      }
      break;
    case 's': 
    case 'S':
    case 'o': 
    case 'O':
      if (player2) {
        snakes[1].pushDirection(directions.DOWN);
      }
      break;
    default:
      return;
  }
  e.preventDefault();
}
function keydown ( e ) { if ( e . repeat || ! isRunning ) { return ; } switch ( e . key ) { case 'ArrowLeft' : snakes [ 0 ] . pushDirection ( directions . LEFT ) ; break ; case 'ArrowRight' : snakes [ 0 ] . pushDirection ( directions . RIGHT ) ; break ; case 'ArrowUp' : snakes [ 0 ] . pushDirection ( directions . UP ) ; break ; case 'ArrowDown' : snakes [ 0 ] . pushDirection ( directions . DOWN ) ; break ; case 'a' : case 'A' : if ( player2 ) { snakes [ 1 ] . pushDirection ( directions . LEFT ) ; } break ; case 'd' : case 'D' : case 'e' : case 'E' : if ( player2 ) { snakes [ 1 ] . pushDirection ( directions . RIGHT ) ; } break ; case 'w' : case 'W' : case ',' : case '<' : if ( player2 ) { snakes [ 1 ] . pushDirection ( directions . UP ) ; } break ; case 's' : case 'S' : case 'o' : case 'O' : if ( player2 ) { snakes [ 1 ] . pushDirection ( directions . DOWN ) ; } break ; default : return ; } e . preventDefault ( ) ; }
Player is changing directions using the keyboard.
Player is changing directions using the keyboard .
// Qwerty // Dvorak // Qwerty // Dvorak // Qwerty // Dvorak