From 8d68bace23c5e128afb0732f4fc74287152c805e Mon Sep 17 00:00:00 2001 From: 4yman <170770027+4yman-0@users.noreply.github.com> Date: Wed, 13 Nov 2024 00:10:57 +0100 Subject: [PATCH] Update --- archive/foobar.ai/index.css | 19 +++------- archive/webgames/js/dom.js | 14 ++++++-- archive/webgames/snake/js/game.js | 32 ++++++++--------- archive/webgames/snake/js/gameDOM.js | 3 +- archive/webgames/snake/js/main.js | 2 +- archive/webgames/tic-tac-toe/js/ai.js | 38 ++++++++++---------- archive/webgames/tic-tac-toe/js/constants.js | 3 +- archive/webgames/tic-tac-toe/js/game.js | 6 ++-- archive/webgames/tic-tac-toe/js/main.js | 2 +- index.css | 1 - 10 files changed, 57 insertions(+), 63 deletions(-) diff --git a/archive/foobar.ai/index.css b/archive/foobar.ai/index.css index 4c831b0..aab7d5e 100644 --- a/archive/foobar.ai/index.css +++ b/archive/foobar.ai/index.css @@ -14,10 +14,6 @@ padding: 0; } -.header { - padding: 0 1.5rem; -} - .header__links { display: flex; gap: .8rem; @@ -32,7 +28,7 @@ .hero__container { display: inline-block; padding: 1rem; - background: rgba(0, 0, 10, .6); + background: #2C2C32; border-radius: 1rem; } @@ -47,11 +43,6 @@ .hero__btn { width: fit-content; margin-left: auto; - text-align: center; -} - -.why-foobar { - padding-top: 20vh; } .cards { @@ -84,7 +75,7 @@ } .solutions { - padding-top: 15vh; + padding: 3rem .4rem; } .solutions__title { @@ -151,17 +142,17 @@ } .integrations { - padding-top: 15vh; background: var(--bg-2); } .integrations__title { text-align: center; - margin-bottom: 10vh; + margin-bottom: 3rem; + font-size: 2rem; } .integrations__list { - margin-bottom: 8vh; + margin-bottom: 2rem; display: flex; justify-content: space-evenly; flex-wrap: wrap; diff --git a/archive/webgames/js/dom.js b/archive/webgames/js/dom.js index bb3989e..9995b6e 100644 --- a/archive/webgames/js/dom.js +++ b/archive/webgames/js/dom.js @@ -1,3 +1,11 @@ -const $ = (id) => document.getElementById(id); -const $q = (q) => document.querySelector(q); -const $qa = (qa) => document.querySelectorAll(qa); \ No newline at end of file +function $(id) { + return document.getElementById(id); +} + +function $q(q) { + return document.querySelector(q); +} + +function $qa(q) { + return document.getElementById(q); +} diff --git a/archive/webgames/snake/js/game.js b/archive/webgames/snake/js/game.js index 7ac6bf8..e4fd08c 100644 --- a/archive/webgames/snake/js/game.js +++ b/archive/webgames/snake/js/game.js @@ -9,17 +9,17 @@ let gameState = { score: 0, over: false, freezeTail: false, - - reset (){ - gameState.snake = [[1, 0], [0, 0]]; - gameState.inputBuffer = [""]; - gameState.dir = [0, 0]; - gameState.apple = [4, 4]; - gameState.score = 0; - gameState.over = false; - } }; +function resetGameState (){ + gameState.snake = [[1, 0], [0, 0]]; + gameState.inputBuffer = [""]; + gameState.dir = [0, 0]; + gameState.apple = [4, 4]; + gameState.score = 0; + gameState.over = false; +} + const game = { gridSize: 9, /** @@ -30,7 +30,7 @@ const game = { moved: false, startGame() { - gameState.reset(); + resetGameState(); game.updateScore(); DOM.hideModal(); game.gameLoop = setInterval(game.frame, 150); @@ -74,10 +74,8 @@ const game = { } }, frame (){ - if (gameState.inputBuffer[0] !== "") { + if (gameState.inputBuffer[0] !== "") game.changeDir(gameState.inputBuffer.shift()); - } - if (gameState.dir[0] != 0 || gameState.dir[1] != 0) { @@ -96,14 +94,14 @@ const game = { game.moved = false; - // Check snake body is out of wall or no + // Check snake body is out of wall or not if (gameState.snake[0][0] < 0 || gameState.snake[0][0] > game.gridSize || gameState.snake[0][1] < 0 || gameState.snake[0][1] > game.gridSize) { game.endGame(); } for (let i = 1; i < gameState.snake.length; i++) { - // Check snake head hit body or no + // Check snake head hit body or not if (i !== 0 && gameState.snake[0][1] === gameState.snake[i][1] && gameState.snake[0][0] === gameState.snake[i][0]) { game.endGame(); @@ -156,9 +154,9 @@ const game = { endGame() { clearInterval(game.gameLoop); gameState.over = true; - gameState.reset(); + resetGameState(); DOM.showModal(); } }; -export { game, gameState }; \ No newline at end of file +export { game, gameState }; diff --git a/archive/webgames/snake/js/gameDOM.js b/archive/webgames/snake/js/gameDOM.js index 36972d0..0452354 100644 --- a/archive/webgames/snake/js/gameDOM.js +++ b/archive/webgames/snake/js/gameDOM.js @@ -14,5 +14,4 @@ const DOM = { }, }; - -export default DOM; \ No newline at end of file +export default DOM; diff --git a/archive/webgames/snake/js/main.js b/archive/webgames/snake/js/main.js index 0bd1e9f..2f55e0b 100644 --- a/archive/webgames/snake/js/main.js +++ b/archive/webgames/snake/js/main.js @@ -24,4 +24,4 @@ DOM.mobileButtons[2].addEventListener("click", DOM.mobileButtons[3].addEventListener("click", () => gameState.inputBuffer.unshift("ArrowRight")); -game.startGame(); \ No newline at end of file +game.startGame(); diff --git a/archive/webgames/tic-tac-toe/js/ai.js b/archive/webgames/tic-tac-toe/js/ai.js index fe223aa..f51ce8a 100644 --- a/archive/webgames/tic-tac-toe/js/ai.js +++ b/archive/webgames/tic-tac-toe/js/ai.js @@ -1,25 +1,25 @@ import { Players } from "./constants.js"; import Game from './game.js'; -const AI = { - move() { - const availableMoves = []; +function AIMove() { + const availableMoves = []; - // Collect all available moves (empty cells) - for (let x = 0; x < 3; x++) { - for (let y = 0; y < 3; y++) { - if (Game.cells[x][y] === Players.EMPTY) { - availableMoves.push({ x, y }); - } - } - } + // Collect all available moves (empty cells) + Game.cells.forEach(col => { + col.forEach(cell => { + if (Game.cells[x][y] === Players.EMPTY) { + availableMoves.push({ x, y }); + } + }); + }); - // Pick a random move from available moves - const randomMove = availableMoves[Math.floor(Math.random() * availableMoves.length)]; - if (randomMove) { - Game.captureCell(randomMove.x, randomMove.y); - } - } -}; + if (availableMoves.length == 0) { + return; + } -export default AI; \ No newline at end of file + // Pick a random move from available moves + const randomMove = availableMoves[Math.floor(Math.random() * availableMoves.length)]; + Game.captureCell(randomMove.x, randomMove.y); +} + +export default AIMove; diff --git a/archive/webgames/tic-tac-toe/js/constants.js b/archive/webgames/tic-tac-toe/js/constants.js index d8474d5..699bb6e 100644 --- a/archive/webgames/tic-tac-toe/js/constants.js +++ b/archive/webgames/tic-tac-toe/js/constants.js @@ -10,7 +10,6 @@ const DOM = { board: $('game-board'), cells: $qa('.cell'), - swapModals() { DOM.modeModal.classList.toggle('hidden'); DOM.winModal.classList.toggle('hidden'); @@ -36,4 +35,4 @@ const GameModes = { TWO_PLAYERS: 1 }; -export { DOM, Players, GameModes }; \ No newline at end of file +export { DOM, Players, GameModes }; diff --git a/archive/webgames/tic-tac-toe/js/game.js b/archive/webgames/tic-tac-toe/js/game.js index 30ec0d0..0e7d589 100644 --- a/archive/webgames/tic-tac-toe/js/game.js +++ b/archive/webgames/tic-tac-toe/js/game.js @@ -1,5 +1,5 @@ import { DOM, Players, GameModes } from './constants.js'; -import AI from './ai.js'; +import AIMove from './ai.js'; const Game = { cells: [ @@ -31,7 +31,7 @@ const Game = { ]; Game.updateBoard(); if (Game.difficulty === GameModes.NORMAL && Game.turn === Players.O) { - AI.move(); + AIMove(); } }, @@ -133,4 +133,4 @@ const Game = { } }; -export default Game; \ No newline at end of file +export default Game; diff --git a/archive/webgames/tic-tac-toe/js/main.js b/archive/webgames/tic-tac-toe/js/main.js index ce4472a..030fe60 100644 --- a/archive/webgames/tic-tac-toe/js/main.js +++ b/archive/webgames/tic-tac-toe/js/main.js @@ -16,4 +16,4 @@ DOM.cells.forEach((cell, index) => { const y = index % 3; Game.captureCell(x, y); }); -}); \ No newline at end of file +}); diff --git a/index.css b/index.css index 0762619..10f6fe3 100644 --- a/index.css +++ b/index.css @@ -60,7 +60,6 @@ .things { - padding-top: .25rem; background: var(--bg-2); }