Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#209] pieces now stop near a piece with a shield when attacking it #222

Merged
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
26 changes: 25 additions & 1 deletion development/code/logic/PieceLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,31 @@ function move(

function failToKillPiece(draggedPiece: Piece, targetPiece: Piece) {
destroyItemOnPiece(targetPiece);
revertPieceMoveOnBoard(draggedPiece);

// Takes the difference of the dragged and target positions in both axis,
// if the dragged position is higher - it would be positive, if lower - negative
// then I use that to determine the direction to move away from the target position
// and divide it by itself cause I wanna move by 1 in any direction
let directionX = 0;
let directionY = 0;
const targetXPosition = targetPiece.position.coordinates[0];
const targetYPosition = targetPiece.position.coordinates[1];
const deltaX = draggedPiece.position.coordinates[0] - targetXPosition;
const deltaY = draggedPiece.position.coordinates[1] - targetYPosition;
if (deltaX !== 0) {
directionX = deltaX / Math.abs(deltaX);
}
if (deltaY !== 0) {
directionY = deltaY / Math.abs(deltaY);
}

const newPosition: Position = {
coordinates: [targetXPosition + directionX, targetYPosition + directionY],
boardId: draggedPiece.position.boardId,
};
movePieceOnBoard(draggedPiece, newPosition);
draggedPiece.position = newPosition;

game.endMove();
}

Expand Down
4 changes: 2 additions & 2 deletions development/code/logic/pieces/Queen.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ describe('Piece killing', () => {
game.setPieces([killerQueen, firstVictimPiece]);
onPlayerAction(killerQueen, firstVictimPiece);

let firstVictimPieceBoardId = firstVictimPiece.position.boardId;
const firstVictimPieceBoardId = firstVictimPiece.position.boardId;
expect(firstVictimPieceBoardId).toEqual(HEAVEN_BOARD_ID);

let killerNewCoordinates = killerQueen.position.coordinates;
Expand All @@ -109,7 +109,7 @@ describe('Piece killing', () => {
killerNewCoordinates = killerQueen.position.coordinates;
expect(killerNewCoordinates).toEqual(diagonalVictimPosition.coordinates);

let playerXP = killerQueen.player.xp;
const playerXP = killerQueen.player.xp;
expect(playerXP).toBeGreaterThan(0);
});
});
4 changes: 3 additions & 1 deletion development/code/logic/rules/BountyRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ export class BountyRule extends BaseRule {
position: { coordinates: pieceCoordinates },
} = piece;
new RuleLog(
`There is an open bounty on a ${playerColor} ${pieceName} [${pieceCoordinates.join(',')}].`,
`There is an open bounty on a ${playerColor} ${pieceName} [${pieceCoordinates.join(
',',
)}].`,
Ido-Barnea marked this conversation as resolved.
Show resolved Hide resolved
).addToQueue();
}
});
Expand Down
Loading