Esempio n. 1
0
 /**
  * This method reads computer input it takes TicTacData class as parameter.
  *
  * @param tdata
  */
 public void gameInput(TicTacData tdata) {
   if (tdata.getCOUNT() == ONE) {
     System.out.println(tdata.getCOUNT());
     array = tdata.getArray();
     random = new Random();
     array[random.nextInt(ROW - 1)][random.nextInt(COL - 1)] = C;
     tdata.setArray(array);
   } else {
     array = tdata.getArray();
     boolean check = false;
     check = rowCheck(tdata, array);
     if (check == false) {
       check = colCheck(tdata, array);
     }
     if (check == false) {
       check = diagonalsCheck(tdata, array);
     }
     if (check == false) {
       check = rowCheckAgain(tdata, array);
     }
     if (check == false) {
       check = colCheckAgain(tdata, array);
     }
     if (check == false) {
       check = diagonalsCheckAgain(tdata, array);
     }
   }
 }
Esempio n. 2
0
  /**
   * this method reads user input from console It takes TicTacData class parameter.
   *
   * @param tdata
   */
  public void userInput(TicTacData tdata) {
    array = tdata.getArray();
    Scanner scan = new Scanner(System.in);
    correct:
    for (int row = 0; row < ROW; row++) {
      String c = scan.next();
      for (int col = 0; col < COL; col++) {

        if (c.charAt(col) == O || c.charAt(col) == X || c.charAt(col) == C) {
          if (array[row][col] == C) {
            array[row][col] = C;
          } else if (array[row][col] == O) {
            array[row][col] = O;
          } else if (array[row][col] == X) {
            array[row][col] = c.charAt(col);
          }
        } else {
          System.out.println("WRONG INPUT");
          continue correct;
        }
      }
    }
    tdata.setArray(array);
  }