Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- import java.awt.*;
- import java.applet.*;
- import java.awt.event.*;
- //I'm so sorry about how gross this looks. Problem is when playing the rectangles correlating to the left middle 3x3 aren't working properly. Rules are you play in the quadrant of the larger 3x3 as indicated by the where the last person played.
- public class Backup extends Applet implements MouseListener {
- Graphics buffer;
- Image img;
- protected int height, width;
- Rectangle[][] rectangles = new Rectangle[9][9];
- int[][] squarecheck = new int[9][9];
- //False = X, True = O
- boolean turn = false;
- boolean clicked = false;
- boolean tleft, tright, tmid, mright, mleft, bright, bmid, bleft;
- boolean mid = true;
- int x,y;
- public void init() {
- //0 = Empty
- //1 = X's
- //2 = O's
- for (int i = 0; i < 9; i++) {
- for (int j = 0; j < 9; j++) {
- squarecheck[i][j] = 0;
- }
- }
- addMouseListener(this);
- }
- // Turn Announcer
- public void paint(Graphics g) {
- height = getSize().height;
- width = getSize().width;
- if (turn == false) {
- g.setColor(Color.white);
- g.fillRect(0,0,80,9);
- g.setColor(Color.black);
- g.drawString("It is X's turn",0,9);
- } else {
- g.setColor(Color.white);
- g.fillRect(0,0,80,9);
- g.setColor(Color.black);
- g.drawString("It is O's turn",0,9);
- }
- // Makes Board
- for (int x = 0; x <= 8; x++) {
- for (int y = 0; y <= 8; y++) {
- if ((x == 3 && y == 0) ||(x==6 && y == 0) || (x==0 && y == 3) || (x==0 && y==6)) {
- g.setColor(Color.red);
- ((Graphics2D)g).setStroke(new BasicStroke(3.0f));
- g.drawLine(width/9*x,0,width/9*x,height);
- g.drawLine(0,height/9*y,width,height/9*y);
- } else {
- g.setColor(Color.black);
- ((Graphics2D)g).setStroke(new BasicStroke(1.0f));
- g.drawLine(width/9*x,0,width/9*x,height);
- g.drawLine(0,height/9*y,width,height/9*y);
- }
- }
- }
- // Makes Rectangle
- for (int x = 0; x <= 8; x++) {
- for (int y = 0; y <= 8; y++){
- if (x <= 2 && y <= 2 && tleft == true) {
- rectangles[x][y] = new Rectangle(width/9*x,height/9*y,width/9,height/9);
- } else if (y <= 2 && (x <= 5 && x >= 3) && tmid == true) {
- rectangles[x][y] = new Rectangle(width/9*x,height/9*y,width/9,height/9);
- } else if (y <= 2 && (x <= 8 && x >= 6) && tright == true) {
- rectangles[x][y] = new Rectangle(width/9*x,height/9*y,width/9,height/9);
- } else if ((y <= 5 && y >= 3) && (x <= 8 && x >= 6) && mright == true) {
- rectangles[x][y] = new Rectangle(width/9*x,height/9*y,width/9,height/9);
- } else if ((y <= 5 && y >= 3) && (x <= 5 && x >= 3) && mid == true) {
- rectangles[x][y] = new Rectangle(width/9*x,height/9*y,width/9,height/9);
- } else if ((y <= 5 && y >= 3) && (x <= 0 && x >= 2) && mleft == true) {
- rectangles[x][y] = new Rectangle(width/9*x,height/9*y,width/9,height/9);
- } else if ((y <= 8 && y >= 6) && (x <= 8 && x >= 6) && bright == true) {
- rectangles[x][y] = new Rectangle(width/9*x,height/9*y,width/9,height/9);
- } else if ((y <= 8 && y >= 6) && (x <= 5 && x >= 3) && bmid == true) {
- rectangles[x][y] = new Rectangle(width/9*x,height/9*y,width/9,height/9);
- } else if ((y <= 8 && y >= 6) && (x <= 2 && x >= 0) && bleft == true) {
- rectangles[x][y] = new Rectangle(width/9*x,height/9*y,width/9,height/9);
- } else {
- rectangles[x][y] = new Rectangle(-20,-20,1,1);
- }
- }
- }
- //Drawing X's and O's 2P
- /* if (clicked == true) {
- if (turn == true) {
- g.drawLine(x-width/36,y-height/36,x+width/36,y+height/36);
- g.drawLine(x-width/36,y+height/36,x+width/36,y-height/36);
- clicked = false;
- }
- if (turn == false) {
- g.drawOval(x-width/36,y-height/36,width/36*2,height/36*2);
- clicked = false;
- }
- }
- */
- //Drawing X's and O'x
- for (int x = 0; x < squarecheck.length; x++) {
- for (int y = 0; y < squarecheck[0].length; y++) {
- if (squarecheck[x][y] == 1) {
- g.drawLine(x*width/9+width/27,y*height/9+height/27,x*width/9+width*2/27,y*height/9+height*2/27);
- g.drawLine(x*width/9+width/27,y*height/9+height*2/27,x*width/9+width*2/27,y*height/9+height/27);
- }
- if (squarecheck[x][y] == 2) {
- g.drawOval(x*width/9+width/27,y*height/9+height/27,width/27,height/27);
- }
- }
- }
- repaint();
- }
- public void mousePressed(MouseEvent e) {
- }
- public void mouseReleased(MouseEvent e) {
- }
- public void mouseClicked(MouseEvent e) {
- x = e.getX();
- y = e.getY();
- clicked = true;
- for (int i = 0; i <= 8; i++) {
- for (int j = 0; j <= 8; j++) {
- if (rectangles[i][j].contains(x,y) && (j % 3 == 0 || j % 3 == 3) && (i % 3 == 3 || i % 3 == 0) && (squarecheck[i][j] == 0)) {
- tleft = true;
- tright = false;
- tmid = false;
- mright = false;
- mid = false;
- mleft = false;
- bright = false;
- bmid = false;
- bleft = false;
- }
- if (rectangles[i][j].contains(x,y) && (i % 3 == 1) && (j % 3 == 3 || j % 3 == 0) && (squarecheck[i][j] == 0)) {
- tleft = false;
- tmid = true;
- tright = false;
- mright = false;
- mid = false;
- mleft = false;
- bright = false;
- bmid = false;
- bleft = false;
- }
- if (rectangles[i][j].contains(x,y) && (i % 3 == 2) && (j % 3 == 3 || j % 3 == 0) && (squarecheck[i][j] == 0)) {
- tleft = false;
- tmid = false;
- tright = true;
- mright = false;
- mid = false;
- mleft = false;
- bright = false;
- bmid = false;
- bleft = false;
- }
- if (rectangles[i][j].contains(x,y) && (j % 3 == 1) && (i % 3 == 2) && (squarecheck[i][j] == 0)) {
- tleft = false;
- tright = false;
- tmid = false;
- mright = true;
- mid = false;
- mleft = false;
- bright = false;
- bmid = false;
- bleft = false;
- }
- if (rectangles[i][j].contains(x,y) && (j % 3 == 1) && (i % 3 == 1) && (squarecheck[i][j] == 0)) {
- tleft = false;
- tright = false;
- tmid = false;
- mid = true;
- mright = false;
- mleft = false;
- bright = false;
- bmid = false;
- bleft = false;
- }
- if (rectangles[i][j].contains(x,y) && (i % 3 == 3 || i % 3 == 0) && (j % 3 == 1) && (squarecheck[i][j] == 0)) {
- tleft = false;
- tright = false;
- tmid = false;
- mright = false;
- mid = false;
- mleft = true;
- bright = false;
- bmid = false;
- bleft = true;
- }
- if (rectangles[i][j].contains(x,y) && (j % 3 == 2) && (i % 3 == 2) && (squarecheck[i][j] == 0)) {
- tleft = false;
- tright = false;
- tmid = false;
- mright = false;
- mid = false;
- mleft = false;
- bright = true;
- bmid = false;
- bleft = false;
- }
- if (rectangles[i][j].contains(x,y) && (j % 3 == 2) && (i % 3 == 1) && (squarecheck[i][j] == 0)) {
- tleft = false;
- tright = false;
- tmid = false;
- mright = false;
- mid = false;
- mleft = false;
- bright = false;
- bmid = true;
- bleft = false;
- }
- if (rectangles[i][j].contains(x,y) && (i % 3 == 0 || i % 3 == 3) && (j % 3 == 2) && (squarecheck[i][j] == 0)) {
- tleft = false;
- tright = false;
- tmid = false;
- mright = false;
- mid = false;
- mleft = false;
- bright = false;
- bmid = false;
- bleft = true;
- }
- if (rectangles[i][j].contains(x,y) && (turn == false) && (squarecheck[i][j] == 0)) {
- squarecheck[i][j] = 1;
- turn = !turn;
- }
- if (rectangles[i][j].contains(x,y) && (turn == true) && (squarecheck[i][j] == 0)) {
- squarecheck[i][j] = 2;
- turn = !turn;
- }
- }
- }
- repaint();
- }
- public void mouseExited(MouseEvent e) {
- }
- public void mouseEntered(MouseEvent e) {
- }
- public void update(Graphics g) {
- paint(g);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement