Skip to content

Commit 442e955

Browse files
committed
Bug Fixes (tested server, client and bot)
1 parent b9bffb9 commit 442e955

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

game/src/spaghetti/game/Board.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public void addBoardListener(BoardListener l) {
6161

6262
public void removeBoardListener(BoardListener l) {
6363
listeners.remove(l);
64-
if (moveCount != 0 && (controllers[0] == l || controllers[1] == l)) close();
64+
if (currentState != BoardState.OVER && (controllers[0] == l || controllers[1] == l)) close();
6565
}
6666

6767
public void close() {

networking/client/src/spaghetti/networking/client/ServerConnection.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public void quit() {
5555
} catch (IOException e) {
5656
e.printStackTrace();
5757
}
58+
board.removeBoardListener(this);
5859
}
5960

6061
@Override

swing/src/spaghetti/gui/swing/GraphicalBoard.java

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,13 @@ public GraphicalBoard(SpaghettiInterface parent) {
3232
}
3333

3434
public void setBoard(Board board) {
35-
if (this.board != null) this.board.removeBoardListener(this);
35+
if (this.board != null) {
36+
this.board.removeBoardListener(this);
37+
for (BoardListener l : this.board.getBoardListeners())
38+
if (isChild(l)) {
39+
this.board.removeBoardListener(l);
40+
}
41+
}
3642
this.board = board;
3743
if (board != null) board.addBoardListener(this);
3844
}
@@ -156,11 +162,11 @@ public void paintComponent(Graphics g) {
156162
if (msg != null) {
157163
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
158164
g2.setColor(parent.colorPalette.get(8));
159-
g2.drawRect(0, 0, 100, 50);
165+
g2.fillRect(50, 50, 100, 30);
160166
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
161167
g2.setFont(font);
162168
g2.setColor(parent.colorPalette.get(0));
163-
g2.drawString(msg, 0, 0);
169+
g2.drawString(msg, 50, 50);
164170
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
165171
}
166172

@@ -357,14 +363,18 @@ public void close() {
357363
highlight = null;
358364
}
359365

366+
public boolean isChild(BoardListener l) {
367+
return l instanceof MouseInputBoardController &&
368+
((MouseInputBoardController)l).gb == this;
369+
}
370+
360371
public boolean isBoardRunning() {
361372
return board != null && board.getCurrentState() == BoardState.RUNNING;
362373
}
363374

364375
public boolean isControllerTurn() {
365376
return isBoardRunning() &&
366-
board.getControllerTurn() instanceof MouseInputBoardController &&
367-
((MouseInputBoardController)board.getControllerTurn()).gb == this;
377+
isChild(board.getControllerTurn());
368378
}
369379

370380
@Override
@@ -417,7 +427,11 @@ public void mouseDragged(MouseEvent e) {
417427

418428
@Override
419429
public void mouseMoved(MouseEvent e) {
420-
if (!isBoardRunning()) return;
430+
if (!isBoardRunning()) {
431+
sample = null;
432+
highlight = null;
433+
return;
434+
}
421435
if (inSample(e.getPoint())) {
422436
highlight = null;
423437
sampleHighlight = getTypeFromSample(e.getPoint());
@@ -444,8 +458,8 @@ public void enablePage(JFrame frame) {
444458
public void disablePage(JFrame frame) {
445459
frame.getContentPane().removeAll();
446460
removeKeyListener(this);
447-
close();
448461
parent.repaint();
462+
close();
449463
}
450464

451465
@Override
@@ -454,7 +468,9 @@ public void keyTyped(KeyEvent e) {
454468

455469
@Override
456470
public void keyPressed(KeyEvent e) {
457-
if (e.getKeyCode() == KeyEvent.VK_ESCAPE) parent.setPage(parent.getStartPage());
471+
if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
472+
parent.setPage(parent.getStartPage());
473+
}
458474
}
459475

460476
@Override

0 commit comments

Comments
 (0)