Advertisement
Guest User

Untitled

a guest
Apr 25th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. Board myBoard;
  2. //Cell myCell;
  3.  
  4. void setup() {
  5. size(400, 400);
  6. //myCell = new Cell(0, 0, width, height);
  7. myBoard = new Board();
  8. }
  9.  
  10. void draw() {
  11. background(0);
  12. //myCell.click();
  13. //myCell.display();
  14. myBoard.check();
  15. myBoard.display();
  16. }
  17.  
  18. class Board {
  19. Cell[][] board;
  20. turn = 1;
  21.  
  22. Board() {
  23. for (int i = 0; i < 3; i++) {
  24. for (int j = 0; j < 3; j++) {
  25. board[i][j] = new Cell(); // you do this
  26. }
  27. }
  28. }
  29.  
  30. void check() {
  31. } //check for a winner
  32.  
  33. void display() {
  34. for (int i = 0; i < 3; i++) {
  35. for (int j = 0; j < 3; j++) {
  36. board[i][j].click();
  37. board[i][j].display();
  38. }
  39. }
  40. }
  41. }
  42.  
  43. class Cell {
  44. float x, y;
  45. float w, h;
  46. int state = 0; //always starts blank
  47.  
  48. // Cell Constructor
  49. Cell(float tempX, float tempY, float tempW, float tempH) {
  50. x = tempX;
  51. y = tempY;
  52. w = tempW;
  53. h = tempH;
  54. }
  55.  
  56. void click() {
  57. if (state==0) {
  58. if (mouseX > x && mouseX < x+w &&
  59. mouseY > y && mouseY < y+h && mousePressed) {
  60. mousePressed = false;
  61. state = 1;
  62. }
  63. }
  64. }
  65.  
  66. void display() {
  67. fill(255);
  68. rect(x, y, w, h);
  69. if (state == 1) { //draw an X
  70. line(x, y, x+w, y+h);
  71. line(x, y+h, x+w, y);
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement