Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/api/src/game/Game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export class Game {
}

shootInDirection(directionHex: Hex, shooter: Player) {
if (shooter.pos.equals(directionHex)) return false;
let shotCard = false;
shooter.previousPos = shooter.pos;
const RANGE = 3;
Expand All @@ -95,7 +96,6 @@ export class Game {
if (position.equals(this.cardPos!)) {
shooter.lastBulletHex = this.cardPos;
this.previousCardPos = this.cardPos;
// this.spawnCard();
shotCard = true;
return shotCard;
}
Expand Down
4 changes: 4 additions & 0 deletions apps/api/src/game/game-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ export const MOVE_DURATION_IN_SECONDS = 15;
export function isNeighbor(hex: Hex, other: Hex) {
return hex.neighbors().some((n) => n.equals(other));
}

export function isSameMove(move: Hex, pos: Hex | null) {
return move.q === pos?.q && move.r === pos?.r;
}
14 changes: 10 additions & 4 deletions apps/api/src/game/game.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,16 @@ export class GameService {
if (p.pendingMove !== null) {
console.log("pending move wasn't null", p.playerType);
}

if (p.pendingMove === null) {
if (p.pos.equals(data.move)) return;
if (!isNeighbor(p.pos, data.move)) return;
if (!data.isShooting) {
if (
p.pendingMove === null &&
!(isNeighbor(p.pos, data.move) || p.pos.equals(data.move))
)
return;
} else {
if (p.pendingMove === null && !isNeighbor(p.pos, data.move)) {
return;
}
}
p.pendingMove = new Hex(data.move.q, data.move.r);
}
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/AnimatedPopup/AnimatedPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const AnimatedPopup: React.FC<Props> = ({
return (
<div className={c.popup}>
{events.map((e) => (
<PopupImage eventType={e} canvasSize={canvasSize} />
<PopupImage key={e} eventType={e} canvasSize={canvasSize} />
))}
</div>
);
Expand Down
23 changes: 17 additions & 6 deletions apps/web/src/components/Game/Game.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,24 @@ const Game = () => {
(p) => p.walletId === walletId?.toString(),
)!;

if (
currentPlayer &&
(!isNeighbor(move, currentPlayer.pos) ||
if (!isShooting) {
if (
!(
isNeighbor(move, currentPlayer.pos) ||
isSameMove(move, currentPlayer.pos)
) ||
!isInGrid(move, gameState.grid, gameState.disappearedHexes)
) {
return;
}
} else {
if (
!isNeighbor(move, currentPlayer.pos) ||
!isInGrid(move, gameState.grid, gameState.disappearedHexes) ||
isSameMove(move, currentPlayer.pos))
) {
return;
isSameMove(move, currentPlayer.pos)
) {
return;
}
}
setClickedHex(hoveredHex);
setMadeMove(true);
Expand Down
5 changes: 1 addition & 4 deletions apps/web/src/utils/calculation-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,7 @@ export function isInGrid(hex: Hex, grid: Hex[], disappearedHexes: Hex[]) {
}

export function isSameMove(move: Hex, pos: Hex | null) {
if (move.q === pos?.q && move.r === pos?.r) {
return true;
}
return false;
return move.q === pos?.q && move.r === pos?.r;
}

export function inverseIsometricTransformation(
Expand Down