diff --git a/src/Board.java b/src/Board.java index e04fd3b..c89d40c 100644 --- a/src/Board.java +++ b/src/Board.java @@ -30,9 +30,11 @@ public class Board { ArrayList legalMoves = null; Stack moveHistory; public boolean isGameOver; + public boolean isStalemate; public boolean victor; Image youWin; Image youLose; + Image stalemate; public Board() { moveHistory = new Stack<>(); @@ -41,6 +43,7 @@ public class Board { panel = new DrawingPanel(DIMENSION, DIMENSION); youWin = panel.loadImage("you-win.png"); youLose = panel.loadImage("you-lose.png"); + stalemate = panel.loadImage("stalemate.png"); graphics = panel.getGraphics(); // Connect up event handlers @@ -160,6 +163,7 @@ public class Board { void handleMouseDown(int x, int y) { if (isGameOver) { isGameOver = false; + isStalemate = false; setup(); return; } @@ -231,6 +235,9 @@ public class Board { } undoMove(); } + } else if (getAllLegalMoves(movedPiece.black).isEmpty()) { + isGameOver = true; + isStalemate = true; } victor = movedPiece.black; } @@ -284,7 +291,7 @@ public class Board { // Draw game over text if (isGameOver) { - graphics.drawImage(victor ? youLose : youWin, 0, 0, panel); + graphics.drawImage(isStalemate ? stalemate : (victor ? youLose : youWin), 0, 0, panel); } } diff --git a/stalemate.png b/stalemate.png new file mode 100644 index 0000000..895fc02 Binary files /dev/null and b/stalemate.png differ diff --git a/stalemate.svg b/stalemate.svg new file mode 100644 index 0000000..bc78b9d --- /dev/null +++ b/stalemate.svg @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + STALEMATE + click to play again + + diff --git a/you-lose.svg b/you-lose.svg index e6eee75..eb7c42b 100644 --- a/you-lose.svg +++ b/you-lose.svg @@ -8,7 +8,7 @@ version="1.1" id="svg5" sodipodi:docname="you-lose.svg" - inkscape:export-filename="you-win.png" + inkscape:export-filename="you-lose.png" inkscape:export-xdpi="25.4" inkscape:export-ydpi="25.4" inkscape:version="1.2.2 (b0a8486541, 2022-12-01)" @@ -28,8 +28,8 @@ inkscape:document-units="mm" showgrid="false" inkscape:zoom="0.3901936" - inkscape:cx="1232.7214" - inkscape:cy="1014.8808" + inkscape:cx="786.78891" + inkscape:cy="981.56402" inkscape:window-width="1920" inkscape:window-height="1048" inkscape:window-x="1920" @@ -99,9 +99,9 @@ style="font-size:341.333px;white-space:pre;shape-inside:url(#rect952);display:inline;fill:#3d3d3d;fill-opacity:1;filter:url(#filter1272)">YOU LOSE + id="tspan1821">YOU LOSE