yes
This commit is contained in:
@@ -14,10 +14,12 @@ import javalib.worldimages.WorldImage;
|
|||||||
class Board {
|
class Board {
|
||||||
Map<Coord, Piece> board;
|
Map<Coord, Piece> board;
|
||||||
Map<Coord, Info> info;
|
Map<Coord, Info> info;
|
||||||
|
Game game;
|
||||||
|
|
||||||
Board() {
|
Board(Game game) {
|
||||||
this.board = new HashMap<Coord, Piece>();
|
this.board = new HashMap<Coord, Piece>();
|
||||||
this.info = new HashMap<Coord, Info>();
|
this.info = new HashMap<Coord, Info>();
|
||||||
|
this.game = game;
|
||||||
}
|
}
|
||||||
|
|
||||||
WorldScene draw() {
|
WorldScene draw() {
|
||||||
@@ -93,6 +95,7 @@ class Board {
|
|||||||
Piece piece = this.get(targ);
|
Piece piece = this.get(targ);
|
||||||
this.drop(targ);
|
this.drop(targ);
|
||||||
this.set(dest, piece);
|
this.set(dest, piece);
|
||||||
|
this.game.changeActive();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the valid moves for a piece.
|
// Get the valid moves for a piece.
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ class Game extends World {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Game() {
|
Game() {
|
||||||
this.board = new Board();
|
this.board = new Board(this);
|
||||||
this.white = new Player(Util.Col.WHITE, this.board);
|
this.white = new Player(Util.Col.WHITE, this.board);
|
||||||
this.black = new Player(Util.Col.BLACK, this.board);
|
this.black = new Player(Util.Col.BLACK, this.board);
|
||||||
this.activeActor = this.white;
|
this.activeActor = this.white;
|
||||||
@@ -116,4 +116,9 @@ class Game extends World {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onKeyEvent(String key) { this.activeActor.key(key); }
|
public void onKeyEvent(String key) { this.activeActor.key(key); }
|
||||||
|
|
||||||
|
void changeActive() {
|
||||||
|
if (this.activeActor.equals(this.white)) this.activeActor = this.black;
|
||||||
|
else this.activeActor = this.white;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+36
-22
@@ -9,36 +9,50 @@ class Player extends Actor {
|
|||||||
Player(Util.Col col, Board board) { super(col, board); }
|
Player(Util.Col col, Board board) { super(col, board); }
|
||||||
|
|
||||||
void click(Coord coord) {
|
void click(Coord coord) {
|
||||||
if (this.board.get(coord) == null) {
|
Piece piece = this.board.get(coord);
|
||||||
if (this.selected == null) return;
|
|
||||||
|
if (this.selected == null) {
|
||||||
|
if (piece == null) {
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
if (piece.col.equals(this.col)) {
|
||||||
|
System.out.println("clicked piece with nothing selected");
|
||||||
|
this.selected = coord;
|
||||||
|
this.board.displaySelected(coord);
|
||||||
|
this.board.displayMoves(coord);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
System.out.println(
|
||||||
|
"clicked other actor with nothing selected"
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
ArrayList<Coord> moves = this.board.getMoves(this.selected);
|
ArrayList<Coord> moves = this.board.getMoves(this.selected);
|
||||||
if (moves.contains(coord)) {
|
if (moves.contains(coord)) {
|
||||||
|
System.out.println(
|
||||||
|
"clicked on moveable space with something selected"
|
||||||
|
);
|
||||||
this.board.move(this.selected, coord);
|
this.board.move(this.selected, coord);
|
||||||
|
this.board.unselect(this.selected);
|
||||||
|
this.board.undisplayMoves(moves);
|
||||||
|
this.selected = null;
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
System.out.println(
|
||||||
|
"clicked on bad space with something selected"
|
||||||
|
);
|
||||||
|
this.board.undisplayMoves(moves);
|
||||||
|
this.board.unselect(coord);
|
||||||
|
this.selected = null;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
this.board.unselect(this.selected);
|
|
||||||
this.board.undisplayMoves(moves);
|
|
||||||
this.selected = null;
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Click while something selected.
|
|
||||||
if (this.selected != null) {
|
|
||||||
ArrayList<Coord> moves = this.board.getMoves(this.selected);
|
|
||||||
// Click on same piece -- unselect.
|
|
||||||
if (this.selected.equals(coord)) {}
|
|
||||||
this.board.unselect(this.selected);
|
|
||||||
this.board.undisplayMoves(moves);
|
|
||||||
this.selected = null;
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
this.selected = coord;
|
|
||||||
this.board.displaySelected(this.selected);
|
|
||||||
this.board.displayMoves(this.selected);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void key(String key) {
|
void key(String key) {
|
||||||
|
if (this.selected == null) return;
|
||||||
this.board.undisplayMoves(this.board.getMoves(this.selected));
|
this.board.undisplayMoves(this.board.getMoves(this.selected));
|
||||||
this.board.unselect(this.selected);
|
this.board.unselect(this.selected);
|
||||||
this.selected = null;
|
this.selected = null;
|
||||||
|
|||||||
Reference in New Issue
Block a user