Advertisement
Kuebjii

TicTacToe Java

Jan 4th, 2020
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.97 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.awt.*;
  4. import java.util.Random;
  5. import java.util.Scanner;
  6. /*
  7. 1 == O || This is the player
  8. 2 == X || This is the bot
  9. 0 == / || This means nothing is selected
  10.  
  11. */
  12.  
  13. class boxNumbers {
  14. int boxOne = 0;
  15. int boxTwo = 0;
  16. int boxThree = 0;
  17. int boxFour = 0;
  18. int boxFive = 0;
  19. int boxSixe = 0;
  20. int boxSeven = 0;
  21. int boxEight = 0;
  22. int boxNine = 0;
  23.  
  24. public int getBoxOne() {
  25. return boxOne;
  26. }
  27. public int getBoxTwo() {
  28. return boxTwo;
  29. }
  30.  
  31. public int getBoxThree() {
  32. return boxThree;
  33. }
  34.  
  35. public int getBoxFour() {
  36. return boxFour;
  37. }
  38.  
  39. public int getBoxFive() {
  40. return boxFive;
  41. }
  42.  
  43. public int getBoxSixe() {
  44. return boxSixe;
  45. }
  46.  
  47. public int getBoxSeven() {
  48. return boxSeven;
  49. }
  50.  
  51. public int getBoxEight() {
  52. return boxEight;
  53. }
  54.  
  55. public int getBoxNine() {
  56. return boxNine;
  57. }
  58. public int setBoxOne(int setBoxOne) {
  59. setBoxOne = boxOne;
  60. return setBoxOne;
  61. }
  62. public int setBoxTwo(int setBoxTwo) {
  63. setBoxTwo = boxTwo;
  64. return setBoxTwo;
  65. }
  66. public int setBoxThree(int setBoxThree) {
  67. setBoxThree = boxThree;
  68. return setBoxThree;
  69. }
  70. public int setBoxFour(int setBoxFour) {
  71. setBoxFour = boxFour;
  72. return boxFour;
  73. }
  74. public int setBoxFive(int setBoxFive) {
  75. setBoxFive = boxFive;
  76. return boxFive;
  77. }
  78. public int setBoxSix(int setBoxSix) {
  79. setBoxSix = boxSixe;
  80. return setBoxSix;
  81. }
  82. public int setBoxSeven(int setBoxSeven) {
  83. setBoxSeven = boxSeven;
  84. return setBoxSeven;
  85. }
  86. public int setBoxEight(int setBoxEight) {
  87. setBoxEight = boxEight;
  88. return setBoxEight;
  89. }
  90. public int setBoxNine(int setBoxNine) {
  91. setBoxNine = boxNine;
  92. return setBoxNine;
  93. }
  94. }
  95.  
  96.  
  97. public class Main {
  98.  
  99. public static void emptyBoard () {
  100. System.out.println(" | | ");
  101. System.out.println(" | | ");
  102. System.out.println(" | | ");
  103. System.out.println("___________________");
  104. System.out.println(" | | ");
  105. System.out.println(" | | ");
  106. System.out.println(" | | ");
  107. System.out.println("___________________");
  108. System.out.println(" | | ");
  109. System.out.println(" | | ");
  110. System.out.println(" | | ");
  111. }
  112.  
  113.  
  114. public static void main(String[] args) {
  115.  
  116. Scanner reader = new Scanner(System.in);
  117. System.out.println("Welcome to Tic-Tac-Toe");
  118. System.out.println("Please select your difficulty");
  119. System.out.println("Easy | Hard");
  120. String userDifficulty = reader.nextLine();
  121.  
  122. if (userDifficulty.equalsIgnoreCase("easy")) {
  123. System.out.println("Easy Mode Selected");
  124. easyMode();
  125. }
  126. if (userDifficulty.equalsIgnoreCase("hard")) {
  127. System.out.println("Hard Mode Selected");
  128. }
  129.  
  130. }
  131. public static void boxSelection() {
  132. Scanner reader = new Scanner(System.in);
  133. int boxSelection = reader.nextInt();
  134. boxNumbers box = new boxNumbers();
  135.  
  136. if (boxSelection == 1) {
  137. if (box.boxOne == 0){
  138. box.boxOne = 1;
  139. System.out.println(box.boxOne);
  140. return;
  141. }
  142. if (box.boxOne == 1){
  143. System.out.println("You already have that box!");
  144. boxSelection();
  145. }
  146. if (box.boxOne == 2) {
  147. System.out.println("That box is taken!");
  148. boxSelection();
  149. }
  150. }
  151. if (boxSelection == 2) {
  152. if (box.boxTwo == 0) {
  153. box.boxTwo = 1;
  154. System.out.println(box.boxTwo);
  155. return;
  156. }
  157. if (box.boxTwo == 1) {
  158. System.out.println("You already have this box!");
  159. boxSelection();
  160. }
  161. if (box.boxTwo == 2) {
  162. System.out.println("That box is already taken!");
  163. boxSelection();
  164.  
  165. }
  166. }
  167. }
  168.  
  169. public static void easyMode () {
  170.  
  171. //Boxes corresponding to numbers
  172. //If box = 1, that is X
  173. //If box = 2, that is O
  174. //If box = 0, that is no-one
  175. int boxOne = 0;
  176. int boxTwo = 0;
  177. int boxThree = 0;
  178. int boxFour = 0;
  179. int boxFive = 0;
  180. int boxSIx = 0;
  181. int boxSeven = 0;
  182. int boxEight = 0;
  183. int boxNine = 0;
  184.  
  185. Scanner reader = new Scanner(System.in);
  186. System.out.println("It's your turn, choose a number corresponding to a box on the board!");
  187. boxSelection();
  188.  
  189. }
  190. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement