Skip to content

Commit

Permalink
Built site for gh-pages
Browse files Browse the repository at this point in the history
  • Loading branch information
dhmmasson committed Oct 6, 2024
1 parent b41c6e0 commit 41b1506
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .nojekyll
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0f41bd3f
4a807706
39 changes: 24 additions & 15 deletions src/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function aiThink() {
if (Game.action == Actions.select) {
let frog = random(
Game.players[Game.currentPlayer].frogs
.filter((frog) => !frog.selected)
//.filter((frog) => !frog.selected)
.filter((frog) => getValidMoves(frog).length > 0) // Only select frogs that can move
);
frog.selected = true;
Expand All @@ -88,7 +88,13 @@ function aiThink() {
if (Game.action == Actions.move) {
let frog = Game.currentFrog;
let quads = getValidMoves(frog);

if (quads.length == 0) {
Game.players[Game.currentPlayer].done = true;
frog.selected = false;
Game.currentFrog = null;
Game.action = Actions.select;
return false;
}
let quad = random(quads);
quad =
quads.reduce((acc, quad) => {
Expand Down Expand Up @@ -224,6 +230,22 @@ function drawGame() {
drawFrogs();

displayScore();
if (Game.action != Actions.place && Game.action != Actions.wait) {
Game.players.forEach((player) => {
player.done = isPlayerDone(player);
});
// If both players are done, end the game
if (Game.players.reduce((acc, player) => acc && player.done, true)) {
clearInterval(Game.aiHandle);
Game.highscores.push(Game.players[0].score);
Game.state = GameStates.menu;
Game.nextMenu = "main";
Game.action = Actions.wait;
}
if (Game.players[Game.currentPlayer].done) {
Game.currentPlayer = (Game.currentPlayer + 1) % Game.players.length;
}
}
}

function setup() {
Expand Down Expand Up @@ -323,19 +345,6 @@ function PlayingFrog() {
Game.currentPlayer = (Game.currentPlayer + 1) % Game.players.length;
Game.action = Actions.select;
unvalidBoard();

Game.players.forEach((player) => {
player.done = isPlayerDone(player);
});
// If both players are done, end the game
if (Game.players.reduce((acc, player) => acc && player.done, true)) {
Game.higscores.push(Game.players[0].score);
Game.state = GameStates.menu;
Game.nextMenu = "main";
}
if (Game.players[Game.currentPlayer].done) {
Game.currentPlayer = (Game.currentPlayer + 1) % Game.players.length;
}
}
}
}
Expand Down
20 changes: 9 additions & 11 deletions src/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,7 @@ function displayMenu() {
if (Game.state !== GameStates.menu) {
return false;
}
try {
textAlign(CENTER, TOP);
fill(colors["Vanilla"]);
text(
"Higscore " + Game.highscores.reduce(max, 0),
Game.board.size.width / 2,
10
);
} catch (error) {
console.log(error);
}

// Create the menu on menu change
if (Game.currentMenu !== Game.nextMenu) {
initMenu(Game.menus[Game.nextMenu]);
Expand All @@ -70,6 +60,14 @@ function displayMenu() {

// Check if buttons are pressed
checkButtons();

textAlign(CENTER, TOP);
fill(colors["Vanilla"]);
text(
"Higscore " + Game.highscores.reduce(max, 0),
Game.board.size.width / 2,
10
);
}

function displayScore() {
Expand Down

0 comments on commit 41b1506

Please sign in to comment.