Skip to content

Commit c915d33

Browse files
authored
Merge pull request #180 from Ido-Barnea/131-create-a-shield-item
Created shield item
2 parents e9e8c37 + fb477a3 commit c915d33

File tree

11 files changed

+175
-114
lines changed

11 files changed

+175
-114
lines changed

development/code/Game.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { Piece } from './logic/pieces/Piece';
1010
import { Queen } from './logic/pieces/Queen';
1111
import { Rook } from './logic/pieces/Rook';
1212
import { RulesManager } from './logic/rules/RulesManager';
13-
import { showWinningAlert } from './ui/Screen';
13+
import { showWinningAlert as showGameEndAlert } from './ui/Screen';
1414

1515
let rulesManager: RulesManager;
1616
const whitePlayer = new Player(PlayerColors.WHITE);
@@ -59,7 +59,7 @@ let isCastling = false;
5959
let isFriendlyFire = false;
6060
let isPieceKilled = false;
6161
let fellOffTheBoardPiece: Piece | undefined;
62-
let winner: Player | undefined = undefined;
62+
let isGameFinished = false;
6363

6464
function initializeGame() {
6565
rulesManager = new RulesManager();
@@ -86,8 +86,10 @@ function endTurn() {
8686
// To make sure the element is removed before displaying the winning alert, we need to add
8787
// a small delay before displaying the alert.
8888
setTimeout(() => {
89-
if (winner !== undefined) {
90-
showWinningAlert(winner.color);
89+
if (isGameFinished) {
90+
const livingKingPlayer = pieces.filter(piece => piece instanceof King)[0].player;
91+
92+
showGameEndAlert(livingKingPlayer.color);
9193
window.location.reload();
9294
}
9395
}, 10);
@@ -192,12 +194,13 @@ function setFellOffTheBoardPiece(_fellOffTheBoardPiece: Piece | undefined) {
192194
fellOffTheBoardPiece = _fellOffTheBoardPiece;
193195
}
194196

195-
function setWinner(_winner: Player) {
196-
winner = _winner;
197+
function endGame() {
198+
isGameFinished = true;
197199
}
198200

199201
export const game = {
200202
initialize: initializeGame,
203+
end: endGame,
201204
endTurn,
202205
getCurrentPlayer,
203206
switchIsCastling,
@@ -217,5 +220,4 @@ export const game = {
217220
setIsPieceKilled,
218221
getFellOffTheBoardPiece,
219222
setFellOffTheBoardPiece,
220-
setWinner,
221223
};

development/code/LogicAdapter.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { game } from './Game';
22
import { isPlayerAllowedToAct, onPieceFellOffTheBoard, onPlayerAction } from './logic/PieceLogic';
3-
import { Player, PlayerColors } from './logic/Players';
3+
import { PlayerColors } from './logic/Players';
44
import { comparePositions, convertSquareIdToPosition } from './logic/Utilities';
55
import { Item } from './logic/items/Items';
66
import { Piece } from './logic/pieces/Piece';
@@ -131,16 +131,16 @@ export function onPieceSelected(
131131

132132
export function movePieceOnBoard(
133133
draggedPiece: Piece,
134-
targetSquare: Square,
134+
targetPosition: Position,
135135
) {
136136
const draggedPieceCoordinates = draggedPiece.position.coordinates;
137137
const originSquareId = draggedPieceCoordinates.join(',');
138138

139139
const boardId = draggedPiece.position.boardId;
140-
const targetSquareId = targetSquare.position.coordinates.join(',');
140+
const targetSquareId = targetPosition.coordinates.join(',');
141141

142142
// Ensure square is not highlighted if piece did not move
143-
if (!comparePositions(draggedPiece.position, targetSquare.position)) {
143+
if (!comparePositions(draggedPiece.position, targetPosition)) {
144144
const originSquareElement = getSquareElementById(originSquareId, boardId) as HTMLElement;
145145
const targetSquareElement = getSquareElementById(targetSquareId, boardId) as HTMLElement;
146146
highlightLastMove(originSquareElement, targetSquareElement, boardId);
@@ -196,6 +196,6 @@ export function changePieceToAnotherPlayer(piece: Piece) {
196196
piece.player = game.getPlayers().filter(_player => _player !== piece.player)[0];
197197
}
198198

199-
export function winGame(winnerPlayer: Player){
200-
game.setWinner(winnerPlayer);
199+
export function endGame(){
200+
game.end();
201201
}

development/code/logic/Constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@ export const SELECTED_PIECE_CLASS = 'selected-piece';
2222
export const NOTATIONS_LETTERS = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'];
2323
export const NOTATIONS_NUMBERS = ['8', '7', '6', '5', '4', '3', '2', '1'];
2424
export const BOARD_WIDTH = 8;
25+
26+
export const MIN_KILLINGS_FOR_BOUNTY = 3;

0 commit comments

Comments
 (0)