Advertisement
whiftz

Untitled

Jan 16th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.51 KB | None | 0 0
  1. // The "CPT" class.
  2. import java.awt.*;
  3. import hsa.Console;
  4.  
  5. public class CPT
  6. {
  7. static Console c; // The output console
  8.  
  9. public static void main (String[] args)
  10. {
  11. c = new Console (35, 207);
  12.  
  13. int input = 0;
  14. int[] [] map = {{0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}};
  15. int row, col = 0;
  16. int x, colour = 0;
  17. int squares = 0;
  18. int p1num = 1;
  19. int p2num = 0;
  20. int xreturn = 0;
  21. int z = 1;
  22. String p1 = "";
  23. String p2 = "";
  24. c.setColor (new Color (0, 255, 255));
  25. c.fillRect (1, 1, 3000, 3000);
  26. c.setFont (new Font ("Lucida Calligraphy", Font.BOLD, 50));
  27. c.setColor (new Color (0, 153, 0));
  28. c.drawString ("Tic Tac Toe Game", 300, 250);
  29. c.setColor (new Color (204, 0, 204));
  30. c.drawString ("Please select an option", 300, 300);
  31. c.setColor (new Color (0, 153, 0));
  32. c.drawString ("For player vs player press '1'", 300, 350);
  33. c.setColor (new Color (204, 0, 204));
  34. c.drawString ("To view instructions press '2'", 300, 400);
  35. input = c.readInt ();
  36. if (input == 2)
  37. {
  38. c.setFont (new Font ("Arial", Font.BOLD, 20));
  39. c.drawString ("The object of Tic Tac Toe is to get three in a row. You play on a three by three game board. The first player is known as X and the second is O.", 200, 450);
  40. c.drawString ("Players alternate placing X's and O's on the game board until either opponent has three in a row or all nine squares are filled. X always goes first", 200, 500);
  41. c.drawString ("and in the event that no one has three in a row, the stalemate is called a tied game. X will be 1 and O will be 2. If you want to go play game press 1 ", 200, 550);
  42. input = c.readInt ();
  43. }
  44.  
  45. if (input == 1)
  46. {
  47. c.clear ();
  48. {
  49. c.setColor (new Color (0, 255, 255));
  50. c.fillRect (1, 1, 3000, 3000);
  51.  
  52. c.setFont (new Font ("Lucida Calligraphy", Font.BOLD, 50));
  53. c.setColor (new Color (204, 0, 204));
  54. c.drawString ("Welcome to player vs player tic tac toe!", 200, 50);
  55. c.drawString ("Player 1, please select a name", 200, 100);
  56. c.setCursor (8, 30);
  57. p1 = c.readLine ();
  58. c.clear ();
  59. c.setColor (new Color (0, 255, 255));
  60. c.fillRect (1, 1, 3000, 3000);
  61. c.setColor (new Color (204, 0, 204));
  62. c.drawString ("Welcome Player 2, please select a name", 200, 100);
  63. c.setCursor (8, 30);
  64. p2 = c.readLine ();
  65. c.clear ();
  66.  
  67.  
  68. do
  69. {
  70. c.setFont (new Font ("Arial", Font.BOLD, 50));
  71. c.drawString ("0", 720, 120);
  72. c.drawString ("1", 820, 120);
  73. c.drawString ("2", 920, 120);
  74. c.drawString ("0", 620, 220);
  75. c.drawString ("1", 620, 320);
  76. c.drawString ("2", 620, 420);
  77. displayBoard (map);
  78. c.setCursor (25, 100);
  79. c.println (p1 + " please enter a row: ");
  80. c.setCursor (26, 110);
  81. row = c.readInt ();
  82.  
  83. c.setCursor (25, 100);
  84. c.println (p1 + " please enter a column: ");
  85. c.setCursor (26, 110);
  86. col = c.readInt ();
  87. colour = 2;
  88. // z = z + 1;
  89. // if (z == 2)
  90. // {
  91. // c.setCursor (25, 100);
  92. // c.println (p2 + " please enter a row: ");
  93. // c.setCursor (26, 110);
  94. // row = c.readInt ();
  95. //
  96. // c.setCursor (25, 100);
  97. // c.println (p2 + " please enter a column: ");
  98. // c.setCursor (26, 110);
  99. // col = c.readInt ();
  100. // colour = 2;
  101. // z = z - 1;
  102. //
  103. // }
  104.  
  105.  
  106.  
  107.  
  108. if (p2num % 2 == 0)
  109. {
  110. colour = 1;
  111. }
  112. else
  113. {
  114. colour = 2;
  115. }
  116. p2num++;
  117. squares = squares + 1;
  118. if (squares == 9)
  119. {
  120. c.clear ();
  121. c.setFont (new Font ("DialogInput", Font.BOLD, 50));
  122. c.drawString ("GAME IS A TIE", 100, 250);
  123. break;
  124. }
  125. map [row] [col] = colour;
  126. displayBoard (map);
  127. xreturn = win (map);
  128. if (xreturn == 6)
  129. {
  130. c.println ("CONGRATS PLAYER 1. YOU ARE THE WINNER");
  131. }
  132. if (xreturn == 3)
  133. {
  134. c.println ("CONGRATS PLAYER 2. YOU ARE THE WINNER");
  135. }
  136. if (xreturn == 9)
  137. {
  138. c.println ("CONGRATS PLAYER 2. YOU ARE THE WINNER");
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement