From 7ed89d2dae0ec8078f47244a213898a14b07c3a5 Mon Sep 17 00:00:00 2001 From: Jon Brennan Date: Mon, 13 Nov 2023 15:38:02 -0500 Subject: [PATCH] refactored to temp solution of non-mobile enemies attacking if next to a hero --- src/Board.jsx | 37 ++++++++++++++++++++++++++++++++++++- src/Game.jsx | 10 +++++++--- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/src/Board.jsx b/src/Board.jsx index 059e7d5..ed2bc72 100644 --- a/src/Board.jsx +++ b/src/Board.jsx @@ -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", diff --git a/src/Game.jsx b/src/Game.jsx index 4b4d9be..bd3f1d1 100644 --- a/src/Game.jsx +++ b/src/Game.jsx @@ -4,7 +4,7 @@ import { calculateMoveTiles, getAdjacentTiles } from "./Board"; const hero = { name: "Hero", - position: 23, + position: 9, id: 0, attackDice: 3, defenseDice: 2, @@ -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 }) => { @@ -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); }, },