Add stalemate text

main
Elnu 2 years ago
parent 446006cf4a
commit e178d88742

@ -30,9 +30,11 @@ public class Board {
ArrayList<Move> legalMoves = null; ArrayList<Move> legalMoves = null;
Stack<Move> moveHistory; Stack<Move> moveHistory;
public boolean isGameOver; public boolean isGameOver;
public boolean isStalemate;
public boolean victor; public boolean victor;
Image youWin; Image youWin;
Image youLose; Image youLose;
Image stalemate;
public Board() { public Board() {
moveHistory = new Stack<>(); moveHistory = new Stack<>();
@ -41,6 +43,7 @@ public class Board {
panel = new DrawingPanel(DIMENSION, DIMENSION); panel = new DrawingPanel(DIMENSION, DIMENSION);
youWin = panel.loadImage("you-win.png"); youWin = panel.loadImage("you-win.png");
youLose = panel.loadImage("you-lose.png"); youLose = panel.loadImage("you-lose.png");
stalemate = panel.loadImage("stalemate.png");
graphics = panel.getGraphics(); graphics = panel.getGraphics();
// Connect up event handlers // Connect up event handlers
@ -160,6 +163,7 @@ public class Board {
void handleMouseDown(int x, int y) { void handleMouseDown(int x, int y) {
if (isGameOver) { if (isGameOver) {
isGameOver = false; isGameOver = false;
isStalemate = false;
setup(); setup();
return; return;
} }
@ -231,6 +235,9 @@ public class Board {
} }
undoMove(); undoMove();
} }
} else if (getAllLegalMoves(movedPiece.black).isEmpty()) {
isGameOver = true;
isStalemate = true;
} }
victor = movedPiece.black; victor = movedPiece.black;
} }
@ -284,7 +291,7 @@ public class Board {
// Draw game over text // Draw game over text
if (isGameOver) { if (isGameOver) {
graphics.drawImage(victor ? youLose : youWin, 0, 0, panel); graphics.drawImage(isStalemate ? stalemate : (victor ? youLose : youWin), 0, 0, panel);
} }
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

@ -0,0 +1,117 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
width="512mm"
height="512mm"
viewBox="0 0 512 512"
version="1.1"
id="svg5"
sodipodi:docname="stalemate.svg"
inkscape:export-filename="stalemate.png"
inkscape:export-xdpi="25.4"
inkscape:export-ydpi="25.4"
inkscape:version="1.2.2 (b0a8486541, 2022-12-01)"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<sodipodi:namedview
id="namedview7"
pagecolor="#ffffff"
bordercolor="#000000"
borderopacity="0.25"
inkscape:showpageshadow="2"
inkscape:pageopacity="0.0"
inkscape:pagecheckerboard="0"
inkscape:deskcolor="#d1d1d1"
inkscape:document-units="mm"
showgrid="false"
inkscape:zoom="0.3901936"
inkscape:cx="492.06342"
inkscape:cy="1009.7551"
inkscape:window-width="1920"
inkscape:window-height="1048"
inkscape:window-x="1920"
inkscape:window-y="32"
inkscape:window-maximized="1"
inkscape:current-layer="layer1" />
<defs
id="defs2">
<rect
x="380.73235"
y="551.6332"
width="1925.2562"
height="945.95678"
id="rect952" />
<filter
style="color-interpolation-filters:sRGB;"
inkscape:label="Drop Shadow"
id="filter1272"
x="-0.020339003"
y="0"
width="1.020339"
height="1.1324139">
<feFlood
flood-opacity="0.498039"
flood-color="rgb(0,0,0)"
result="flood"
id="feFlood1262" />
<feComposite
in="flood"
in2="SourceGraphic"
operator="in"
result="composite1"
id="feComposite1264" />
<feGaussianBlur
in="composite1"
stdDeviation="0"
result="blur"
id="feGaussianBlur1266" />
<feOffset
dx="-32"
dy="32"
result="offset"
id="feOffset1268" />
<feComposite
in="SourceGraphic"
in2="offset"
operator="over"
result="composite2"
id="feComposite1270" />
</filter>
</defs>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1">
<rect
style="fill:#333333;stroke-width:0.264583;fill-opacity:0.5"
id="rect111"
width="512"
height="512"
x="0"
y="0" />
<text
xml:space="preserve"
transform="matrix(0.26458333,0,0,0.26458333,-42.254641,69.177459)"
id="text950"
style="font-size:256px;white-space:pre;shape-inside:url(#rect952);display:inline;fill:#3d3d3d;fill-opacity:1;filter:url(#filter1272)"><tspan
x="380.73242"
y="782.22594"
id="tspan1879"><tspan
style="font-weight:bold;font-family:Arimo;-inkscape-font-specification:'Arimo Bold';fill:#ffffff"
id="tspan1877">STALEMATE</tspan></tspan></text>
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:33.8667px;font-family:Arimo;-inkscape-font-specification:'Arimo Bold';fill:#ffffff;fill-opacity:0.75;stroke-width:0.264583"
x="110.52037"
y="328.68213"
id="text1451"><tspan
sodipodi:role="line"
id="tspan1449"
style="font-size:33.8667px;fill:#ffffff;fill-opacity:0.75;stroke-width:0.264583"
x="110.52037"
y="328.68213">click to play again</tspan></text>
</g>
</svg>

After

Width:  |  Height:  |  Size: 3.5 KiB

@ -8,7 +8,7 @@
version="1.1" version="1.1"
id="svg5" id="svg5"
sodipodi:docname="you-lose.svg" sodipodi:docname="you-lose.svg"
inkscape:export-filename="you-win.png" inkscape:export-filename="you-lose.png"
inkscape:export-xdpi="25.4" inkscape:export-xdpi="25.4"
inkscape:export-ydpi="25.4" inkscape:export-ydpi="25.4"
inkscape:version="1.2.2 (b0a8486541, 2022-12-01)" inkscape:version="1.2.2 (b0a8486541, 2022-12-01)"
@ -28,8 +28,8 @@
inkscape:document-units="mm" inkscape:document-units="mm"
showgrid="false" showgrid="false"
inkscape:zoom="0.3901936" inkscape:zoom="0.3901936"
inkscape:cx="1232.7214" inkscape:cx="786.78891"
inkscape:cy="1014.8808" inkscape:cy="981.56402"
inkscape:window-width="1920" inkscape:window-width="1920"
inkscape:window-height="1048" inkscape:window-height="1048"
inkscape:window-x="1920" 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)"><tspan style="font-size:341.333px;white-space:pre;shape-inside:url(#rect952);display:inline;fill:#3d3d3d;fill-opacity:1;filter:url(#filter1272)"><tspan
x="380.73242" x="380.73242"
y="859.09003" y="859.09003"
id="tspan1803"><tspan id="tspan1823"><tspan
style="font-weight:bold;font-family:Arimo;-inkscape-font-specification:'Arimo Bold';fill:#ffffff" style="font-weight:bold;font-family:Arimo;-inkscape-font-specification:'Arimo Bold';fill:#ffffff"
id="tspan1801">YOU LOSE</tspan></tspan></text> id="tspan1821">YOU LOSE</tspan></tspan></text>
<text <text
xml:space="preserve" xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:33.8667px;font-family:Arimo;-inkscape-font-specification:'Arimo Bold';fill:#ffffff;fill-opacity:0.75;stroke-width:0.264583" style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:33.8667px;font-family:Arimo;-inkscape-font-specification:'Arimo Bold';fill:#ffffff;fill-opacity:0.75;stroke-width:0.264583"

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 3.5 KiB