3 Commits

Author SHA1 Message Date
Trianta f1346a628c core: make entire card same border radius 2024-11-25 15:34:53 -06:00
Trianta 343af77bd1 snake: make game resizable by user 2024-11-25 15:20:56 -06:00
Trianta 47fd5c7458 core: rearrange navigation and put main projects in a single row 2024-11-25 14:37:17 -06:00
3 changed files with 48 additions and 14 deletions
+12 -3
View File
@@ -22,6 +22,7 @@ body {
padding: 8px; padding: 8px;
line-height: 21px; line-height: 21px;
display: inline-block; display: inline-block;
text-align: right;
} }
#top { #top {
@@ -34,9 +35,19 @@ body {
} }
#main { #main {
margin: 0px 120px;
display: flex;
/*background: #1e2030;*/ /*background: #1e2030;*/
} }
.canvas {
width: 780px;
height: 600px;
align-items: center;
justify-content: center;
display: flex;
}
.cardStats { .cardStats {
font-size: 18px; font-size: 18px;
} }
@@ -121,9 +132,7 @@ a.button {
.card { .card {
background: #363a4f; background: #363a4f;
text-align: center; text-align: center;
border-radius: 6px; border-radius: 18px;
border-top-left-radius: 18px;
border-top-right-radius: 18px;
animation: card 3s linear infinite; animation: card 3s linear infinite;
width: 800px; width: 800px;
height: 800px; height: 800px;
+20 -10
View File
@@ -7,20 +7,22 @@
</head> </head>
<body> <body>
<div id="navigation"> <div id="navigation">
<p class="navItem" style="text-align: left; flex-grow: 1;">Trianta</p>
<a class="navItem" href="https://www.github.com/trimutex">GitHub</a> <a class="navItem" href="https://www.github.com/trimutex">GitHub</a>
<a class="navItem" href="https://lab.trianta.dev/Trianta">Projects</a> <a class="navItem" href="https://lab.trianta.dev/Trianta">Projects</a>
<p class="navItem" style="text-align: right; flex-grow: 1;">Trianta</p>
</div> </div>
<div id="main"> <div id="main">
<div class="card"> <div class="card">
<h2 class="cardTop">Pong</h2> <h2 class="cardTop">Pong</h2>
<canvas width="750" height="585" id="pong"></canvas> <div class="canvas">
<script src="public/pong.js"></script> <canvas width="750" height="585" id="pong"></canvas>
<div id="gameover" hidden="true"> <script src="public/pong.js"></script>
<h1>Game Over</h1> <div id="gameover" hidden="true">
</div> <h1>Game Over</h1>
<div id="restart" hidden="true"> </div>
<button class="button" type="button" onclick = "restartGame()">Restart Game</a> <div id="restart" hidden="true">
<button class="button" type="button" onclick = "restartGame()">Restart Game</a>
</div>
</div> </div>
<p class="cardStats">Left Paddle Height: <span id="leftPaddle"></span></p> <p class="cardStats">Left Paddle Height: <span id="leftPaddle"></span></p>
<p class="cardStats">Right Paddle Height: <span id="rightPaddle"></span></p> <p class="cardStats">Right Paddle Height: <span id="rightPaddle"></span></p>
@@ -28,8 +30,16 @@
</div> </div>
<div class="card"> <div class="card">
<h2 class="cardTop">Snake</h2> <h2 class="cardTop">Snake</h2>
<canvas width="625" height="375" id="snake"></canvas> <div class="canvas">
<script src="public/snake.js"></script> <canvas width="625" height="375" id="snake"></canvas>
<script src="public/snake.js"></script>
</div>
<p class="cardStats">
Adjust game size -- Width:
<input class="cardStats" id="snakeWidth" type="number" min="2" max="31" value="25">
Height:
<input class="cardStats" id="snakeHeight" type="number" min="2" max="24" value="15">
</p>
<p class="cardStats">Snake Head Location: <span id="snakeHead"></span></p> <p class="cardStats">Snake Head Location: <span id="snakeHead"></span></p>
<p class="cardStats">Food Location: <span id="snakeFood"></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>
+16 -1
View File
@@ -169,6 +169,21 @@ class SnakeCore {
document.getElementById("snakeHead").innerHTML = "x: " + this.body[this.body.length - 1].x + " y: " + this.body[this.body.length - 1].y; 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 ; document.getElementById("snakeFood").innerHTML = "x: " + this.food.x + " y: " + this.food.y ;
} }
// Update width and height from page to match game
getPageNumbers() {
let specifiedWidth = parseInt((document.getElementById("snakeWidth") as HTMLInputElement).value);
let specifiedHeight = parseInt((document.getElementById("snakeHeight") as HTMLInputElement).value);
if (this.width == specifiedWidth && this.height == specifiedHeight)
return false;
this.width = specifiedWidth;
this.height = specifiedHeight;
while (this.height > this.board.length)
this.board.push(new Array(this.width));
this.canvas.setAttribute("width", String(specifiedWidth * this.grid));
this.canvas.setAttribute("height", String(specifiedHeight * this.grid));
return true;
}
} }
class Bot { class Bot {
@@ -270,7 +285,7 @@ const g_snakebot: Bot = new Bot();
// game loop // game loop
function snakeloop() { function snakeloop() {
// Reset of needed // Reset of needed
if (g_snake.gameover) if (g_snake.gameover || g_snake.getPageNumbers())
g_snake.reset(); g_snake.reset();
// Simulate movement of snake // Simulate movement of snake