Advertisement
Dar954826

Tic-tac-toe[ENG].java

Feb 18th, 2015
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.13 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class TicTacToe {
  3.     private static Scanner dd;
  4.  
  5.     public static void Trispl(String[] args) {
  6.         dd = new Scanner(System.in);
  7.         String a,s,d,f,g,h,j,k,l,symbol1,symbol2;
  8.        
  9.         while(true){
  10.         System.out.print("Insert player 1 symbol: ");
  11.         symbol1=new String(dd.next());
  12.         if(symbol1.length()==1){break;}
  13.         System.out.println("1 character.");
  14.         }
  15.         while(true){
  16.             System.out.print("Insert player 1 symbol: ");
  17.             symbol2=new String(dd.next());
  18.             if(symbol2.length()==1){break;}
  19.             System.out.println("1 character.");
  20.         }
  21.         int sel;
  22.         a=s=d=f=g=h=j=k=l=" ";
  23.         while(true){
  24.         System.out.println("7|8|9       "+j+"|"+k+"|"+l);
  25.         System.out.println("-----       -----");
  26.         System.out.println("4|5|6       "+f+"|"+g+"|"+h);
  27.         System.out.println("-----       -----");
  28.         System.out.println("1|2|3       "+a+"|"+s+"|"+d);
  29.         while(true){
  30.         System.out.print("Where insert player 1 symbol: ");
  31.         sel=dd.nextInt();
  32.         if(sel==1 & a==" "){a=symbol1;break;}
  33.         else if(sel==2 & s==" "){s=symbol1;break;}
  34.         else if(sel==3 & d==" "){d=symbol1;break;}
  35.         else if(sel==4 & f==" "){f=symbol1;break;}
  36.         else if(sel==5 & g==" "){g=symbol1;break;}
  37.         else if(sel==6 & h==" "){h=symbol1;break;}
  38.         else if(sel==7 & j==" "){j=symbol1;break;}
  39.         else if(sel==8 & k==" "){k=symbol1;break;}
  40.         else if(sel==9 & l==" "){l=symbol1;break;}
  41.         else{System.out.println("Can not insert the symbol.");}
  42.         }
  43.         if(a==symbol1&s==symbol1&d==symbol1){}
  44.         else if(f==symbol1&g==symbol1&h==symbol1){System.out.println("Player 1 won!");break;}
  45.         else if(j==symbol1&k==symbol1&l==symbol1){System.out.println("Player 1 won!");break;}
  46.         else if(j==symbol1&f==symbol1&a==symbol1){System.out.println("Player 1 won!");break;}
  47.         else if(k==symbol1&g==symbol1&s==symbol1){System.out.println("Player 1 won!");break;}
  48.         else if(l==symbol1&h==symbol1&d==symbol1){System.out.println("Player 1 won!");break;}
  49.         else if(j==symbol1&g==symbol1&d==symbol1){System.out.println("Player 1 won!");break;}
  50.         else if(l==symbol1&g==symbol1&a==symbol1){System.out.println("Player 1 won!");break;}
  51.         else if(a!=" "&s!=" "&d!=" "&f!=" "&g!=" "&h!=" "&j!=" "&k!=" "&l!=" "){System.out.println("The two players have drawn!");break;}
  52.         System.out.println("7|8|9       "+j+"|"+k+"|"+l);
  53.         System.out.println("-----       -----");
  54.         System.out.println("4|5|6       "+f+"|"+g+"|"+h);
  55.         System.out.println("-----       -----");
  56.         System.out.println("1|2|3       "+a+"|"+s+"|"+d);
  57.         while(true){
  58.             System.out.print("Where insert player 2 symbol: ");
  59.             sel=dd.nextInt();
  60.             if(sel==1 & a==" "){a=symbol2;break;}
  61.             else if(sel==2 & s==" "){s=symbol2;break;}
  62.             else if(sel==3 & d==" "){d=symbol2;break;}
  63.             else if(sel==4 & f==" "){f=symbol2;break;}
  64.             else if(sel==5 & g==" "){g=symbol2;break;}
  65.             else if(sel==6 & h==" "){h=symbol2;break;}
  66.             else if(sel==7 & j==" "){j=symbol2;break;}
  67.             else if(sel==8 & k==" "){k=symbol2;break;}
  68.             else if(sel==9 & l==" "){l=symbol2;break;}
  69.             else{System.out.println("Can not insert the symbol.");}
  70.             }
  71.         if(a==symbol2&s==symbol2&d==symbol2){System.out.println("Player 2 won!");dd.next();break;}
  72.         else if(f==symbol2&g==symbol2&h==symbol2){System.out.println("Player 2 won!");break;}
  73.         else if(j==symbol2&k==symbol2&l==symbol2){System.out.println("Player 2 won!");break;}
  74.         else if(j==symbol2&f==symbol2&a==symbol2){System.out.println("Player 2 won!");break;}
  75.         else if(k==symbol2&g==symbol2&s==symbol2){System.out.println("Player 2 won!");break;}
  76.         else if(l==symbol2&h==symbol2&d==symbol2){System.out.println("Player 2 won!");break;}
  77.         else if(j==symbol2&g==symbol2&d==symbol2){System.out.println("Player 2 won!");break;}
  78.         else if(l==symbol2&g==symbol2&a==symbol2){System.out.println("Player 2 won!");break;}
  79.         else if(a!=" "&s!=" "&d!=" "&f!=" "&g!=" "&h!=" "&j!=" "&k!=" "&l!=" "){System.out.println("The two players have drawn!");break;}
  80.         }
  81.         System.out.println(j+"|"+k+"|"+l);
  82.         System.out.println("-----");
  83.         System.out.println(f+"|"+g+"|"+h);
  84.         System.out.println("-----");
  85.         System.out.println(a+"|"+s+"|"+d);
  86.         dd.nextLine();
  87.         dd.nextLine();
  88.        
  89.         int b=0;
  90.         while(b!=1000){System.out.println();b++;}
  91.     }
  92.  
  93.     public static void main(String[] args) {
  94.         while(true){Trispl(args);}
  95.     }
  96.  
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement