Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0ffaa4d08e | |||
| f24ab96870 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -30,3 +30,4 @@ glow.apk
|
||||
compose-scripts.md
|
||||
uploads
|
||||
|
||||
package-lock.json
|
||||
@ -5,7 +5,7 @@ A snake implementation with vanilla JavaScript
|
||||
[PLAY!](http://zzznake.surge.sh/)
|
||||
|
||||
Todo
|
||||
* [ ] Add restart logic
|
||||
* [x] Add restart logic
|
||||
* [ ] Make it functional
|
||||
* [ ] Use canvas instead of div's
|
||||
* [ ] Add animations
|
||||
|
||||
@ -1,6 +0,0 @@
|
||||
<html>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/src/index.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
1068
package-lock.json
generated
1068
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -9,10 +9,11 @@
|
||||
"lodash": "^4.17.4"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "vite",
|
||||
"build": "vite build --outDir build"
|
||||
"start": "neutrino start --use neutrino-preset-web",
|
||||
"build": "neutrino build --use neutrino-preset-web"
|
||||
},
|
||||
"devDependencies": {
|
||||
"vite": "^7.1.7"
|
||||
"neutrino": "^6.1.5",
|
||||
"neutrino-preset-web": "^6.1.5"
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
export default {
|
||||
bgColor: "grey",
|
||||
unit: 20,
|
||||
dimensions: {
|
||||
width: 30,
|
||||
|
||||
@ -9,7 +9,7 @@ import {
|
||||
import keys from "./utils/keys";
|
||||
import { S, N, A, K, E } from "./utils/letters";
|
||||
|
||||
const { dimensions, unit, snake, food, bgColor } = config;
|
||||
const { dimensions, unit, snake, food } = config;
|
||||
|
||||
let GAME_STARTED = false;
|
||||
let GAME_RUNNING;
|
||||
@ -40,7 +40,7 @@ for (let i = 0; i < dimensions.height; i++) {
|
||||
width: `${unit}px`,
|
||||
height: `${unit}px`,
|
||||
display: "inline-block",
|
||||
background: bgColor,
|
||||
background: "#000",
|
||||
},
|
||||
"board"
|
||||
);
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
*/
|
||||
|
||||
export const createDivElement = (name, styles, target) => {
|
||||
window[name] = document.createElement('div');
|
||||
window[name] = document.createElement("div");
|
||||
window[name].id = name;
|
||||
|
||||
Object.assign(window[name].style, styles);
|
||||
@ -29,14 +29,19 @@ export const setDivColor = (color, x, y) => {
|
||||
|
||||
export const setDivsColor = (divs, color) => {
|
||||
divs.forEach(({ x, y }) => {
|
||||
((document.getElementById(`${x}.${y}`) || {}).style || {}).background = color;
|
||||
((document.getElementById(`${x}.${y}`) || {}).style || {}).background =
|
||||
color;
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Draw charchter
|
||||
*/
|
||||
* Draw charchter
|
||||
*/
|
||||
|
||||
export const drawLetter = (char) => {
|
||||
setDivColor('#333', char.toString().split('.')[0], char.toString().split('.')[1]);
|
||||
};
|
||||
setDivColor(
|
||||
"#333",
|
||||
char.toString().split(".")[0],
|
||||
char.toString().split(".")[1]
|
||||
);
|
||||
};
|
||||
|
||||
@ -8,4 +8,4 @@ export default {
|
||||
UP: 38,
|
||||
RIGHT: 39,
|
||||
DOWN: 40,
|
||||
}
|
||||
};
|
||||
|
||||
@ -3,7 +3,18 @@
|
||||
*/
|
||||
|
||||
export const S = [2.2, 2.3, 2.4, 2.5, 3.2, 4.3, 5.4, 6.5, 7.5, 7.4, 7.3, 7.2];
|
||||
export const N = [2.7, 3.7, 4.7, 5.7, 6.7, 7.7, 3.8, 4.9, 5.9, 6.10, 6.11, 7.11, 6.11, 5.11, 4.11, 3.11, 2.11];
|
||||
export const A = [2.13, 3.13, 4.13, 5.13, 6.13, 7.13, 2.14, 2.15, 2.16, 2.17, 3.17, 4.17, 5.17, 6.17, 7.17, 5.16, 5.15, 5.14];
|
||||
export const K = [2.19, 3.19, 4.19, 4.20, 5.19, 5.20, 6.19, 7.19, 6.21, 7.22, 3.21, 2.22];
|
||||
export const E = [2.24, 3.24, 4.24, 5.24, 6.24, 7.24, 2.25, 2.26, 2.27, 2.28, 7.25, 7.26, 7.27, 7.28, 4.25];
|
||||
export const N = [
|
||||
2.7, 3.7, 4.7, 5.7, 6.7, 7.7, 3.8, 4.9, 5.9, 6.1, 6.11, 7.11, 6.11, 5.11,
|
||||
4.11, 3.11, 2.11,
|
||||
];
|
||||
export const A = [
|
||||
2.13, 3.13, 4.13, 5.13, 6.13, 7.13, 2.14, 2.15, 2.16, 2.17, 3.17, 4.17, 5.17,
|
||||
6.17, 7.17, 5.16, 5.15, 5.14,
|
||||
];
|
||||
export const K = [
|
||||
2.19, 3.19, 4.19, 4.2, 5.19, 5.2, 6.19, 7.19, 6.21, 7.22, 3.21, 2.22,
|
||||
];
|
||||
export const E = [
|
||||
2.24, 3.24, 4.24, 5.24, 6.24, 7.24, 2.25, 2.26, 2.27, 2.28, 7.25, 7.26, 7.27,
|
||||
7.28, 4.25,
|
||||
];
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user