From c57a0a80567c057ee613b6c2b97c50bec9715ab0 Mon Sep 17 00:00:00 2001 From: Jacob Signorovitch Date: Mon, 19 May 2025 08:26:54 -0400 Subject: [PATCH] almost --- chess/src/chess/Board.java | 3 +-- chess/src/chess/Player.java | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/chess/src/chess/Board.java b/chess/src/chess/Board.java index e5b3dfc..4d8b273 100644 --- a/chess/src/chess/Board.java +++ b/chess/src/chess/Board.java @@ -78,8 +78,7 @@ class Board { } // Clear moves from screen. - void undisplayMoves(Coord coord) { - ArrayList moves = this.get(coord).moves(coord); + void undisplayMoves(ArrayList moves) { for (Coord move : moves) this.info.remove(move); } diff --git a/chess/src/chess/Player.java b/chess/src/chess/Player.java index f74237c..a1a231b 100644 --- a/chess/src/chess/Player.java +++ b/chess/src/chess/Player.java @@ -10,22 +10,24 @@ class Player extends Actor { void click(Coord coord) { if (this.board.get(coord) == null) { + if (this.selected == null) return; + ArrayList moves = this.board.getMoves(this.selected); + if (moves.contains(coord)) { + this.board.move(this.selected, coord); + } this.board.unselect(this.selected); - this.board.undisplayMoves(this.selected); + this.board.undisplayMoves(moves); this.selected = null; return; }; // Click while something selected. if (this.selected != null) { - System.err.println("here"); + ArrayList moves = this.board.getMoves(this.selected); // Click on same piece -- unselect. - if (this.selected.equals(coord)) { - } else if (this.board.getMoves(this.selected).contains(coord)) { - this.board.move(this.selected, coord); - } + if (this.selected.equals(coord)) {} this.board.unselect(this.selected); - this.board.undisplayMoves(this.selected); + this.board.undisplayMoves(moves); this.selected = null; return; } else { @@ -37,7 +39,7 @@ class Player extends Actor { } void key(String key) { - this.board.undisplayMoves(this.selected); + this.board.undisplayMoves(this.board.getMoves(this.selected)); this.board.unselect(this.selected); this.selected = null; }