Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a754319374 | |||
|
|
4aeed537d7 | ||
|
|
f725b4e922 | ||
|
|
8252f38bb7 | ||
|
|
e4d9afdd68 | ||
|
|
90c868d9e9 | ||
|
|
452c35c1b0 | ||
|
|
9dea6014fe | ||
|
|
e37d737d3a | ||
|
|
65c7b930e3 | ||
|
|
082176d75e | ||
|
|
18673c95c4 | ||
|
|
cb52bd1561 | ||
| 0c196e690f | |||
|
|
532d8a480c | ||
|
|
92cfd954c1 |
+4
-2
@@ -1,6 +1,6 @@
|
|||||||
FROM nginx:latest
|
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
|
WORKDIR /app
|
||||||
|
|
||||||
@@ -14,10 +14,12 @@ RUN npm run build
|
|||||||
|
|
||||||
WORKDIR /usr/share/nginx/html
|
WORKDIR /usr/share/nginx/html
|
||||||
COPY index.html .
|
COPY index.html .
|
||||||
|
COPY default.css .
|
||||||
|
|
||||||
RUN mkdir -p /usr/share/nginx/html/public
|
RUN mkdir -p /usr/share/nginx/html/public
|
||||||
COPY src/*.css ./public
|
|
||||||
|
|
||||||
RUN cp /app/build/* ./public
|
RUN cp /app/build/* ./public
|
||||||
|
|
||||||
|
HEALTHCHECK CMD nc -z 127.0.0.1 80
|
||||||
|
|
||||||
EXPOSE 80
|
EXPOSE 80
|
||||||
|
|||||||
+3
-2
@@ -3,7 +3,7 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8"/>
|
<meta charset="utf-8"/>
|
||||||
<title>Trianta</title>
|
<title>Trianta</title>
|
||||||
<link rel="stylesheet" href="public/home.css" />
|
<link rel="stylesheet" href="default.css" />
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="navigation">
|
<div id="navigation">
|
||||||
@@ -30,7 +30,8 @@
|
|||||||
<h2 class="cardTop">Snake</h2>
|
<h2 class="cardTop">Snake</h2>
|
||||||
<canvas width="625" height="375" id="snake"></canvas>
|
<canvas width="625" height="375" id="snake"></canvas>
|
||||||
<script src="public/snake.js"></script>
|
<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>
|
<a class="navItem" href="https://lab.trianta.dev/Trianta/trianta.dev/src/branch/main/src/snake.ts">View Code</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Generated
+5
-5
@@ -1,21 +1,21 @@
|
|||||||
{
|
{
|
||||||
"name": "trianta.dev",
|
"name": "trianta.dev",
|
||||||
"version": "0.1.0",
|
"version": "0.2.2",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "trianta.dev",
|
"name": "trianta.dev",
|
||||||
"version": "0.1.0",
|
"version": "0.2.2",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"typescript": "^5.5.4"
|
"typescript": "^5.5.4"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/typescript": {
|
"node_modules/typescript": {
|
||||||
"version": "5.5.4",
|
"version": "5.6.3",
|
||||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.4.tgz",
|
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.6.3.tgz",
|
||||||
"integrity": "sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q==",
|
"integrity": "sha512-hjcS1mhfuyi4WW8IWtjP7brDrG2cuDZukyrYrSauoXGNgx0S7zceP07adYkJycEr56BOUTNPzbInooiN3fn1qw==",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"bin": {
|
"bin": {
|
||||||
"tsc": "bin/tsc",
|
"tsc": "bin/tsc",
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "trianta.dev",
|
"name": "trianta.dev",
|
||||||
"version": "0.1.0",
|
"version": "0.2.2",
|
||||||
"description": "My personal website",
|
"description": "My personal website",
|
||||||
"main": "index.html",
|
"main": "index.html",
|
||||||
"scripts": {
|
"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;
|
height: number;
|
||||||
board: number[][];
|
board: number[][];
|
||||||
body: Point[];
|
body: Point[];
|
||||||
|
food: Point;
|
||||||
gameover: boolean;
|
gameover: boolean;
|
||||||
foodAte: boolean;
|
foodAte: boolean;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
// TODO: Add CSS stuff for page
|
|
||||||
this.canvas = document.getElementById('snake') as HTMLCanvasElement;
|
this.canvas = document.getElementById('snake') as HTMLCanvasElement;
|
||||||
this.context = this.canvas.getContext('2d') as CanvasRenderingContext2D;
|
this.context = this.canvas.getContext('2d') as CanvasRenderingContext2D;
|
||||||
this.grid = 25; // size of grid squares
|
this.grid = 25; // size of grid squares
|
||||||
this.timeout = 100; // speed in ms
|
this.timeout = 32; // speed in ms
|
||||||
this.width = 25;
|
this.width = 25;
|
||||||
this.height = 15;
|
this.height = 15;
|
||||||
this.board = [];
|
this.board = [];
|
||||||
for (let i = 0; i < this.height; i++)
|
for (let i = 0; i < this.height; i++)
|
||||||
this.board.push(new Array(this.width));
|
this.board.push(new Array(this.width));
|
||||||
this.body = [];
|
this.body = [];
|
||||||
|
this.food = new Point();
|
||||||
this.gameover = false;
|
this.gameover = false;
|
||||||
this.foodAte = true;
|
this.foodAte = true;
|
||||||
this.body.push(new Point(12, 8));
|
this.body.push(new Point(12, 8));
|
||||||
@@ -112,6 +113,7 @@ class SnakeCore {
|
|||||||
if (isBitSet(this.board[tmp.y][tmp.x], BoardState.SNAKE))
|
if (isBitSet(this.board[tmp.y][tmp.x], BoardState.SNAKE))
|
||||||
continue;
|
continue;
|
||||||
this.board[tmp.y][tmp.x] = bitSet(this.board[tmp.y][tmp.x], BoardState.FOOD);
|
this.board[tmp.y][tmp.x] = bitSet(this.board[tmp.y][tmp.x], BoardState.FOOD);
|
||||||
|
this.food.copy(tmp);
|
||||||
return;
|
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 {
|
class Bot {
|
||||||
@@ -204,7 +212,6 @@ class Bot {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Fix trim function
|
|
||||||
trim() {
|
trim() {
|
||||||
let reachedSnake = false;
|
let reachedSnake = false;
|
||||||
this.path.push(this.pathUntrimmed.pop() as Point); // Push food location
|
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() {
|
nextMove() {
|
||||||
// Get new path to food
|
// Get new path to food
|
||||||
if (this.path.length === 0)
|
if (this.path.length === 0)
|
||||||
@@ -280,6 +280,7 @@ function snakeloop() {
|
|||||||
g_snake.foodRegen();
|
g_snake.foodRegen();
|
||||||
|
|
||||||
g_snake.draw();
|
g_snake.draw();
|
||||||
|
g_snake.updatePageText();
|
||||||
}
|
}
|
||||||
|
|
||||||
// start the game
|
// start the game
|
||||||
|
|||||||
Reference in New Issue
Block a user