Commit 633367f9 authored by kimia's avatar kimia

who's turn?

parent 9dfb84e8
......@@ -6,9 +6,10 @@ public class Main{
*@version 1.0
*@since 2019-5-7
*/
private static char boardChar[][] = new char [8][8] ;
private static void printBoard() {
private static void printBoard() {
for (int i=1 ; i<9 ; ++i) {
System.out.print(" " + i) ;
}
......@@ -28,7 +29,7 @@ private static void printBoard() {
}
}
private static void updateBoard(Piece pw[], Piece pb[]) {
private static void updateBoard(Piece pw[], Piece pb[]) {
for (int i=0 ; i<8 ; ++i) {
for (int j=0 ; j<8 ; ++j) {
boardChar[i][j] = ' ' ;
......@@ -54,7 +55,7 @@ private static void updateBoard(Piece pw[], Piece pb[]) {
}
}
private static void checkCondition(Cell board[][], Piece pw[], Piece pb[]) {
private static void checkCondition(Cell board[][], Piece pw[], Piece pb[]) {
for (Piece p:pw) {
if (p instanceof King) {
int sw1=0 ;
......@@ -79,7 +80,7 @@ private static void checkCondition(Cell board[][], Piece pw[], Piece pb[]) {
}
}
public static void main(String[] args) {
public static void main(String[] args) {
Scanner in = new Scanner(System.in) ;
Player white = new Player(Color.WHITE) ;
Player black = new Player(Color.BLACK) ;
......@@ -102,7 +103,8 @@ public static void main(String[] args) {
updateBoard(pw, pb) ;
printBoard() ;
while (true) {
wORb++ ;
if (wORb%2==0) System.out.println("White player turn") ;
else System.out.println("Black player turn") ;
String s = in.nextLine() ;
if (s.length()==2) {
for (Piece p:pw) {
......@@ -135,10 +137,12 @@ public static void main(String[] args) {
}
}
else if (s.length()==5) {
if (wORb%2==0) {
for (Piece p:pw) {
if (p.getCell().getRow()==s.charAt(0)-'a' &&
p.getCell().getCol()+1==s.charAt(1)-'0') {
if (p.isValidMove(new Cell(s.charAt(3)-'a', s.charAt(4)-'1'), board, pw, pb)) {
wORb++ ;
Cell tmp = new Cell(s.charAt(3)-'a', s.charAt(4)-'1') ;
board[p.getCell().getRow()][p.getCell().getCol()].setEmpty(true) ;
p.setCell(tmp) ;
......@@ -160,10 +164,19 @@ public static void main(String[] args) {
}
}
}
if (wORb%2==0) System.out.println("please enter a valid move!") ;
else {
checkCondition(board, pw, pb) ;
updateBoard(pw, pb) ;
printBoard() ;
}
}
else {
for (Piece p:pb) {
if (p.getCell().getRow()==s.charAt(0)-'a' &&
p.getCell().getCol()+1==s.charAt(1)-'0')
if (p.isValidMove(new Cell(s.charAt(3)-'a', s.charAt(4)-'1'), board, pw, pb) ) {
wORb++ ;
Cell tmp = new Cell(s.charAt(3)-'a', s.charAt(4)-'1') ;
board[p.getCell().getRow()][p.getCell().getCol()].setEmpty(true) ;
p.setCell(tmp) ;
......@@ -184,15 +197,19 @@ public static void main(String[] args) {
}
}
}
if (wORb%2==1) System.out.println("please enter a valid move!") ;
else {
checkCondition(board, pw, pb) ;
updateBoard(pw, pb) ;
printBoard() ;
}
}
}
else {
System.out.println("Please enter a valid input!") ;
}
}
}
}
}
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