Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- stage {
- backdrop White("gallery:General/White")
- let matrix = [ ];
- let grid = 4;
- let pairs = 0;
- let flip = [];
- let closed = true;
- actor Robot {
- costume Idle("gallery:Figures/Robot Idle")
- function createMatrix(rows, cols) {
- matrix = [ ];
- for(let i = 0; i < rows; i++) {
- let list = [ ];
- for(let j = 0; j < cols; j++) {
- list.push(0);
- }
- matrix.push(list);
- }
- }
- function showMatrix(rows, cols) {
- let y = 120;
- for(let i = 0; i < rows; i++) {
- let x = -100;
- for(let j = 0; j < cols; j++) {
- let item = matrix[i][j];
- item.setPosition(x, y);
- item.show();
- x += 120;
- }
- y -= 80;
- }
- }
- function createClones(n) {
- for(let i = 1; i <= n; i++) {
- stage.createClone(Tiles);
- }
- }
- when stage.started {
- this.setPosition(-250,-100);
- this.createMatrix(grid, grid);
- this.createClones(grid * grid);
- this.show();
- this.say("Welcome to the MEMORY game! Find the pairs using the fewest attempts possible.");
- this.wait(2);
- this.say("");
- this.hide();
- this.mix();
- this.showMatrix(grid, grid);
- }
- function mix() {
- for(let k = 1; k <= 8; k++) {
- for(let l = 1; l <= 2; l++) {
- let item = Tiles;
- do {
- let i = Math.randomBetween(0, grid - 1);
- let j = Math.randomBetween(0, grid - 1);
- item = matrix[i][j];
- } while(item.cId != 0);
- item.cId = k;
- }
- }
- }
- }
- actor Ring {
- costume Red("gallery:Objects/Ring Red")
- costume Blue("gallery:Objects/Ring Blue")
- when stage.started{
- this.setPosition(-300, 150);
- this.setCostume(Red);
- pairs = 0;
- sayPairs();
- }
- function sayPairs() {
- this.say("Pairs: " + pairs);
- }
- }
- actor Tiles {
- costume Alap("gallery:Objects/Apple Idle")
- costume Banana("gallery:Objects/Banana Idle")
- costume Raspberry("gallery:Objects/Raspberry Idle")
- costume Orange("gallery:Objects/Orange Idle")
- costume Cheese("gallery:Objects/Cheese Whole")
- costume Donut_Lila("gallery:Objects/Donut Purple Whole")
- costume Donut_Red("gallery:Objects/Donut Red Whole")
- costume Cake("gallery:Objects/Logi Cake Full")
- costume Gift("gallery:Objects/Gift Red")
- let cId = 0;
- when stage.started {
- this.hide();
- this.setCostume(Gift);
- }
- when cloned {
- let id = this.cloneId - 1;
- let j = id % grid;
- let i = (id - j) / grid;
- matrix[i][j] = this;
- }
- when clicked {
- if(closed && costumeId == 9){
- closed = false;
- this.setCostume(cId);
- if (flip.length < 2){
- if(!flip[0]){
- flip[0] = this;
- }
- else{
- flip[1] = this;
- if(flip.length == 2) {
- if(flip[0].cId == flip[1].cId) {
- this.wait(0.5);
- for(let i = 1; i <= 8; i++) {
- flip[0].size -= 10;
- flip[1].size -= 10;
- this.wait(0.05);
- }
- flip[0].hide();
- flip[1].hide();
- pairs++;
- Ring.sayPairs();
- flip = [];
- }
- else{
- this.wait(0.5);
- flip[0].setCostume(9);
- flip[1].setCostume(9);
- flip = [];
- }
- }
- }
- closed = true;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement