Skip to content

Commit

Permalink
Merge pull request #216 from Ido-Barnea/205-pieces-dont-kill-when-spa…
Browse files Browse the repository at this point in the history
…wning-on-another-piece-1

[#205] Fixed pieces not killing when spawning on piece
  • Loading branch information
Ido-Barnea authored Feb 21, 2024
2 parents 41fadde + 265ddf9 commit aad5ef8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions development/code/LogicAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ export function movePieceOnBoard(
}

export function destroyPieceOnBoard(piece: Piece) {
const tpieceCoordinates = piece.position.coordinates;
const squareId = tpieceCoordinates.join(',');
const pieceCoordinates = piece.position.coordinates;
const squareId = pieceCoordinates.join(',');

destroyElementOnBoardByPosition(squareId, piece.position.boardId);
}
Expand Down
4 changes: 2 additions & 2 deletions development/code/logic/PieceLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,12 @@ function killPieceByAnotherPiece(
draggedPiece.player.gold += targetPiece.killCount;
}

destroyPieceOnBoard(targetPiece);
killPiece(targetPiece);
new KillLog(targetPiece, draggedPiece).addToQueue();
return true;
}

function killPieceByGame(targetPiece: Piece, killCause: string) {
destroyPieceOnBoard(targetPiece);
killPiece(targetPiece);
new KillLog(targetPiece, killCause).addToQueue();
}
Expand All @@ -269,6 +267,8 @@ function killPiece(targetPiece: Piece) {
}

function handleOverworldKill(targetPiece: Piece) {
destroyPieceOnBoard(targetPiece);

if (targetPiece.killCount > 0 || targetPiece instanceof King) {
targetPiece.position.boardId = HELL_BOARD_ID;
} else {
Expand Down
5 changes: 4 additions & 1 deletion development/code/logic/pieces/DoubleQueen.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ describe('Piece killing', () => {
coordinates: [2, 2],
boardId: OVERWORLD_BOARD_ID,
};
const killerDoubleQueen = new DoubleQueen(initialKillerPosition, whitePlayer);
const killerDoubleQueen = new DoubleQueen(
initialKillerPosition,
whitePlayer,
);

const victimPosition: Position = {
coordinates: [2, 5],
Expand Down

0 comments on commit aad5ef8

Please sign in to comment.