Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Board myBoard;
- //Cell myCell;
- void setup() {
- size(400, 400);
- //myCell = new Cell(0, 0, width, height);
- myBoard = new Board();
- }
- void draw() {
- background(0);
- //myCell.click();
- //myCell.display();
- myBoard.check();
- myBoard.display();
- }
- class Board {
- Cell[][] board;
- turn = 1;
- Board() {
- for (int i = 0; i < 3; i++) {
- for (int j = 0; j < 3; j++) {
- board[i][j] = new Cell(); // you do this
- }
- }
- }
- void check() {
- } //check for a winner
- void display() {
- for (int i = 0; i < 3; i++) {
- for (int j = 0; j < 3; j++) {
- board[i][j].click();
- board[i][j].display();
- }
- }
- }
- }
- class Cell {
- float x, y;
- float w, h;
- int state = 0; //always starts blank
- // Cell Constructor
- Cell(float tempX, float tempY, float tempW, float tempH) {
- x = tempX;
- y = tempY;
- w = tempW;
- h = tempH;
- }
- void click() {
- if (state==0) {
- if (mouseX > x && mouseX < x+w &&
- mouseY > y && mouseY < y+h && mousePressed) {
- mousePressed = false;
- state = 1;
- }
- }
- }
- void display() {
- fill(255);
- rect(x, y, w, h);
- if (state == 1) { //draw an X
- line(x, y, x+w, y+h);
- line(x, y+h, x+w, y);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement