Games: Tic-tac-Hole games (Java)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.