weinerwad3000

Untitled

Apr 3rd, 2014
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.37 KB | None | 0 0
  1. package gameZone;
  2.  
  3. import javax.swing.JOptionPane;
  4.  
  5. public class TicTacToe {
  6.  
  7. public static void main(String[] args) {
  8. // TODO Auto-generated method stub
  9.  
  10. char ttt[][] = {{'0','1','2',
  11. '3','4','5',
  12. '6','7','8'}};
  13.  
  14. int uC;
  15. boolean win = false;
  16. boolean lose = false;
  17. int b = 0;
  18. int compChoice = 100;
  19. int end = 0;
  20.  
  21. while(win == false && lose == false && b <= 9 && end != 999)
  22. {
  23. do
  24. {
  25. compChoice = (int)(Math.random() * 9);
  26. }
  27. while(ttt[0][compChoice] == 'O' || ttt[0][compChoice] == 'X');
  28. uC = Integer.parseInt(JOptionPane.showInputDialog(null, ttt[0][0] + "," + ttt[0][1] + "," + ttt[0][2] + "\n" +
  29. ttt[0][3] + "," + ttt[0][4] + "," + ttt[0][5] + "\n" +
  30. ttt[0][6] + "," + ttt[0][7] + "," + ttt[0][8] + "\nPlease enter "
  31. + "a number where you want to place an X."));
  32. b = b + 1;
  33. if(b <= 8)
  34. {
  35. compChoice = (int)(Math.random() * 9);
  36. b = b + 1;
  37. }
  38.  
  39. while(ttt[0][uC] == 'X' || ttt[0][uC] == 'O')
  40. {
  41. uC = Integer.parseInt(JOptionPane.showInputDialog(null, ttt[0][0] + "," + ttt[0][1] + "," + ttt[0][2] + "\n" +
  42. ttt[0][3] + "," + ttt[0][4] + "," + ttt[0][5] + "\n" +
  43. ttt[0][6] + "," + ttt[0][7] + "," + ttt[0][8] + "\nPlease choose another location"));
  44. }
  45. ttt[0][uC] = 'X';
  46. ttt[0][compChoice] = 'O';
  47.  
  48. if(ttt[0][0] == 'X' && ttt[0][1] =='X' && ttt[0][2] == 'X' ||
  49. ttt[0][3] == 'X' && ttt[0][4] =='X' && ttt[0][5] == 'X' ||
  50. ttt[0][6] == 'X' && ttt[0][7] =='X' && ttt[0][8] == 'X' ||
  51. ttt[0][0] == 'X' && ttt[0][3] =='X' && ttt[0][6] == 'X' ||
  52. ttt[0][1] == 'X' && ttt[0][4] =='X' && ttt[0][7] == 'X' ||
  53. ttt[0][2] == 'X' && ttt[0][5] =='X' && ttt[0][8] == 'X' ||
  54. ttt[0][0] == 'X' && ttt[0][4] =='X' && ttt[0][8] == 'X' ||
  55. ttt[0][2] == 'X' && ttt[0][4] =='X' && ttt[0][6] == 'X')
  56. {
  57. win = true;
  58. JOptionPane.showMessageDialog(null, ttt[0][0] + "," + ttt[0][1] + "," + ttt[0][2] + "\n" +
  59. ttt[0][3] + "," + ttt[0][4] + "," + ttt[0][5] + "\n" +
  60. ttt[0][6] + "," + ttt[0][7] + "," + ttt[0][8] + "\nYou Win!");
  61.  
  62. }
  63. if(ttt[0][0] == 'O' && ttt[0][1] =='O' && ttt[0][2] == 'O' ||
  64. ttt[0][3] == 'O' && ttt[0][4] =='O' && ttt[0][5] == 'O' ||
  65. ttt[0][6] == 'O' && ttt[0][7] =='O' && ttt[0][8] == 'O' ||
  66. ttt[0][0] == 'O' && ttt[0][3] =='O' && ttt[0][6] == 'O' ||
  67. ttt[0][1] == 'O' && ttt[0][4] =='O' && ttt[0][7] == 'O' ||
  68. ttt[0][2] == 'O' && ttt[0][5] =='O' && ttt[0][8] == 'O' ||
  69. ttt[0][0] == 'O' && ttt[0][4] =='O' && ttt[0][8] == 'O' ||
  70. ttt[0][2] == 'O' && ttt[0][4] =='O' && ttt[0][6] == 'O')
  71. {
  72. lose = true;
  73. JOptionPane.showMessageDialog(null, ttt[0][0] + "," + ttt[0][1] + "," + ttt[0][2] + "\n" +
  74. ttt[0][3] + "," + ttt[0][4] + "," + ttt[0][5] + "\n" +
  75. ttt[0][6] + "," + ttt[0][7] + "," + ttt[0][8] + "\nYou lose. :(");
  76. }
  77. if(b == 9 && win == false && lose == false)
  78. {
  79. JOptionPane.showMessageDialog(null, ttt[0][0] + "," + ttt[0][1] + "," + ttt[0][2] + "\n" +
  80. ttt[0][3] + "," + ttt[0][4] + "," + ttt[0][5] + "\n" +
  81. ttt[0][6] + "," + ttt[0][7] + "," + ttt[0][8] + "\nYou tied. :/");
  82. end = 999;
  83. }
  84.  
  85. }
  86.  
  87.  
  88.  
  89. }
  90.  
  91. }
Add Comment
Please, Sign In to add comment