Compare commits

...

9 Commits
test ... main

Author SHA1 Message Date
e059ff91eb add lock 2026-02-01 23:12:02 +01:00
87e42d87a5 change color 2025-10-30 19:57:06 +01:00
c494780fad update color 2025-10-29 19:45:26 +01:00
d4610bf5e8 change color 2025-10-29 02:04:13 +01:00
6c8897746c update color 2025-10-29 01:36:35 +01:00
afe39c77c4 update color 2025-10-29 01:33:40 +01:00
0ad707476d change color 2025-10-29 01:06:51 +01:00
bf7a37e66c fix deps 2025-10-27 18:56:03 +01:00
c64d89b5db move to vite 2025-09-30 20:04:22 +02:00
7 changed files with 1127 additions and 5195 deletions

1
.gitignore vendored
View File

@ -30,4 +30,3 @@ glow.apk
compose-scripts.md compose-scripts.md
uploads uploads
package-lock.json

6
index.html Normal file
View File

@ -0,0 +1,6 @@
<html>
<body>
<div id="app"></div>
<script type="module" src="/src/index.js"></script>
</body>
</html>

1068
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -9,11 +9,10 @@
"lodash": "^4.17.4" "lodash": "^4.17.4"
}, },
"scripts": { "scripts": {
"start": "neutrino start --use neutrino-preset-web", "start": "vite",
"build": "neutrino build --use neutrino-preset-web" "build": "vite build --outDir build"
}, },
"devDependencies": { "devDependencies": {
"neutrino": "^6.1.5", "vite": "^7.1.7"
"neutrino-preset-web": "^6.1.5"
} }
} }

View File

@ -1,5 +1,5 @@
export default { export default {
bgColor: "grey",
unit: 20, unit: 20,
dimensions: { dimensions: {
width: 30, width: 30,
@ -14,5 +14,5 @@ export default {
food: { food: {
x: null, x: null,
y: null, y: null,
} },
}; };

View File

@ -1,15 +1,15 @@
import { random, find, takeRight } from 'lodash'; import { random, find, takeRight } from "lodash";
import config from './config'; import config from "./config";
import { createDivElement, setDivColor, setDivsColor, drawLetter } from './utils/div'; import {
import keys from './utils/keys'; createDivElement,
import { S, N, A, K, E } from './utils/letters'; setDivColor,
setDivsColor,
drawLetter,
} from "./utils/div";
import keys from "./utils/keys";
import { S, N, A, K, E } from "./utils/letters";
const { const { dimensions, unit, snake, food, bgColor } = config;
dimensions,
unit,
snake,
food,
} = config;
let GAME_STARTED = false; let GAME_STARTED = false;
let GAME_RUNNING; let GAME_RUNNING;
@ -21,11 +21,11 @@ let SNAKE_SPEED = 100;
* Draw the board * Draw the board
*/ */
createDivElement('board', { createDivElement("board", {
height: `${unit * dimensions.height}px`, height: `${unit * dimensions.height}px`,
width: `${unit * dimensions.width}px`, width: `${unit * dimensions.width}px`,
position: 'relative', position: "relative",
fontSize: '0', fontSize: "0",
}); });
/** /**
@ -34,12 +34,16 @@ createDivElement('board', {
for (let i = 0; i < dimensions.height; i++) { for (let i = 0; i < dimensions.height; i++) {
for (let j = 0; j < dimensions.width; j++) { for (let j = 0; j < dimensions.width; j++) {
createDivElement(`${i + 1}.${j + 1}`, { createDivElement(
`${i + 1}.${j + 1}`,
{
width: `${unit}px`, width: `${unit}px`,
height: `${unit}px`, height: `${unit}px`,
display: 'inline-block', display: "inline-block",
background: '#000', background: bgColor,
}, 'board'); },
"board"
);
} }
} }
@ -47,9 +51,10 @@ for (let i = 0; i < dimensions.height; i++) {
* Draw the snake * Draw the snake
*/ */
const showSnake = () => setDivsColor(takeRight(SNAKE_LOG, snake.body), 'yellow'); const showSnake = () =>
setDivsColor(takeRight(SNAKE_LOG, snake.body), "yellow");
const hideSnake = () => setDivsColor(takeRight(SNAKE_LOG, snake.body), 'black'); const hideSnake = () => setDivsColor(takeRight(SNAKE_LOG, snake.body), "black");
/** /**
* Move the snake * Move the snake
@ -62,19 +67,19 @@ const pushToSnakeLog = (cords) => {
const moveSnake = (direction) => { const moveSnake = (direction) => {
hideSnake(); hideSnake();
if (direction === 'left') { if (direction === "left") {
snake.y--; snake.y--;
} }
if (direction === 'up') { if (direction === "up") {
snake.x--; snake.x--;
} }
if (direction === 'right') { if (direction === "right") {
snake.y++; snake.y++;
} }
if (direction === 'down') { if (direction === "down") {
snake.x++; snake.x++;
} }
@ -103,29 +108,29 @@ const moveSnake = (direction) => {
* Set key events * Set key events
*/ */
const setSnakeDirection = direction => SNAKE_DIRECTION = direction; const setSnakeDirection = (direction) => (SNAKE_DIRECTION = direction);
const keyFunctions = ({ keyCode }) => { const keyFunctions = ({ keyCode }) => {
switch (keyCode) { switch (keyCode) {
case keys.ENTER: case keys.ENTER:
if (GAME_STARTED) return; if (GAME_STARTED) return;
startGame(); startGame();
case keys.LEFT: case keys.LEFT:
setSnakeDirection('left'); setSnakeDirection("left");
break; break;
case keys.UP: case keys.UP:
setSnakeDirection('up'); setSnakeDirection("up");
break; break;
case keys.RIGHT: case keys.RIGHT:
setSnakeDirection('right'); setSnakeDirection("right");
break; break;
case keys.DOWN: case keys.DOWN:
setSnakeDirection('down'); setSnakeDirection("down");
break; break;
} }
}; };
document.addEventListener('keydown', keyFunctions); document.addEventListener("keydown", keyFunctions);
/** /**
* Make food * Make food
@ -136,24 +141,24 @@ const makeFood = () => {
const y = random(1, config.dimensions.height); const y = random(1, config.dimensions.height);
const snakeLength = SNAKE_LOG.length - 1; const snakeLength = SNAKE_LOG.length - 1;
const snakeBody = SNAKE_LOG.slice((snakeLength - snake.body), snakeLength); const snakeBody = SNAKE_LOG.slice(snakeLength - snake.body, snakeLength);
if (find(snakeBody, { x, y })) { if (find(snakeBody, { x, y })) {
console.log('food placed under the snake...'); console.log("food placed under the snake...");
return makeFood(); return makeFood();
} }
food.x = x; food.x = x;
food.y = y; food.y = y;
setDivColor('red', x, y); setDivColor("red", x, y);
}; };
/** /**
* Check if snake is eating * Check if snake is eating
*/ */
const checkIfSnakeIsEating = (snake, food) => { const checkIfSnakeIsEating = (snake, food) => {
if (snake.x === food.x && snake.y === food.y) { if (snake.x === food.x && snake.y === food.y) {
snake.body = snake.body + 1; snake.body = snake.body + 1;
SNAKE_SPEED = SNAKE_SPEED - 10; SNAKE_SPEED = SNAKE_SPEED - 10;
@ -165,16 +170,16 @@ const checkIfSnakeIsEating = (snake, food) => {
* Check collision * Check collision
*/ */
const checkCollision = ({ x, y }) => { const checkCollision = ({ x, y }) => {
const snakeLength = SNAKE_LOG.length - 2; const snakeLength = SNAKE_LOG.length - 2;
const snakeBody = SNAKE_LOG.slice((snakeLength - snake.body), snakeLength); const snakeBody = SNAKE_LOG.slice(snakeLength - snake.body, snakeLength);
if (find(snakeBody, { x, y })) { if (find(snakeBody, { x, y })) {
GAME_STARTED = false; GAME_STARTED = false;
clearInterval(GAME_RUNNING); clearInterval(GAME_RUNNING);
startScreen(); startScreen();
} }
} };
/** /**
* Start screen * Start screen
@ -186,13 +191,12 @@ const startScreen = () => {
A.forEach(drawLetter); A.forEach(drawLetter);
K.forEach(drawLetter); K.forEach(drawLetter);
E.forEach(drawLetter); E.forEach(drawLetter);
} };
/** /**
* Run game * Run game
*/ */
const startGame = () => { const startGame = () => {
const runGame = () => { const runGame = () => {
moveSnake(SNAKE_DIRECTION); moveSnake(SNAKE_DIRECTION);
@ -207,4 +211,3 @@ const startGame = () => {
}; };
startScreen(); startScreen();

5143
yarn.lock

File diff suppressed because it is too large Load Diff