Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. public class TicTacToeDemo
  2. {
  3. public static char[][] board = new char[3][3];
  4.  
  5. public static void main(String[] args)
  6. {
  7. TicTacToe.newGame();
  8.  
  9. for (int i = 0; i < 9; i++)
  10. {
  11. if ((i == 0) || (i == 2) || (i == 4) || (i == 6) || (i == 8))
  12. {
  13. if (TicTacToe.winner() == false) //if there is not a winner
  14. {
  15. TicTacToe.writeBoard(); //print board to screen
  16. TicTacToe.getMoveX(); //get move from player X
  17. }
  18. }
  19. else
  20. {
  21. TicTacToe.writeBoard(); //print board to screen
  22. TicTacToe.getMoveO(); //get move from player O
  23. }
  24. }
  25.  
  26. for (int j = 0; j < 3; j++)
  27. {
  28. /*checks to see if the board is full*/
  29. if ((board[j][0] == board[j][1]) && (board[j][0] == board[j][2]))
  30. {
  31. if (board[j][0] == '\0') /*if the board is full...*/
  32. System.out.println("IT IS A DRAW!"); //there is no winner
  33. TicTacToe.writeBoard(); //print final board
  34. System.exit(0);
  35. }
  36. }
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement