diff --git a/sass/components/_endGame.scss b/sass/components/_endGame.scss new file mode 100644 index 0000000..c49a17b --- /dev/null +++ b/sass/components/_endGame.scss @@ -0,0 +1,19 @@ +.endGame { + display: flex; + justify-content: center; + align-items: center; + height: 200px; + width: 500px; + background-image: url('../static/img/papirus-background.png'); + background-size: cover; + background-repeat: no-repeat; + background-position: center; + position: absolute; + top: calc(50vh - 100px); + left: calc(50vw - 250px); + &__text { + text-align: center; + font-size: 3rem; + font-family: $font-family--primary; + } +} diff --git a/sass/style.scss b/sass/style.scss index 28df67a..88e9d74 100644 --- a/sass/style.scss +++ b/sass/style.scss @@ -10,5 +10,6 @@ @import 'components/chessboard'; @import 'components/button'; @import 'components/piece'; +@import 'components/endGame'; // * LAYOUTS diff --git a/src/app/presenter/ChessBoardPresenter.ts b/src/app/presenter/ChessBoardPresenter.ts index f7d5806..e0e61b7 100644 --- a/src/app/presenter/ChessBoardPresenter.ts +++ b/src/app/presenter/ChessBoardPresenter.ts @@ -57,6 +57,11 @@ export class ChessBoardPresenter { case 'PieceWasMoved': this.view.movePiece(this.translateSquareToAlgebraicNotation(event.from), this.translateSquareToAlgebraicNotation(event.to)); break; + case 'CheckmateHasOccurred': + this.view.showEndGameWindow(event.king.side.toString(), this.translateSquareToAlgebraicNotation(event.onSquare as Square)); + break; + case 'StalemateHasOccurred': + this.view.showEndGameWindow(); } } diff --git a/src/app/view/ChessBoardView.ts b/src/app/view/ChessBoardView.ts index 8182ec4..5c05fb9 100644 --- a/src/app/view/ChessBoardView.ts +++ b/src/app/view/ChessBoardView.ts @@ -15,4 +15,6 @@ export interface ChessBoardView extends ViewEventSource { movePiece(squareFrom: string, squareTo: string): void; capturePiece(onSquare: string): void; + + showEndGameWindow(side?: string, position?: string): void; } diff --git a/src/app/view/web/WebChessView.ts b/src/app/view/web/WebChessView.ts index aadb410..e6fe13c 100644 --- a/src/app/view/web/WebChessView.ts +++ b/src/app/view/web/WebChessView.ts @@ -86,4 +86,20 @@ export class WebChessView implements ChessBoardView { newPieceElement.src = pieceImage; return newPieceElement; } + + showEndGameWindow(side: string, position: string): void { + //TODO zbudować ładne okno z wyświetleniem wyniku + const endGameModal = document.createElement('div'); + endGameModal.classList.add('endGame'); + + const endGameText = document.createElement('div'); + endGameText.classList.add('endGame__text'); + if (side && position) { + endGameText.innerText = `${side} player lost! Checkmate on ${position}.`; + } else { + endGameText.innerText = `Draw!`; + } + endGameModal.appendChild(endGameText); + this.parent.appendChild(endGameModal); + } } diff --git a/static/img/papirus-background.png b/static/img/papirus-background.png new file mode 100644 index 0000000..cd1e72b Binary files /dev/null and b/static/img/papirus-background.png differ diff --git a/test/app/presenter/ChessBoardPresenter.spec.ts b/test/app/presenter/ChessBoardPresenter.spec.ts index 3b6cd15..cfb8aed 100644 --- a/test/app/presenter/ChessBoardPresenter.spec.ts +++ b/test/app/presenter/ChessBoardPresenter.spec.ts @@ -106,6 +106,7 @@ function chessBoardViewMock(viewEventBus: ViewEventBus): ChessBoardView { hideAllAvailableMoves: jest.fn(), movePiece: jest.fn(), capturePiece: jest.fn(), + showEndGameWindow: jest.fn(), }; }