Can output in real-time, do not allow repeated lazi, have a judgment mechanism, use coordinates to play chess.
1 Packagewell word game;2 ImportJava.util.*;3 4 Public classMine {5 Public Static voidMain (string[] args) {6 Char[] Array = {{', ' ', ' '},{', ' ', '},{', ', '}};7Scanner input =NewScanner (system.in);8 intx, y;9 output (array);Ten for(inti=0;i<9;i++) { OneSystem.out.print ("Please enter the coordinates x and y of the pawn:"); A Do { -x=input.nextint (); -y=input.nextint (); the} while(x<1| | x>3| | y<1| | Y>3); -x--;y--; - if(array[x][y]!= ") { -SYSTEM.OUT.PRINTLN ("There are already pieces, please re-select!! "); + Do { -x=input.nextint (); +y=input.nextint (); A} while(x<1| | x>3| | y<1| | Y>3); atx--;y--; - } - if(i%2==0) -array[x][y]= ' x '; - Else -Array[x][y]= ' O '; in output (array); - Switch(judge (array)) { to Case1:system.out.println ("x" chess player has won!) "); i=9; Break; + Case2:system.out.println ("O" chess player has won!) "); i=9; Break; - } the if(i!=9) { * if(i%2==0) $System.out.print ("The Next step is" o "Pawn:");Panax Notoginseng Else -System.out.print ("The Next step is" X "Pieces:"); the } + } A } the Static voidOutputChar[] Array) { +System.out.println ("-------------"); -System.out.printf ("| %c | %c | %c |\n ", array[0][0],array[0][1],array[0][2]); $System.out.println ("-------------"); $System.out.printf ("| %c | %c | %c |\n ", array[1][0],array[1][1],array[1][2]); -System.out.println ("-------------"); -System.out.printf ("| %c | %c | %c |\n ", array[2][0],array[2][1],array[2][2]); theSystem.out.println ("-------------"); - }Wuyi Static intJudgeChar[] Array) { the for(inti=0;i<3;i++) { - if(array[i][0]==array[i][1]&&array[i][1]==array[i][2]&&array[i][2]== ' x ') Wu return1; - if(array[0][i]==array[1][i]&&array[1][i]==array[2][i]&&array[2][i]== ' x ') About return1; $ } - if(array[0][0]==array[1][1]&&array[1][1]==array[2][2]&&array[2][2]== ' x ') - return1; - if(array[0][2]==array[1][1]&&array[1][1]==array[2][0]&&array[2][0]== ' x ') A return1; + for(inti=0;i<3;i++) { the if(array[i][0]==array[i][1]&&array[i][1]==array[i][2]&&array[i][2]== ' O ') - return2; $ if(array[0][i]==array[1][i]&&array[1][i]==array[2][i]&&array[2][i]== ' O ') the return2; the } the if(array[0][0]==array[1][1]&&array[1][1]==array[2][2]&&array[2][2]== ' O ') the return2; - if(array[0][2]==array[1][1]&&array[1][1]==array[2][0]&&array[2][0]== ' O ') in return2; the return0; the } About the}
Games: Tic-tac-Hole games (Java)