Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.69 KB | None | 0 0
  1. stage {
  2. backdrop White("gallery:General/White")
  3. let matrix = [ ];
  4. let grid = 4;
  5. let pairs = 0;
  6. let flip = [];
  7. let closed = true;
  8.  
  9. actor Robot {
  10. costume Idle("gallery:Figures/Robot Idle")
  11. function createMatrix(rows, cols) {
  12. matrix = [ ];
  13. for(let i = 0; i < rows; i++) {
  14. let list = [ ];
  15. for(let j = 0; j < cols; j++) {
  16. list.push(0);
  17. }
  18. matrix.push(list);
  19. }
  20. }
  21. function showMatrix(rows, cols) {
  22. let y = 120;
  23. for(let i = 0; i < rows; i++) {
  24. let x = -100;
  25. for(let j = 0; j < cols; j++) {
  26. let item = matrix[i][j];
  27. item.setPosition(x, y);
  28. item.show();
  29. x += 120;
  30. }
  31. y -= 80;
  32. }
  33. }
  34. function createClones(n) {
  35. for(let i = 1; i <= n; i++) {
  36. stage.createClone(Tiles);
  37. }
  38. }
  39. when stage.started {
  40. this.setPosition(-250,-100);
  41. this.createMatrix(grid, grid);
  42. this.createClones(grid * grid);
  43. this.show();
  44. this.say("Welcome to the MEMORY game! Find the pairs using the fewest attempts possible.");
  45. this.wait(2);
  46. this.say("");
  47. this.hide();
  48. this.mix();
  49. this.showMatrix(grid, grid);
  50. }
  51. function mix() {
  52. for(let k = 1; k <= 8; k++) {
  53. for(let l = 1; l <= 2; l++) {
  54. let item = Tiles;
  55. do {
  56. let i = Math.randomBetween(0, grid - 1);
  57. let j = Math.randomBetween(0, grid - 1);
  58. item = matrix[i][j];
  59. } while(item.cId != 0);
  60. item.cId = k;
  61. }
  62. }
  63. }
  64. }
  65.  
  66. actor Ring {
  67. costume Red("gallery:Objects/Ring Red")
  68. costume Blue("gallery:Objects/Ring Blue")
  69. when stage.started{
  70. this.setPosition(-300, 150);
  71. this.setCostume(Red);
  72. pairs = 0;
  73. sayPairs();
  74. }
  75. function sayPairs() {
  76. this.say("Pairs: " + pairs);
  77. }
  78. }
  79.  
  80. actor Tiles {
  81. costume Alap("gallery:Objects/Apple Idle")
  82. costume Banana("gallery:Objects/Banana Idle")
  83. costume Raspberry("gallery:Objects/Raspberry Idle")
  84. costume Orange("gallery:Objects/Orange Idle")
  85. costume Cheese("gallery:Objects/Cheese Whole")
  86. costume Donut_Lila("gallery:Objects/Donut Purple Whole")
  87. costume Donut_Red("gallery:Objects/Donut Red Whole")
  88. costume Cake("gallery:Objects/Logi Cake Full")
  89. costume Gift("gallery:Objects/Gift Red")
  90. let cId = 0;
  91. when stage.started {
  92. this.hide();
  93. this.setCostume(Gift);
  94. }
  95. when cloned {
  96. let id = this.cloneId - 1;
  97. let j = id % grid;
  98. let i = (id - j) / grid;
  99. matrix[i][j] = this;
  100. }
  101. when clicked {
  102. if(closed && costumeId == 9){
  103. closed = false;
  104. this.setCostume(cId);
  105. if (flip.length < 2){
  106. if(!flip[0]){
  107. flip[0] = this;
  108. }
  109. else{
  110. flip[1] = this;
  111. if(flip.length == 2) {
  112. if(flip[0].cId == flip[1].cId) {
  113. this.wait(0.5);
  114. for(let i = 1; i <= 8; i++) {
  115. flip[0].size -= 10;
  116. flip[1].size -= 10;
  117. this.wait(0.05);
  118. }
  119. flip[0].hide();
  120. flip[1].hide();
  121. pairs++;
  122. Ring.sayPairs();
  123. flip = [];
  124. }
  125. else{
  126. this.wait(0.5);
  127. flip[0].setCostume(9);
  128. flip[1].setCostume(9);
  129. flip = [];
  130.  
  131. }
  132. }
  133. }
  134. closed = true;
  135. }
  136. }
  137. }
  138.  
  139. }
  140. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement