Commit 2632294b authored by hamed's avatar hamed

king movement bug fixed & console interaction improved

parent 25e80531
...@@ -13,6 +13,8 @@ public class Main { ...@@ -13,6 +13,8 @@ public class Main {
// } // }
// System.out.println(b); // System.out.println(b);
boolean whichMove = true; boolean whichMove = true;
boolean isBlackPrintBoard = false;
boolean isWhitePrintBoard = false;
while (true){ while (true){
if(whichMove) { if(whichMove) {
System.out.println("White Turn.... insert a move in a line"); System.out.println("White Turn.... insert a move in a line");
...@@ -35,13 +37,16 @@ public class Main { ...@@ -35,13 +37,16 @@ public class Main {
if (b.getMove(x, y, dx, dy)) { if (b.getMove(x, y, dx, dy)) {
System.out.println(splt[0]+" Moved to "+splt[1]); System.out.println(splt[0]+" Moved to "+splt[1]);
whichMove = false; whichMove = false;
isWhitePrintBoard = true;
} else { } else {
System.out.println("Incorrect Move, Please insert Correct Movement"); System.out.println("Incorrect Move, Please insert Correct Movement");
} }
} }
} }
if(!whichMove) if(isWhitePrintBoard) {
System.out.println(b); System.out.println(b);
isWhitePrintBoard = false;
}
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
if(whichMove) continue; if(whichMove) continue;
System.out.println("Black Turn.... insert a move in a line"); System.out.println("Black Turn.... insert a move in a line");
...@@ -64,12 +69,15 @@ public class Main { ...@@ -64,12 +69,15 @@ public class Main {
if(b.getMove(x,y,dx,dy)){ if(b.getMove(x,y,dx,dy)){
System.out.println(splt[0]+" Moved to "+splt[1]); System.out.println(splt[0]+" Moved to "+splt[1]);
whichMove = true; whichMove = true;
isBlackPrintBoard=true;
}else { }else {
System.out.println("Incorrect Move, Please insert Correct Movement"); System.out.println("Incorrect Move, Please insert Correct Movement");
} }
} }
if(whichMove) if(isBlackPrintBoard) {
System.out.println(b); System.out.println(b);
isBlackPrintBoard = false;
}
} }
} }
public static void printMoves(ArrayList<int[]> moves){ public static void printMoves(ArrayList<int[]> moves){
......
...@@ -47,7 +47,7 @@ public class King extends Piece { ...@@ -47,7 +47,7 @@ public class King extends Piece {
for (int i = 0 ; i < 8 ; i++){ for (int i = 0 ; i < 8 ; i++){
for(int j =0 ; j < 8 ; j++){ for(int j =0 ; j < 8 ; j++){
Piece p = getBoard().getBoard()[i][j]; Piece p = getBoard().getBoard()[i][j];
if(p!=null && (p.isWhite()!=isWhite())){ if(p!=null && !(p instanceof King) &&((p.isWhite()&& isBlack()) ||(p.isBlack() && isWhite()))){
ArrayList<int[]> moves = p.moves(); ArrayList<int[]> moves = p.moves();
for(int m[] : moves){ for(int m[] : moves){
Cell c = new Cell(m[0],m[1]); Cell c = new Cell(m[0],m[1]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment