Compare commits
15 Commits
v0.2.0
...
reorganize
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4aeed537d7 | ||
|
|
f725b4e922 | ||
|
|
8252f38bb7 | ||
|
|
e4d9afdd68 | ||
|
|
90c868d9e9 | ||
|
|
452c35c1b0 | ||
|
|
9dea6014fe | ||
|
|
e37d737d3a | ||
|
|
65c7b930e3 | ||
|
|
082176d75e | ||
|
|
18673c95c4 | ||
|
|
cb52bd1561 | ||
| 0c196e690f | |||
|
|
532d8a480c | ||
|
|
92cfd954c1 |
+4
-2
@@ -1,6 +1,6 @@
|
||||
FROM nginx:latest
|
||||
|
||||
RUN apt-get update && apt-get install -y nodejs npm
|
||||
RUN apt-get update && apt-get install -y nodejs npm netcat-openbsd
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
@@ -14,10 +14,12 @@ RUN npm run build
|
||||
|
||||
WORKDIR /usr/share/nginx/html
|
||||
COPY index.html .
|
||||
COPY default.css .
|
||||
|
||||
RUN mkdir -p /usr/share/nginx/html/public
|
||||
COPY src/*.css ./public
|
||||
|
||||
RUN cp /app/build/* ./public
|
||||
|
||||
HEALTHCHECK CMD nc -z 127.0.0.1 80
|
||||
|
||||
EXPOSE 80
|
||||
|
||||
+3
-2
@@ -3,7 +3,7 @@
|
||||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
<title>Trianta</title>
|
||||
<link rel="stylesheet" href="public/home.css" />
|
||||
<link rel="stylesheet" href="default.css" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="navigation">
|
||||
@@ -30,7 +30,8 @@
|
||||
<h2 class="cardTop">Snake</h2>
|
||||
<canvas width="625" height="375" id="snake"></canvas>
|
||||
<script src="public/snake.js"></script>
|
||||
<p class="cardStats">Bottom Text<span></span></p>
|
||||
<p class="cardStats">Snake Head Location: <span id="snakeHead"></span></p>
|
||||
<p class="cardStats">Food Location: <span id="snakeFood"></span></p>
|
||||
<a class="navItem" href="https://lab.trianta.dev/Trianta/trianta.dev/src/branch/main/src/snake.ts">View Code</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Generated
+5
-5
@@ -1,21 +1,21 @@
|
||||
{
|
||||
"name": "trianta.dev",
|
||||
"version": "0.1.0",
|
||||
"version": "0.2.2",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "trianta.dev",
|
||||
"version": "0.1.0",
|
||||
"version": "0.2.2",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"typescript": "^5.5.4"
|
||||
}
|
||||
},
|
||||
"node_modules/typescript": {
|
||||
"version": "5.5.4",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.4.tgz",
|
||||
"integrity": "sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q==",
|
||||
"version": "5.6.3",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.6.3.tgz",
|
||||
"integrity": "sha512-hjcS1mhfuyi4WW8IWtjP7brDrG2cuDZukyrYrSauoXGNgx0S7zceP07adYkJycEr56BOUTNPzbInooiN3fn1qw==",
|
||||
"license": "Apache-2.0",
|
||||
"bin": {
|
||||
"tsc": "bin/tsc",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "trianta.dev",
|
||||
"version": "0.1.0",
|
||||
"version": "0.2.2",
|
||||
"description": "My personal website",
|
||||
"main": "index.html",
|
||||
"scripts": {
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
html, body {
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
body {
|
||||
background: black;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.button {
|
||||
background: blue;
|
||||
color: white;
|
||||
padding: 15px 20px;
|
||||
font-size: 32px;
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
text-transform: uppercase;
|
||||
cursor: pointer;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
+11
-10
@@ -55,21 +55,22 @@ class SnakeCore {
|
||||
height: number;
|
||||
board: number[][];
|
||||
body: Point[];
|
||||
food: Point;
|
||||
gameover: boolean;
|
||||
foodAte: boolean;
|
||||
|
||||
constructor() {
|
||||
// TODO: Add CSS stuff for page
|
||||
this.canvas = document.getElementById('snake') as HTMLCanvasElement;
|
||||
this.context = this.canvas.getContext('2d') as CanvasRenderingContext2D;
|
||||
this.grid = 25; // size of grid squares
|
||||
this.timeout = 100; // speed in ms
|
||||
this.timeout = 32; // speed in ms
|
||||
this.width = 25;
|
||||
this.height = 15;
|
||||
this.board = [];
|
||||
for (let i = 0; i < this.height; i++)
|
||||
this.board.push(new Array(this.width));
|
||||
this.body = [];
|
||||
this.food = new Point();
|
||||
this.gameover = false;
|
||||
this.foodAte = true;
|
||||
this.body.push(new Point(12, 8));
|
||||
@@ -112,6 +113,7 @@ class SnakeCore {
|
||||
if (isBitSet(this.board[tmp.y][tmp.x], BoardState.SNAKE))
|
||||
continue;
|
||||
this.board[tmp.y][tmp.x] = bitSet(this.board[tmp.y][tmp.x], BoardState.FOOD);
|
||||
this.food.copy(tmp);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -161,6 +163,12 @@ class SnakeCore {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update text on page to match game
|
||||
updatePageText() {
|
||||
document.getElementById("snakeHead").innerHTML = "x: " + this.body[this.body.length - 1].x + " y: " + this.body[this.body.length - 1].y;
|
||||
document.getElementById("snakeFood").innerHTML = "x: " + this.food.x + " y: " + this.food.y ;
|
||||
}
|
||||
}
|
||||
|
||||
class Bot {
|
||||
@@ -204,7 +212,6 @@ class Bot {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Fix trim function
|
||||
trim() {
|
||||
let reachedSnake = false;
|
||||
this.path.push(this.pathUntrimmed.pop() as Point); // Push food location
|
||||
@@ -231,13 +238,6 @@ class Bot {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
values:
|
||||
0 = left
|
||||
1 = up
|
||||
2 = right
|
||||
4 = down
|
||||
*/
|
||||
nextMove() {
|
||||
// Get new path to food
|
||||
if (this.path.length === 0)
|
||||
@@ -280,6 +280,7 @@ function snakeloop() {
|
||||
g_snake.foodRegen();
|
||||
|
||||
g_snake.draw();
|
||||
g_snake.updatePageText();
|
||||
}
|
||||
|
||||
// start the game
|
||||
|
||||
Reference in New Issue
Block a user