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

View checkmate #90

Open
wants to merge 28 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
1ef27f7
Initiall commit
PiotrRynio Feb 15, 2021
c633f1d
Initiall commit
PiotrRynio Feb 15, 2021
c673194
Merge branch 'develop' of https://github.com/nowakprojects/CodersCamp…
PiotrRynio Feb 15, 2021
b2b8351
Add types
PiotrRynio Feb 15, 2021
57e074b
Fix name of pieceMovesNotCausingAllyKingCheck function
PiotrRynio Feb 15, 2021
ce1fc69
Add first test
PiotrRynio Feb 15, 2021
bb1f3a8
Add second test
PiotrRynio Feb 15, 2021
1d09bc6
Finishtest
PiotrRynio Feb 15, 2021
713ccd2
Add CheckmatedKing variable and isCheckmatedKing function
PiotrRynio Feb 15, 2021
dfb6efe
Delete last added function: isCheckmatedKing
PiotrRynio Feb 15, 2021
44415a3
After code review | Update tests
PiotrRynio Feb 15, 2021
ba8c80f
Add empty method in ChessEngine. Add code in move() method
PiotrRynio Feb 15, 2021
d9fd09e
Fix last commit
PiotrRynio Feb 15, 2021
c31d00d
Add new test
PiotrRynio Feb 15, 2021
609eb8b
Delete doubled test
PiotrRynio Feb 15, 2021
fc29bc5
Fix bug in test
PiotrRynio Feb 15, 2021
1562c78
Finish checkmateHasOccurred function,
PiotrRynio Feb 15, 2021
fcb270a
Finish all without cleaning code.
PiotrRynio Feb 16, 2021
ec6860d
EsLint CoderReview | Update
PiotrRynio Feb 16, 2021
b1424ac
Add tests for Stalemate Has Occurred
PiotrRynio Feb 16, 2021
4d6a243
Add type for Stalemate Has Occurred
PiotrRynio Feb 16, 2021
1174cc2
Fix | Fix test for Stalemate Has Occurred
PiotrRynio Feb 16, 2021
31a136b
Fix | Fix test from others tasks because this tests had bug with stal…
PiotrRynio Feb 16, 2021
001b7d3
Finish stalemate event service
PiotrRynio Feb 16, 2021
dc3a922
Eslint CodeReview | Update
PiotrRynio Feb 16, 2021
054048b
Solution of end game, service of check mate and display of game resul…
tomaszdworniczak Feb 16, 2021
e2a5755
Merge branch 'develop' of https://github.com/nowakprojects/CodersCamp…
tomaszdworniczak Feb 16, 2021
7d9f104
#71 Implement checkmate service, display end game window
tomaszdworniczak Feb 16, 2021
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
19 changes: 19 additions & 0 deletions sass/components/_endGame.scss
Original file line number Diff line number Diff line change
@@ -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;
}
}
1 change: 1 addition & 0 deletions sass/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
@import 'components/chessboard';
@import 'components/button';
@import 'components/piece';
@import 'components/endGame';

// * LAYOUTS
5 changes: 5 additions & 0 deletions src/app/presenter/ChessBoardPresenter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/app/view/ChessBoardView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
16 changes: 16 additions & 0 deletions src/app/view/web/WebChessView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
MateuszNaKodach marked this conversation as resolved.
Show resolved Hide resolved

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!`;
}
Comment on lines +96 to +101
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
endGameText.classList.add('endGame__text');
if (side && position) {
endGameText.innerText = `${side} player lost! Checkmate on ${position}.`;
} else {
endGameText.innerText = `Draw!`;
}
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);
}
}
Binary file added static/img/papirus-background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test/app/presenter/ChessBoardPresenter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ function chessBoardViewMock(viewEventBus: ViewEventBus): ChessBoardView {
hideAllAvailableMoves: jest.fn(),
movePiece: jest.fn(),
capturePiece: jest.fn(),
showEndGameWindow: jest.fn(),
};
}

Expand Down