Advertisement
Guest User

fuck this shit

a guest
Nov 28th, 2014
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.74 KB | None | 0 0
  1. class tile
  2. {
  3. int Xmin;
  4. int Xmax;
  5. int Ymin;
  6. int Ymax;
  7.  
  8. int type;
  9.  
  10. boolean flipped;
  11.  
  12. boolean paired;
  13.  
  14. tile(int xmin, int xmax, int ymin, int ymax)
  15. {
  16. Xmin = xmin;
  17. Xmax = xmax;
  18. Ymin = ymin;
  19. Ymax = ymax;
  20. }
  21.  
  22. void setType(int t)
  23. {
  24. type = t;
  25. }
  26.  
  27. void changeFlip()
  28. {
  29. flipped = !flipped;
  30. }
  31.  
  32. void flipReset()
  33. {
  34. flipped = false;
  35. }
  36.  
  37.  
  38. void pair()
  39. {
  40. paired = true;
  41. }
  42. }
  43.  
  44. int numTiles = 4*3; //width * height to get how many tiles
  45.  
  46. int flipCounter = 0;
  47.  
  48. tile[] tiles = new tile[numTiles];
  49.  
  50. PImage[] types;
  51.  
  52.  
  53. void setup()
  54. {
  55. size(500, 500);
  56.  
  57. initTiles(4, 3);
  58. }
  59.  
  60. void draw()
  61. {
  62. background(255); //redraw the background
  63.  
  64. PImage[] types = { //types, in images
  65. loadImage("circle.png"), loadImage("square.png"), loadImage("spiral.png"), loadImage("heart.png"), loadImage("x.png"), loadImage("checker.png")
  66. };
  67.  
  68. drawTiles(4, 3, types); //draw all the tiles every time
  69. }
  70.  
  71. void initTiles(int w, int h)
  72. {
  73. int squareW = width/w, squareH = height/h; //calculate the square width and set the square height
  74. int squareX = 0, squareY = 0; //X starts at 0, Y stays at 0
  75.  
  76. int i = 0;
  77. while (i < numTiles)
  78. {
  79. tiles[i] = new tile(squareX, (squareX) + (squareW), squareY, (squareY) + (squareH)); //give the object its location
  80.  
  81. squareX += squareW; //move the X coordinate over by one box width
  82.  
  83. if (squareX+squareW > width)
  84. {
  85. squareY += squareH;
  86. squareX = 0;
  87. }
  88.  
  89. i++;
  90. }
  91.  
  92. //predetermined pattern
  93. tiles[0].setType(1);
  94. tiles[1].setType(3);
  95. tiles[2].setType(0);
  96. tiles[3].setType(2);
  97. tiles[4].setType(4);
  98. tiles[5].setType(5);
  99. tiles[6].setType(0);
  100. tiles[7].setType(1);
  101. tiles[8].setType(2);
  102. tiles[9].setType(3);
  103. tiles[10].setType(4);
  104. tiles[11].setType(5);
  105. }
  106.  
  107. void drawTiles(int w, int h, PImage[] type)
  108. {
  109.  
  110. int squareW = width/w, squareH = height/h; //calculate the square width and set the square height
  111. int squareX = 0, squareY = 0; //X starts at 0, Y stays at 0
  112. int i = 0; //counting variables
  113.  
  114. while (i < w*h)
  115. {
  116.  
  117.  
  118. if (!tiles[i].flipped) //if they are not flipped, make red
  119. {
  120. fill(255, 0, 0);
  121. rect(tiles[i].Xmin, tiles[i].Ymin, squareW, squareH);
  122. } else //if flipped, draw their type on the card
  123. {
  124. fill(255);
  125. rect(tiles[i].Xmin, tiles[i].Ymin, squareW, squareH);
  126.  
  127. image(type[tiles[i].type], tiles[i].Xmin+1, tiles[i].Ymin+1 );
  128. }
  129.  
  130. i++;
  131. }
  132. }
  133.  
  134.  
  135. void mouseClicked()
  136. {
  137. int j = 0;
  138.  
  139. while (j < numTiles)
  140. {
  141. if ( ((mouseX > tiles[j].Xmin && mouseX < tiles[j].Xmax) && (mouseY > tiles[j].Ymin && mouseY < tiles[j].Ymax)) && !tiles[j].flipped ) //check where they clicked and flip that card if it isn't already flipped
  142. {
  143. tiles[j].changeFlip();
  144.  
  145.  
  146. flipCounter++;
  147.  
  148. if (flipCounter > 2) //flip them back over if you exceed 2 cards at a time
  149. {
  150. for (int i = 0; i < numTiles; i++)
  151. {
  152. if (!tiles[i].paired) //flip all the unpaired ones back over
  153. {
  154. tiles[i].flipReset();
  155. }
  156. }
  157.  
  158. flipCounter = 1; //continue and flip the one they wanted to flip and set the counter apropriately
  159. tiles[j].changeFlip(); //flip the next one without wait
  160. }
  161. }
  162.  
  163. j++;
  164. }
  165.  
  166. //this SHOULD check all tiles against each other and see if they're flipped and not paired and the same type
  167. /*for (int i = 0; i < numTiles; i++)
  168. {
  169. for (int k = 0; k < numTiles; k++)
  170. {
  171. if (tiles[i].type == tiles[k].type && !tiles[i].paired && !tiles[k].paired && tiles[i].flipped && tiles[k].flipped)
  172. {
  173. tiles[i].pair();
  174. tiles[k].pair();
  175. }
  176. }
  177. }*/
  178. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement