Advertisement
sujonshekh

Simple Tic Tac Toe game

Jul 14th, 2016
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.33 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package tiktakto;
  7.  
  8. import java.util.Scanner;
  9.  
  10. /**
  11.  *
  12.  * @author Sharif
  13.  */
  14. public class Tiktakto {
  15.  
  16.     /**
  17.      * @param args the command line arguments
  18.      */
  19.     public static void main(String[] args) {
  20.         // TODO code application logic here
  21.         Scanner sc = new Scanner(System.in);
  22.         int moves = sc.nextInt();
  23.         int board[][] = new int[4][4];
  24.         for(int i=1; i<=moves; i++)
  25.         {
  26.             int row,col,symbol;
  27.             row= sc.nextInt();
  28.             col=sc.nextInt();
  29.             symbol= sc.nextInt();
  30.             board[row][col]=symbol;
  31.         }
  32.         System.out.println();
  33.         for(int i=1; i<=3;i++)
  34.         {
  35.             for(int j=1; j<=3; j++)
  36.                 System.out.print(board[i][j]+" ");
  37.             System.out.println("");
  38.         }  
  39.         if(board[1][1]==board[1][2]&&board[1][2]==board[1][3]&&(board[1][1]==1||board[1][1]==2))
  40.             result(board[1][1]);
  41.         else if(board[2][1]==board[2][2]&&board[2][2]==board[2][3]&&(board[2][1]==1||board[2][1]==2))
  42.             result(board[2][1]);
  43.         else if(board[3][1]==board[3][2]&&board[3][2]==board[3][3]&&(board[3][1]==1||board[3][1]==2))
  44.             result(board[3][1]);
  45.         else if(board[1][1]==board[2][1]&&board[2][1]==board[3][1]&&(board[1][1]==1||board[1][1]==2))
  46.             result(board[1][1]);
  47.         else if(board[1][2]==board[2][2]&&board[2][2]==board[3][2]&&(board[1][2]==1||board[1][2]==2))
  48.             result(board[1][2]);
  49.         else if(board[1][3]==board[2][3]&&board[2][3]==board[3][3]&&(board[1][3]==1||board[1][3]==2))
  50.             result(board[1][3]);
  51.         else if(board[1][1]==board[2][2]&&board[2][2]==board[3][3]&&(board[1][1]==1||board[1][1]==2))
  52.             result(board[1][1]);
  53.         else if(board[1][3]==board[2][2]&&board[2][2]==board[3][1]&&(board[1][3]==1||board[1][3]==2))
  54.             result(board[1][3]);
  55.         else
  56.             System.out.println("no one is win");
  57.        
  58.     }
  59.         static void result(int r)
  60.         {
  61.             if(r==1)
  62.             System.out.println("1 is win");
  63.             else if(r==2)
  64.             System.out.println("2 is win");
  65.         }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement