Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
4yman-0 committed Nov 12, 2024
1 parent fda4e47 commit 8d68bac
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 63 deletions.
19 changes: 5 additions & 14 deletions archive/foobar.ai/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
padding: 0;
}

.header {
padding: 0 1.5rem;
}

.header__links {
display: flex;
gap: .8rem;
Expand All @@ -32,7 +28,7 @@
.hero__container {
display: inline-block;
padding: 1rem;
background: rgba(0, 0, 10, .6);
background: #2C2C32;
border-radius: 1rem;
}

Expand All @@ -47,11 +43,6 @@
.hero__btn {
width: fit-content;
margin-left: auto;
text-align: center;
}

.why-foobar {
padding-top: 20vh;
}

.cards {
Expand Down Expand Up @@ -84,7 +75,7 @@
}

.solutions {
padding-top: 15vh;
padding: 3rem .4rem;
}

.solutions__title {
Expand Down Expand Up @@ -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;
Expand Down
14 changes: 11 additions & 3 deletions archive/webgames/js/dom.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
const $ = (id) => document.getElementById(id);
const $q = (q) => document.querySelector(q);
const $qa = (qa) => document.querySelectorAll(qa);
function $(id) {
return document.getElementById(id);
}

function $q(q) {
return document.querySelector(q);
}

function $qa(q) {
return document.getElementById(q);
}
32 changes: 15 additions & 17 deletions archive/webgames/snake/js/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
/**
Expand All @@ -30,7 +30,7 @@ const game = {
moved: false,

startGame() {
gameState.reset();
resetGameState();
game.updateScore();
DOM.hideModal();
game.gameLoop = setInterval(game.frame, 150);
Expand Down Expand Up @@ -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) {
Expand All @@ -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();
Expand Down Expand Up @@ -156,9 +154,9 @@ const game = {
endGame() {
clearInterval(game.gameLoop);
gameState.over = true;
gameState.reset();
resetGameState();
DOM.showModal();
}
};

export { game, gameState };
export { game, gameState };
3 changes: 1 addition & 2 deletions archive/webgames/snake/js/gameDOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@ const DOM = {
},
};


export default DOM;
export default DOM;
2 changes: 1 addition & 1 deletion archive/webgames/snake/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ DOM.mobileButtons[2].addEventListener("click",
DOM.mobileButtons[3].addEventListener("click",
() => gameState.inputBuffer.unshift("ArrowRight"));

game.startGame();
game.startGame();
38 changes: 19 additions & 19 deletions archive/webgames/tic-tac-toe/js/ai.js
Original file line number Diff line number Diff line change
@@ -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;
// 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;
3 changes: 1 addition & 2 deletions archive/webgames/tic-tac-toe/js/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const DOM = {
board: $('game-board'),
cells: $qa('.cell'),


swapModals() {
DOM.modeModal.classList.toggle('hidden');
DOM.winModal.classList.toggle('hidden');
Expand All @@ -36,4 +35,4 @@ const GameModes = {
TWO_PLAYERS: 1
};

export { DOM, Players, GameModes };
export { DOM, Players, GameModes };
6 changes: 3 additions & 3 deletions archive/webgames/tic-tac-toe/js/game.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DOM, Players, GameModes } from './constants.js';
import AI from './ai.js';
import AIMove from './ai.js';

const Game = {
cells: [
Expand Down Expand Up @@ -31,7 +31,7 @@ const Game = {
];
Game.updateBoard();
if (Game.difficulty === GameModes.NORMAL && Game.turn === Players.O) {
AI.move();
AIMove();
}
},

Expand Down Expand Up @@ -133,4 +133,4 @@ const Game = {
}
};

export default Game;
export default Game;
2 changes: 1 addition & 1 deletion archive/webgames/tic-tac-toe/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ DOM.cells.forEach((cell, index) => {
const y = index % 3;
Game.captureCell(x, y);
});
});
});
1 change: 0 additions & 1 deletion index.css
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@


.things {
padding-top: .25rem;
background: var(--bg-2);
}

Expand Down

0 comments on commit 8d68bac

Please sign in to comment.