Skip to content

Commit

Permalink
refactored to temp solution of non-mobile enemies attacking if next t…
Browse files Browse the repository at this point in the history
…o a hero
  • Loading branch information
Jon Brennan authored and Jon Brennan committed Nov 13, 2023
1 parent ba2f7f5 commit 7ed89d2
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
37 changes: 36 additions & 1 deletion src/Board.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,45 @@ export function Board({ ctx, G, moves }) {
const boardTiles = G.tiles.length;
const currentPlayer = G.players[ctx.currentPlayer];
const currentPosition = currentPlayer.position;
const currentPlayerTeam = currentPlayer.team;

if (currentPlayerTeam === "ENEMY") {
console.log("AI is thinking...");

// console.log(moves);
// while (!currentPlayer.hasMoved) {
const otherTeam = "HERO";
const otherTeamPlayer = G.players.find(
(player) => player.team === otherTeam
);
// console.log(otherTeamPlayer);
const otherTeamPosition = otherTeamPlayer.position;
// console.log(otherTeamPosition);
if (
isAdjacentTile(otherTeamPosition, currentPosition, boardTiles) &&
!currentPlayer.hasDoneAction
) {
moves.attack(otherTeamPosition);
// const isAdjacentToOtherTeam = (position) => {
// const adjacentPositions = getAdjacentTiles(position, G.tiles.length);
// return adjacentPositions.some((position) => {
// return otherTeamPositions.includes(position);
// });
// };

// if (isAdjacentToOtherTeam(currentPosition)) {
// otherTeamPositions.forEach((position) => {
// if (isAdjacentTile(position, currentPosition, G.tiles.length)) {
// moves.attack(position);
// }
// });
// }
}
}

const handleKeyPress = (event) => {
const key = event.key.toLowerCase();
console.log(key);
// console.log(key);
const movementKeys = [
"w",
"a",
Expand Down
10 changes: 7 additions & 3 deletions src/Game.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { calculateMoveTiles, getAdjacentTiles } from "./Board";

const hero = {
name: "Hero",
position: 23,
position: 9,
id: 0,
attackDice: 3,
defenseDice: 2,
Expand Down Expand Up @@ -50,7 +50,8 @@ export const DungeonHopper = {
G.tiles.length
);
console.log(distance);
return distance;
console.log(G.ai.play);
// return distance;
},

rollMovementDice: ({ G, ctx, random, events, playerID }) => {
Expand Down Expand Up @@ -154,11 +155,14 @@ export const DungeonHopper = {
},

turn: {
onBegin: ({ G }) => {
onBegin: ({ G, ctx }) => {
G.players.forEach((player) => {
player.hasMoved = false;
player.hasDoneAction = false;
});

const currentPlayer = G.players[ctx.currentPlayer];
console.log("Active Team:", currentPlayer.team);
},
},

Expand Down

0 comments on commit 7ed89d2

Please sign in to comment.