Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. int maxmatches=21, index, indexPc, counter;
  2. String str= "Push 1, 2 or 3 to take matches from the pile";
  3. boolean pc;
  4.  
  5. void setup() {
  6. size(400, 200);
  7. }
  8.  
  9. void draw() {
  10. background(255);
  11.  
  12. drawMatches(25, 15, 40, 10, 15, 50);
  13.  
  14. textSize(15);
  15. fill(0);
  16. text(str, 25, 20);
  17. if (pc==false) {
  18. myTurn();
  19. } else {
  20. PcTurn();
  21. }
  22. }
  23.  
  24. //draw all remaining matches
  25. void drawMatches(int xPos, int space, int yPos, int w, int h, int hRect) {
  26. for (int i=0; i<maxmatches; i++) {
  27. fill(255, 0, 0);
  28. ellipseMode(CENTER);
  29. ellipse(xPos+i*space, yPos, w, h);
  30.  
  31. fill(#C9C314);
  32. rect(xPos-w/2+i*space, yPos+h/4, w, hRect);
  33. }
  34. }
  35.  
  36. void myTurn() {
  37.  
  38. text("You turn:", 25, 120);
  39. if (key>='0'&& key<='9') {
  40. if (key<='3') {
  41. index = key-48;
  42. text(index + "(press enter to continue)", 100, 120);
  43. } else {
  44. text ("Only 1,2 or 3 allowed! Try again!", 100, 120);
  45. }
  46. }
  47.  
  48. if (keyPressed) {
  49. if (key==ENTER && index>=0 && index<=3) {
  50. maxmatches-=index;
  51. index=5;
  52. pc=true;
  53. }
  54. }
  55. }
  56.  
  57. void PcTurn() {
  58. counter++;
  59. text("PC turn:", 25, 120);
  60. if (counter==0) {
  61. indexPc=(int)random(1, 4);
  62. }
  63. if (counter>=120) {
  64. text(indexPc + "(press enter to continue)", 100, 120);
  65. if (keyPressed) {
  66. if (key==ENTER) {
  67. counter=0;
  68. maxmatches-=indexPc;
  69. pc=false;
  70. }
  71. }
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement