From 28a072aff77f7b27badb6d38ff92b2c4aa66303e Mon Sep 17 00:00:00 2001 From: aah13002 Date: Mon, 28 Mar 2016 17:57:05 -0400 Subject: [PATCH] hasAttackVector supports both colors now --- src/model/Board.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/model/Board.java b/src/model/Board.java index b5480e6..abbe466 100755 --- a/src/model/Board.java +++ b/src/model/Board.java @@ -44,14 +44,18 @@ public boolean checkAttackDirection(Piece p, Direction X, Direction Y) { * Used for validation of moves. * If returns true after a player chooses a move, * that move is invalid because the player can keep on attacking. + * We go by the convention that black starts out at the "bottom", and + * red starts out at the "top". Smoke moves before fire. * @param p * @return */ public boolean hasAttackVector(Piece p) { boolean can_attack = false; - can_attack |= checkAttackDirection(p, Direction.UP, Direction.LEFT); - can_attack |= checkAttackDirection(p, Direction.UP, Direction.RIGHT); - if(p.getType().equals(Type.KING)) { + if (p.color.equals(Color.BLACK) || p.getType().equals(Type.KING)) { + can_attack |= checkAttackDirection(p, Direction.UP, Direction.LEFT); + can_attack |= checkAttackDirection(p, Direction.UP, Direction.RIGHT); + } + if (p.color.equals(Color.RED) || p.getType().equals(Type.KING)) { can_attack |= checkAttackDirection(p, Direction.DOWN, Direction.LEFT); can_attack |= checkAttackDirection(p, Direction.DOWN, Direction.RIGHT); }