Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // The "CPT" class.
- import java.awt.*;
- import hsa.Console;
- public class CPT
- {
- static Console c; // The output console
- public static void main (String[] args)
- {
- c = new Console (35, 207);
- int input = 0;
- int[] [] map = {{0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}};
- int row, col = 0;
- int x, colour = 0;
- int squares = 0;
- int p1num = 1;
- int p2num = 0;
- int xreturn = 0;
- int z = 1;
- String p1 = "";
- String p2 = "";
- c.setColor (new Color (0, 255, 255));
- c.fillRect (1, 1, 3000, 3000);
- c.setFont (new Font ("Lucida Calligraphy", Font.BOLD, 50));
- c.setColor (new Color (0, 153, 0));
- c.drawString ("Tic Tac Toe Game", 300, 250);
- c.setColor (new Color (204, 0, 204));
- c.drawString ("Please select an option", 300, 300);
- c.setColor (new Color (0, 153, 0));
- c.drawString ("For player vs player press '1'", 300, 350);
- c.setColor (new Color (204, 0, 204));
- c.drawString ("To view instructions press '2'", 300, 400);
- input = c.readInt ();
- if (input == 2)
- {
- c.setFont (new Font ("Arial", Font.BOLD, 20));
- 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);
- 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);
- 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);
- input = c.readInt ();
- }
- if (input == 1)
- {
- c.clear ();
- {
- c.setColor (new Color (0, 255, 255));
- c.fillRect (1, 1, 3000, 3000);
- c.setFont (new Font ("Lucida Calligraphy", Font.BOLD, 50));
- c.setColor (new Color (204, 0, 204));
- c.drawString ("Welcome to player vs player tic tac toe!", 200, 50);
- c.drawString ("Player 1, please select a name", 200, 100);
- c.setCursor (8, 30);
- p1 = c.readLine ();
- c.clear ();
- c.setColor (new Color (0, 255, 255));
- c.fillRect (1, 1, 3000, 3000);
- c.setColor (new Color (204, 0, 204));
- c.drawString ("Welcome Player 2, please select a name", 200, 100);
- c.setCursor (8, 30);
- p2 = c.readLine ();
- c.clear ();
- do
- {
- c.setFont (new Font ("Arial", Font.BOLD, 50));
- c.drawString ("0", 720, 120);
- c.drawString ("1", 820, 120);
- c.drawString ("2", 920, 120);
- c.drawString ("0", 620, 220);
- c.drawString ("1", 620, 320);
- c.drawString ("2", 620, 420);
- displayBoard (map);
- c.setCursor (25, 100);
- c.println (p1 + " please enter a row: ");
- c.setCursor (26, 110);
- row = c.readInt ();
- c.setCursor (25, 100);
- c.println (p1 + " please enter a column: ");
- c.setCursor (26, 110);
- col = c.readInt ();
- colour = 2;
- // z = z + 1;
- // if (z == 2)
- // {
- // c.setCursor (25, 100);
- // c.println (p2 + " please enter a row: ");
- // c.setCursor (26, 110);
- // row = c.readInt ();
- //
- // c.setCursor (25, 100);
- // c.println (p2 + " please enter a column: ");
- // c.setCursor (26, 110);
- // col = c.readInt ();
- // colour = 2;
- // z = z - 1;
- //
- // }
- if (p2num % 2 == 0)
- {
- colour = 1;
- }
- else
- {
- colour = 2;
- }
- p2num++;
- squares = squares + 1;
- if (squares == 9)
- {
- c.clear ();
- c.setFont (new Font ("DialogInput", Font.BOLD, 50));
- c.drawString ("GAME IS A TIE", 100, 250);
- break;
- }
- map [row] [col] = colour;
- displayBoard (map);
- xreturn = win (map);
- if (xreturn == 6)
- {
- c.println ("CONGRATS PLAYER 1. YOU ARE THE WINNER");
- }
- if (xreturn == 3)
- {
- c.println ("CONGRATS PLAYER 2. YOU ARE THE WINNER");
- }
- if (xreturn == 9)
- {
- c.println ("CONGRATS PLAYER 2. YOU ARE THE WINNER");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement