diff --git a/src/index.html b/src/index.html index 03dc6b10..e8f8d4e7 100755 --- a/src/index.html +++ b/src/index.html @@ -26,6 +26,20 @@ z-index: 10000; padding: 5px; } + .speed-btn { + cursor: pointer; + border: 1px solid #ccc; + background-color: #f0f0f0; + border-radius: 3px; + } + .speed-btn:hover { + background-color: #e0e0e0; + } + .speed-btn-active { + background-color: #4CAF50; + color: white; + border-color: #4CAF50; + } diff --git a/src/js/snake.js b/src/js/snake.js index 6232e8d9..09b5cc77 100644 --- a/src/js/snake.js +++ b/src/js/snake.js @@ -29,7 +29,7 @@ const MOVE_RIGHT = 1; const MIN_SNAKE_SPEED = 25; const RUSH_INCR = 5; -const DEFAULT_SNAKE_SPEED = 80; +const DEFAULT_SNAKE_SPEED = 300; const BOARD_NOT_READY = 0; const BOARD_READY = 1; @@ -146,7 +146,7 @@ SNAKE.Snake = const me = this; const playingBoard = config.playingBoard; - const growthIncr = 5; + const growthIncr = 1; const columnShift = [0, 1, 0, -1]; const rowShift = [-1, 0, 1, 0]; let prevNode; @@ -381,6 +381,20 @@ SNAKE.Snake = newHead.col = oldHead.col + columnShift[lastMove]; newHead.row = oldHead.row + rowShift[lastMove]; + const maxRow = grid.length - 1; + const maxCol = grid[0].length - 1; + + if (newHead.col <= 0) { + newHead.col = maxCol - 1; + } else if (newHead.col >= maxCol) { + newHead.col = 1; + } + if (newHead.row <= 0) { + newHead.row = maxRow - 1; + } else if (newHead.row >= maxRow) { + newHead.row = 1; + } + if (!newHead.elmStyle) { newHead.elmStyle = newHead.elm.style; }