From 5a780d925464a62ee0d6d25f8b1e6af4b19ec401 Mon Sep 17 00:00:00 2001 From: tsiklic1 Date: Tue, 11 Nov 2025 10:12:48 +0100 Subject: [PATCH 1/3] remove isSameMoveFunction on frontend --- apps/web/src/components/Game/Game.tsx | 4 +--- apps/web/src/utils/calculation-utils.ts | 7 ------- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/apps/web/src/components/Game/Game.tsx b/apps/web/src/components/Game/Game.tsx index 6c4a4bb..c08b98e 100644 --- a/apps/web/src/components/Game/Game.tsx +++ b/apps/web/src/components/Game/Game.tsx @@ -4,7 +4,6 @@ import { getMousePosition, getNearestHex, isInGrid, - isSameMove, pixelToHex, } from '../../utils/calculation-utils'; import { repaint, repaintAnimationLoop } from '../../utils/repaint'; @@ -154,8 +153,7 @@ const Game = () => { if ( currentPlayer && (!isNeighbor(move, currentPlayer.pos) || - !isInGrid(move, gameState.grid, gameState.disappearedHexes) || - isSameMove(move, currentPlayer.pos)) + !isInGrid(move, gameState.grid, gameState.disappearedHexes)) ) { return; } diff --git a/apps/web/src/utils/calculation-utils.ts b/apps/web/src/utils/calculation-utils.ts index 60951f4..38cb627 100644 --- a/apps/web/src/utils/calculation-utils.ts +++ b/apps/web/src/utils/calculation-utils.ts @@ -59,13 +59,6 @@ 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; -} - export function inverseIsometricTransformation( ox: number, oy: number, From 4f2a6f0960dce1bb0c261cce23b8c1c697e0724f Mon Sep 17 00:00:00 2001 From: tsiklic1 Date: Tue, 11 Nov 2025 12:50:41 +0100 Subject: [PATCH 2/3] add check for same move on shooting on backend --- apps/api/src/game/Game.ts | 2 +- apps/api/src/game/game-utils.ts | 4 +++ apps/api/src/game/game.service.ts | 22 +++++++++++++--- .../AnimatedPopup/AnimatedPopup.tsx | 2 +- apps/web/src/components/Game/Game.tsx | 25 ++++++++++++++----- apps/web/src/utils/calculation-utils.ts | 4 +++ apps/web/src/utils/draw-utils.ts | 12 ++++----- 7 files changed, 53 insertions(+), 18 deletions(-) diff --git a/apps/api/src/game/Game.ts b/apps/api/src/game/Game.ts index f5abe38..6fdf61e 100644 --- a/apps/api/src/game/Game.ts +++ b/apps/api/src/game/Game.ts @@ -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; @@ -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; } diff --git a/apps/api/src/game/game-utils.ts b/apps/api/src/game/game-utils.ts index e22374c..532543f 100644 --- a/apps/api/src/game/game-utils.ts +++ b/apps/api/src/game/game-utils.ts @@ -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; +} diff --git a/apps/api/src/game/game.service.ts b/apps/api/src/game/game.service.ts index d5495f2..19ae501 100644 --- a/apps/api/src/game/game.service.ts +++ b/apps/api/src/game/game.service.ts @@ -239,16 +239,29 @@ 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)) { + console.log('hit', data.move, p.pendingMove); + return; + } } + console.log('pendig move set'); p.pendingMove = new Hex(data.move.q, data.move.r); } } }); + console.log('============================='); + game.players.forEach((p) => { + console.log(p.playerType, p.pendingMove); + }); + game.players.forEach((p) => (p.justPickedCard = false)); const waitingForMoves = game.players.some( @@ -290,6 +303,7 @@ export class GameService { game.players.forEach((p) => { if (p.isShooting) { p.lastSeenPos = p.pos; + console.log('shoot', p.playerType, p.pendingMove); const playerShotCard = game.shootInDirection(p.pendingMove!, p); if (playerShotCard) { someoneShotCard = true; diff --git a/apps/web/src/components/AnimatedPopup/AnimatedPopup.tsx b/apps/web/src/components/AnimatedPopup/AnimatedPopup.tsx index 9e88ac1..427ac7a 100644 --- a/apps/web/src/components/AnimatedPopup/AnimatedPopup.tsx +++ b/apps/web/src/components/AnimatedPopup/AnimatedPopup.tsx @@ -32,7 +32,7 @@ const AnimatedPopup: React.FC = ({ return (
{events.map((e) => ( - + ))}
); diff --git a/apps/web/src/components/Game/Game.tsx b/apps/web/src/components/Game/Game.tsx index c08b98e..e00f3e4 100644 --- a/apps/web/src/components/Game/Game.tsx +++ b/apps/web/src/components/Game/Game.tsx @@ -4,6 +4,7 @@ import { getMousePosition, getNearestHex, isInGrid, + isSameMove, pixelToHex, } from '../../utils/calculation-utils'; import { repaint, repaintAnimationLoop } from '../../utils/repaint'; @@ -150,12 +151,24 @@ const Game = () => { (p) => p.walletId === walletId?.toString(), )!; - if ( - currentPlayer && - (!isNeighbor(move, currentPlayer.pos) || - !isInGrid(move, gameState.grid, gameState.disappearedHexes)) - ) { - return; + 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; + } } setClickedHex(hoveredHex); setMadeMove(true); diff --git a/apps/web/src/utils/calculation-utils.ts b/apps/web/src/utils/calculation-utils.ts index 38cb627..d5caa89 100644 --- a/apps/web/src/utils/calculation-utils.ts +++ b/apps/web/src/utils/calculation-utils.ts @@ -59,6 +59,10 @@ export function isInGrid(hex: Hex, grid: Hex[], disappearedHexes: Hex[]) { ); } +export function isSameMove(move: Hex, pos: Hex | null) { + return move.q === pos?.q && move.r === pos?.r; +} + export function inverseIsometricTransformation( ox: number, oy: number, diff --git a/apps/web/src/utils/draw-utils.ts b/apps/web/src/utils/draw-utils.ts index f667855..9950d98 100644 --- a/apps/web/src/utils/draw-utils.ts +++ b/apps/web/src/utils/draw-utils.ts @@ -71,12 +71,12 @@ export function drawHexIsometric( ctx.restore(); ctx.save(); - // ctx.fillStyle = 'white'; - // ctx.font = `${Math.floor(size / 4)}px Arial`; - // ctx.textAlign = 'center'; - // ctx.textBaseline = 'middle'; - // const { ox: ocx, oy: ocy } = applyIsometricTransformation(x, y, size); - // ctx.fillText(`${hex.q},${hex.r}`, ocx, ocy); + ctx.fillStyle = 'white'; + ctx.font = `${Math.floor(size / 4)}px Arial`; + ctx.textAlign = 'center'; + ctx.textBaseline = 'middle'; + const { ox: ocx, oy: ocy } = applyIsometricTransformation(x, y, size); + ctx.fillText(`${hex.q},${hex.r}`, ocx, ocy); } export function drawPlayerIsometric( From 73dfefb40c7123a587503242e36b7d0578e838f7 Mon Sep 17 00:00:00 2001 From: tsiklic1 Date: Tue, 11 Nov 2025 12:55:31 +0100 Subject: [PATCH 3/3] remove console logs --- apps/api/src/game/game.service.ts | 8 -------- apps/web/src/utils/draw-utils.ts | 12 ++++++------ 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/apps/api/src/game/game.service.ts b/apps/api/src/game/game.service.ts index 19ae501..bbb02bf 100644 --- a/apps/api/src/game/game.service.ts +++ b/apps/api/src/game/game.service.ts @@ -247,21 +247,14 @@ export class GameService { return; } else { if (p.pendingMove === null && !isNeighbor(p.pos, data.move)) { - console.log('hit', data.move, p.pendingMove); return; } } - console.log('pendig move set'); p.pendingMove = new Hex(data.move.q, data.move.r); } } }); - console.log('============================='); - game.players.forEach((p) => { - console.log(p.playerType, p.pendingMove); - }); - game.players.forEach((p) => (p.justPickedCard = false)); const waitingForMoves = game.players.some( @@ -303,7 +296,6 @@ export class GameService { game.players.forEach((p) => { if (p.isShooting) { p.lastSeenPos = p.pos; - console.log('shoot', p.playerType, p.pendingMove); const playerShotCard = game.shootInDirection(p.pendingMove!, p); if (playerShotCard) { someoneShotCard = true; diff --git a/apps/web/src/utils/draw-utils.ts b/apps/web/src/utils/draw-utils.ts index 9950d98..f667855 100644 --- a/apps/web/src/utils/draw-utils.ts +++ b/apps/web/src/utils/draw-utils.ts @@ -71,12 +71,12 @@ export function drawHexIsometric( ctx.restore(); ctx.save(); - ctx.fillStyle = 'white'; - ctx.font = `${Math.floor(size / 4)}px Arial`; - ctx.textAlign = 'center'; - ctx.textBaseline = 'middle'; - const { ox: ocx, oy: ocy } = applyIsometricTransformation(x, y, size); - ctx.fillText(`${hex.q},${hex.r}`, ocx, ocy); + // ctx.fillStyle = 'white'; + // ctx.font = `${Math.floor(size / 4)}px Arial`; + // ctx.textAlign = 'center'; + // ctx.textBaseline = 'middle'; + // const { ox: ocx, oy: ocy } = applyIsometricTransformation(x, y, size); + // ctx.fillText(`${hex.q},${hex.r}`, ocx, ocy); } export function drawPlayerIsometric(