Skip to content

Commit

Permalink
adjacent object now not highlighted if action was taken; turn now aut…
Browse files Browse the repository at this point in the history
…o-ends if moveTiles == 0 and no action can be taken
  • Loading branch information
Jon Brennan authored and Jon Brennan committed Dec 12, 2023
1 parent 2801db2 commit 7c8ea9d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 29 deletions.
1 change: 0 additions & 1 deletion src/App.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
a {
/* text-decoration: none; */
color: white;
}

Expand Down
12 changes: 7 additions & 5 deletions src/components/Board.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,12 @@ export function Board({ ctx, G, moves, events }) {
const isOpponent =
isAdjacent &&
G.tiles[idx] !== null &&
!currentPlayer.hasDoneAction &&
G.players.find((player) => G.tiles[idx] === player.team) &&
G.players.find((player) => G.tiles[idx] === player.team) !==
currentPlayer.team;
const isItem = isAdjacent && G.tiles[idx] === "BOX";
const isItem =
isAdjacent && !currentPlayer.hasDoneAction && G.tiles[idx] === "BOX";

const tileContent = G.tiles[idx];

Expand Down Expand Up @@ -302,6 +304,7 @@ export function isAdjacentTile(newTile, refTile, boardSize) {
}

export function getAdjacentTiles(tileIdx, boardSize) {
console.log("getAdjacentTiles");
const rowSize = Math.sqrt(boardSize);
const sameRow = Math.floor(tileIdx / rowSize);
const sameColumn = tileIdx % rowSize;
Expand All @@ -320,6 +323,8 @@ export function getAdjacentTiles(tileIdx, boardSize) {
adjacentTiles.push(tileIdx + 1);
}

// console.log(adjacentTiles);

return adjacentTiles;
}

Expand Down Expand Up @@ -355,10 +360,7 @@ function renderMovementRoll(roll) {
}
if (die === 5) {
return <GiDiceSixFacesFive key={idx} className="movement-die" />;
}
if (die === 6) {
return <GiDiceSixFacesSix key={idx} className="movement-die" />;
}
} else return <GiDiceSixFacesSix key={idx} className="movement-die" />;
});
}

Expand Down
26 changes: 12 additions & 14 deletions src/components/Game.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,6 @@ export const DungeonThrowdown = {
if (currentPlayer.moveTiles === 0) {
currentPlayer.isMoving = false;
currentPlayer.hasMoved = true;
if (
getAdjacentTiles(currentPosition, G.tiles.length).every((tile) => {
return tile === null;
})
) {
events.endTurn();
}
}
},

Expand Down Expand Up @@ -215,7 +208,7 @@ export const DungeonThrowdown = {
currentPlayer.hasMoved = true;
}
},
openBox: ({ G, playerID, random }, tileIdx) => {
openBox: ({ G, playerID, random, moves }, tileIdx) => {
const currentPlayer = G.players[playerID];
const currentPlayerName = currentPlayer.name;
const currentPlayerTeam = currentPlayer.team;
Expand Down Expand Up @@ -263,6 +256,7 @@ export const DungeonThrowdown = {
G.messages.game = "The box is empty!";
}
} else {
console.log(moves);
G.messages.game = "Can't do that right now!";
}
},
Expand All @@ -286,6 +280,8 @@ export const DungeonThrowdown = {
const occupiedTiles = G.tiles.map((tile, idx) => {
if (tile !== null) {
return idx;
} else {
return null;
}
});

Expand All @@ -305,19 +301,21 @@ export const DungeonThrowdown = {
currentPlayer.isMoving = false;
currentPlayer.hasMoved = false;
currentPlayer.hasDoneAction = false;
currentPlayer.moveTiles = 0;
},

endIf: ({ G, ctx }) => {
const currentPlayer = G.players[ctx.currentPlayer];
return (
!currentPlayer.isMoving &&
currentPlayer.hasMoved &&
currentPlayer.hasDoneAction
// || (
// !currentPlayer.isMoving &&
// currentPlayer.hasMoved &&
// getAdjacentTiles(currentPlayer.position, G.tiles.length).length === 0
// )
(currentPlayer.hasDoneAction ||
getAdjacentTiles(currentPlayer.position, G.tiles.length).every(
(tile) => {
console.log(tile, G.tiles[tile]);
return G.tiles[tile] === null;
}
))
);
},
},
Expand Down
8 changes: 0 additions & 8 deletions src/pages/Client.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
// import { Client } from "boardgame.io/react";
// import { DungeonThrowdown } from "../components/Game";
// import { Board } from "../components/Board";

// const ClientPage = Client({ game: DungeonThrowdown, board: Board });

// export default ClientPage;

import React, { useState, useEffect } from "react";
import { Client } from "boardgame.io/react";
import { DungeonThrowdown } from "../components/Game";
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Rules.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const Rules = () => {
<b>YOUR TURN:</b> Each turn has two phases, a Movement and an Action. To
move to an adjacent tile{" "}
<em>(i.e. one above, below, or to the side of you)</em>, you can{" "}
<GiArrowCursor /> click on that tile OR press the cooresponding{" "}
<GiArrowCursor /> click on that tile OR press the corresponding{" "}
<span style={{ fontSize: 24 }}>
<LuArrowUpSquare />
<LuArrowLeftSquare />
Expand Down

0 comments on commit 7c8ea9d

Please sign in to comment.