Browse Source

player can no longer select n/n on the last activiy | name field can't be left empty | a couple of changes in code organization

lairaalmas 6 years ago
parent
commit
6680e78c15
9 changed files with 522 additions and 457 deletions
  1. 3 1
      assets/languages/en_US.json
  2. 3 1
      assets/languages/es_PE.json
  3. 3 1
      assets/languages/fr_FR.json
  4. 3 1
      assets/languages/pt_BR.json
  5. 106 89
      js/boot.js
  6. 112 109
      js/circleOne.js
  7. 3 1
      js/menu.js
  8. 134 131
      js/squareOne.js
  9. 155 123
      js/squareTwo.js

+ 3 - 1
assets/languages/en_US.json

@@ -19,5 +19,7 @@
     "without_name": "WITHOUT",
     "insert_name" : "ENTER YOUR NAME",
     "ready" : "READY",
-    "welcome" : "Welcome"
+    "welcome" : "Welcome",
+    "error_msg" :  "You should select a smaller portion than it's full size",
+    "empty_name" : "You forgot to type your name"
 }

+ 3 - 1
assets/languages/es_PE.json

@@ -19,5 +19,7 @@
     "without_name": "SIN",
     "insert_name" : "INGRESA TU NOMBRE",
     "ready" : "LISTO",
-    "welcome" : "Bienvenido"
+    "welcome" : "Bienvenid@",
+    "error_msg" : "Debes seleccionar una porción más pequeña que su tamaño completo",
+    "empty_name" : "Usted ha olvidado de escribir su nombre"
 }

+ 3 - 1
assets/languages/fr_FR.json

@@ -19,5 +19,7 @@
     "without_name": "SANS",
     "insert_name" : "ENTREZ VOTRE NOM",
     "ready" : "PRET",
-    "welcome" : "Bienvenue"
+    "welcome" : "Bienvenue",
+    "error_msg" : "Vous devriez choisir une portion plus petite que sa taille totale",
+    "empty_name" : "Vous avez oublié de taper votre nom"
 }

+ 3 - 1
assets/languages/pt_BR.json

@@ -19,5 +19,7 @@
     "without_name": "SEM",
     "insert_name" : "DIGITE SEU NOME",
     "ready" : "PRONTO",
-    "welcome" : "Bem vindo"
+    "welcome" : "Bem vind@",
+    "error_msg" : "Você deve selecionar uma porção menor que o seu tamanho total",
+    "empty_name" : "Você esqueceu de digitar seu nome"
 }

+ 106 - 89
js/boot.js

@@ -1,39 +1,113 @@
-
-var username;
+var username, errorEmptyName, words;
 
 /*
     var bootState = {
         preload: function(){},
         create: function(){},
+        --------------------------------------- end of phaser functions
         setLang: function(){} //calls loadState
     };
     
     var loadState = {
         preload: function(){},
         create: function(){} //calls nameState
+        -------------------------------------- end of phaser functions
     };
         
     var nameState = {
         preload: function(){},
         create: function(){},
-        clearName: function(){},
-        keyPressed: function( char ){},
+        ------------------------------------------------ end of phaser functions
         ready: function(){} //calls menu.js -> menuState
     };
 */
 
 // choose language screen
 var bootState = {
-    
+
+    //Loading all assets   
     preload: function() {
+        
+        var imgsrc = 'assets/img/';
+
         //Progress bar image
-        game.load.image('progressBar', 'assets/img/pgbar.png');
+        game.load.image('progressBar', imgsrc+'pgbar.png');
+
+        //flags
+        game.load.image('flag_BR', imgsrc+'flag/BRAZ.jpg');
+        game.load.image('flag_PE', imgsrc+'flag/PERU.jpg');
+        game.load.image('flag_US', imgsrc+'flag/UNST.jpg');
+        game.load.image('flag_FR', imgsrc+'flag/FRAN.jpg');
 
-        //loading flags (manually)
-        game.load.image('flag_BR', 'assets/img/flag/BRAZ.jpg');
-        game.load.image('flag_PE', 'assets/img/flag/PERU.jpg');
-        game.load.image('flag_US', 'assets/img/flag/UNST.jpg');
-        game.load.image('flag_FR', 'assets/img/flag/FRAN.jpg');
+        //scenario
+        game.load.image('bgimage', imgsrc+'bg.jpg');
+        game.load.image('bgmap', imgsrc+'bg_map.png');
+        game.load.image('cloud', imgsrc+'cloud.png');
+        game.load.image('floor', imgsrc+'floor.png');
+        game.load.image('road', imgsrc+'road.png');
+        
+        //game phases buttons list
+        game.load.image('game1c', imgsrc+'game/one-c.png');
+        game.load.image('game2c', imgsrc+'game/two-c.png');
+        game.load.image('game3c', imgsrc+'game/three-c.png');
+        game.load.image('game4c', imgsrc+'game/four-c.png');
+        game.load.image('game1s', imgsrc+'game/one-s.png');
+        game.load.image('game2s', imgsrc+'game/two-s.png');
+        game.load.image('game3s', imgsrc+'game/three-s.png');
+        game.load.image('game4s', imgsrc+'game/four-s.png');
+        game.load.image('game5s', imgsrc+'game/five-s.png');
+        
+        //header menu buttons
+        game.load.image('back', imgsrc+'menu/back.png');
+        game.load.image('home', imgsrc+'menu/home.png');
+        game.load.image('info', imgsrc+'menu/info.png');
+        game.load.image('world', imgsrc+'menu/language.png');
+        game.load.image('list', imgsrc+'menu/menu.png');
+        game.load.image('help', imgsrc+'menu/help.png');
+        game.load.image('pgbar', imgsrc+'menu/progressBar.png');
+        game.load.image('block', imgsrc+'menu/block.png');
+        game.load.image('eraser', imgsrc+'menu/eraser.png');
+        
+        //operators
+        game.load.image('add', imgsrc+'operator/add.png');
+        game.load.image('subtract', imgsrc+'operator/subtract.png');
+        game.load.image('separator', imgsrc+'operator/separator.png');
+        game.load.image('equal', imgsrc+'operator/equal.png');
+        
+        //feedback
+        game.load.image('h_arrow', imgsrc+'help/arrow.png');
+        game.load.image('h_double', imgsrc+'help/double.png');
+        game.load.image('h_error', imgsrc+'help/error.png');
+        game.load.image('h_ok', imgsrc+'help/ok.png');
+        game.load.image('down', imgsrc+'help/down.png');        
+        game.load.image('pointer', imgsrc+'help/pointer.png');
+        
+        // Loading assets based on language        
+        game.load.spritesheet('kid_run', imgsrc+'kid/run.png', 82, 178, 12);
+        game.load.spritesheet('kid_walk', imgsrc+'kid/walk.png', 78, 175, 24);
+        game.load.spritesheet('kid_lost', imgsrc+'kid/lost.png', 72, 170, 6);
+        game.load.spritesheet('tractor', imgsrc+'tractor/frame.png', 201, 144, 10);
+        game.load.image('balloon', imgsrc+'airballoon_upper.png');
+        game.load.image('balloon_basket', imgsrc+'airballoon_base.png');
+        game.load.image('birch', imgsrc+'birch.png');
+        game.load.image('flag', imgsrc+'flag.png');
+        game.load.image('house', imgsrc+'house.png');
+        game.load.image('place_a', imgsrc+'place_a.png');
+        game.load.image('place_b', imgsrc+'place_b.png');
+        game.load.image('garage', imgsrc+'garage.png');
+        game.load.image('farm', imgsrc+'farm.png');
+        game.load.image('rock', imgsrc+'rock.png');
+        game.load.image('school', imgsrc+'school.png');
+        game.load.image('sign', imgsrc+'sign.png');
+        game.load.image('tree1', imgsrc+'tree.png');
+        game.load.image('tree2', imgsrc+'tree2.png');
+        game.load.image('tree3', imgsrc+'tree3.png');
+        game.load.image('tree4', imgsrc+'tree4.png');
+        
+        // Loadind Sound Effects
+        game.load.audio('sound_ok', ['assets/fx/ok.ogg', 'assets/fx/ok.mp3']);
+        game.load.audio('sound_error', ['assets/fx/error.ogg', 'assets/fx/error.mp3']);
+        game.load.audio('sound_beep', ['assets/fx/beep.ogg', 'assets/fx/beep.mp3']);
     },
 
     create: function() {
@@ -109,75 +183,6 @@ var loadState = {
         
         // Loading dictionary
         game.load.json('dictionary', 'assets/languages/'+lang+'.json');
-                
-        // Loading global assets (sprites and images)
-        var imgsrc = 'assets/img/';
-        
-        game.load.image('bgimage', imgsrc+'bg.jpg');
-        game.load.image('bgmap', imgsrc+'bg_map.png');
-        game.load.image('cloud', imgsrc+'cloud.png');
-        game.load.image('floor', imgsrc+'floor.png');
-        game.load.image('road', imgsrc+'road.png');
-        
-         //games list buttons
-        game.load.image('game1c', imgsrc+'game/one-c.png');
-		game.load.image('game2c', imgsrc+'game/two-c.png');
-		game.load.image('game3c', imgsrc+'game/three-c.png');
-		game.load.image('game4c', imgsrc+'game/four-c.png');
-        game.load.image('game1s', imgsrc+'game/one-s.png');
-		game.load.image('game2s', imgsrc+'game/two-s.png');
-		game.load.image('game3s', imgsrc+'game/three-s.png');
-		game.load.image('game4s', imgsrc+'game/four-s.png');
-		game.load.image('game5s', imgsrc+'game/five-s.png');
-         //header menu
-        game.load.image('back', imgsrc+'menu/back.png');
-        game.load.image('home', imgsrc+'menu/home.png');
-        game.load.image('info', imgsrc+'menu/info.png');
-        game.load.image('world', imgsrc+'menu/language.png');
-        game.load.image('list', imgsrc+'menu/menu.png');
-        game.load.image('help', imgsrc+'menu/help.png');
-        game.load.image('pgbar', imgsrc+'menu/progressBar.png');
-        game.load.image('block', imgsrc+'menu/block.png');
-        game.load.image('eraser', imgsrc+'menu/eraser.png');
-         //operators
-		game.load.image('add', imgsrc+'operator/add.png');
-		game.load.image('subtract', imgsrc+'operator/subtract.png');
-		game.load.image('separator', imgsrc+'operator/separator.png');
-		game.load.image('equal', imgsrc+'operator/equal.png');
-         //helpers
-		game.load.image('h_arrow', imgsrc+'help/arrow.png');
-		game.load.image('h_double', imgsrc+'help/double.png');
-		game.load.image('h_error', imgsrc+'help/error.png');
-		game.load.image('h_ok', imgsrc+'help/ok.png');
-        game.load.image('down', imgsrc+'help/down.png');        
-        game.load.image('pointer', imgsrc+'help/pointer.png');
-        
-        // Loading assets based on lang        
-        game.load.spritesheet('kid_run', imgsrc+'kid/run.png', 82, 178, 12);
-        game.load.spritesheet('kid_walk', imgsrc+'kid/walk.png', 78, 175, 24);
-        game.load.spritesheet('kid_lost', imgsrc+'kid/lost.png', 72, 170, 6);
-        game.load.spritesheet('tractor', imgsrc+'tractor/frame.png', 201, 144, 10);
-        game.load.image('balloon', imgsrc+'airballoon_upper.png');
-        game.load.image('balloon_basket', imgsrc+'airballoon_base.png');
-        game.load.image('birch', imgsrc+'birch.png');
-        game.load.image('flag', imgsrc+'flag.png');
-        game.load.image('house', imgsrc+'house.png');
-        game.load.image('place_a', imgsrc+'place_a.png');
-        game.load.image('place_b', imgsrc+'place_b.png');
-        game.load.image('garage', imgsrc+'garage.png');
-        game.load.image('farm', imgsrc+'farm.png');
-        game.load.image('rock', imgsrc+'rock.png');
-        game.load.image('school', imgsrc+'school.png');
-        game.load.image('sign', imgsrc+'sign.png');
-        game.load.image('tree1', imgsrc+'tree.png');
-        game.load.image('tree2', imgsrc+'tree2.png');
-        game.load.image('tree3', imgsrc+'tree3.png');
-        game.load.image('tree4', imgsrc+'tree4.png');
-        
-        // Loadind Sound Effects
-        game.load.audio('sound_ok', ['assets/fx/ok.ogg', 'assets/fx/ok.mp3']);
-        game.load.audio('sound_error', ['assets/fx/error.ogg', 'assets/fx/error.mp3']);
-        game.load.audio('sound_beep', ['assets/fx/beep.ogg', 'assets/fx/beep.mp3']);
         
     },
 
@@ -190,13 +195,14 @@ var loadState = {
 var nameState = {
 
     preload: function () {
+        
     },
 
     create: function() {
         game.stage.backgroundColor = '#cce5ff';
         
         // gets selected language from json
-        var words =  game.cache.getJSON('dictionary');
+        words = game.cache.getJSON('dictionary');
         
         game.physics.startSystem(Phaser.Physics.ARCADE);
         
@@ -217,30 +223,41 @@ var nameState = {
         
         btn.inputEnabled = true;
         btn.input.useHandCursor = true;
-        btn.events.onInputDown.add(this.ready, null);
+        btn.events.onInputDown.add(this.nameIsEmpty, null);
         
         var ready = game.add.text(this.game.world.centerX + 1, this.game.world.centerY + 102, words.ready, { font: '34px Arial', fill: '#f0f5f5', align: 'center' });
-        ready.anchor.setTo(0.5);  
-        
+        ready.anchor.setTo(0.5);
+
+        errorEmptyName = game.add.text(this.game.world.centerX, this.game.world.centerY - 70, "", {font: '18px Arial', fill: '#330000', align: 'center'});
+        errorEmptyName.anchor.setTo(0.5);
+
         document.getElementById("text-field-div").style.visibility = "visible";
-        
         document.getElementById("name_id").addEventListener('keypress', function(e){
             var keycode = e.keycode ? e.keycode : e.which; 
             //se apertar enter vai para ready, assim como o botão
-            if(keycode == 13){ 
-                nameState["ready"]();
+            if(keycode == 13){
+                nameState["nameIsEmpty"]();
             }     
         });
     },
          
+    nameIsEmpty: function() {
+        if(document.getElementById("name_id").value!=""){
+            nameState["ready"]();
+            errorEmptyName.setText("");
+        }else{
+            errorEmptyName.setText(words.empty_name);
+        }
+
+    },
+
     //var ready = function readyFunction() {...},
     //var ready = function() {...},                
     ready: function() {
-
         
         // saves the typed name on username variable
         username = document.getElementById("name_id").value;
-        console.log("user is " + username);        
+        console.log("user is" + username);        
 
         document.getElementById("text-field-div").style.visibility = "hidden";
 

+ 112 - 109
js/circleOne.js

@@ -17,17 +17,19 @@
 
     var gameCircleOne = {
         create: function(){},
+        update: function(){},
+        ---------------------------- end of phaser functions
         updateCounter: function(){},
         overCircle: function(){},
         outCircle: function(){},
         clickCircle: function(){},
         setPlace: function(){},
         postScore: function(){},
-        update: function(){},
         showOption: function(){},
         loadState: function(){},
         viewHelp: function(){},
         checkOverlap: function(){}
+            //getRndDivisor: function(){}
     };
 
     var endCircleOne = {
@@ -438,6 +440,7 @@ var okImg, errorImg;
 var detail;
 
 var gameCircleOne = {
+
     create: function() {
         
         //timer
@@ -714,114 +717,6 @@ var gameCircleOne = {
         errorImg.alpha = 0;
     },
     
-    updateCounter: function() {
-        totalTime++;
-    },
-        
-    overCircle: function(){
-        
-        if(!clicked){
-            for(var i=0;i<numBlocks;i++){
-                if(i<=this.indice){
-                    blocks.children[i].alpha = 1;
-                }else{
-                    blocks.children[i].alpha = 0.5;
-                }
-            }
-        }
-
-    },
-
-    outCircle: function(){
-        if(!clicked){
-            for(var i=0;i<=this.indice;i++){
-                blocks.children[i].alpha = 0.5;
-            }
-        }
-    },
-    
-    clickCircle: function(){
-        if(!clicked){
-            var minusBlocks = 0;
-            
-            for(var i=0;i<numBlocks;i++){
-                if(i<=this.indice){
-                    fractionIndex = this.indice;
-                    blocks.children[i].alpha = 1;
-                }else{
-                    blocks.children[i].visible = false; //Delete unselected block
-                    minusBlocks +=1; //number of blocks to reduce
-                    kid_walk.y += blockSize; //Lowering kid
-                }
-            }
-            
-            numBlocks -= minusBlocks; //Final reduced blocks
-
-            balloon.alpha = 1;
-            clicked = true;
-            animate = true;
-            beepSound.play();
-            if(blockDirection[curBlock]=='Right'){
-                kid_walk.animations.play('right', 6, true);
-            }else{
-                kid_walk.animations.play('left', 6, true);
-            }
-
-            if(oneLabel){ //Hiding labels
-                blockLabel.visible = false;
-                blockSeparator.visible = false;
-            }
-        }
-    },
-
-    setPlace: function(){
-        if(!clicked){
-            
-            balloon.x = game.input.x;
-            basket.x = game.input.x;
-
-            balloon.alpha = 1;
-            clicked = true;
-            animate = true;
-            beepSound.play();
-            if(blockDirection[curBlock]=='Right'){
-                kid_walk.animations.play('right', 6, true);
-            }else{
-                kid_walk.animations.play('left', 6, true);
-            }
-
-            if(oneLabel){ //Hiding labels
-                blockLabel.visible = false;
-                blockSeparator.visible = false;
-            }
-        }
-    },
-
-    postScore: function (){
-        
-        var abst = "numCircles:"+numBlocks+", valCircles: " + detail+" balloonX: " + basket.x + ", selIndex: " + fractionIndex;
-        
-        var hr = new XMLHttpRequest();
-        // Create some variables we need to send to our PHP file
-        var url = "assets/cn/save.php";
-        var vars = "s_ip="+hip+"&s_name="+name+"&s_lang="+lang+"&s_game="+oneShape+"&s_mode="+oneType;
-        vars += "&s_oper="+oneOperator+"&s_leve="+oneDifficulty+"&s_posi="+onePosition+"&s_resu="+result+"&s_time="+totalTime+"&s_deta="+abst;
-        
-        hr.open("POST", url, true);
-        hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
-        hr.onreadystatechange = function() {
-            console.log(hr);
-
-            if(hr.readyState == 4 && hr.status == 200) {
-                var return_data = hr.responseText;
-                console.log(return_data);
-            }
-        }
-        // Send the data to PHP now... and wait for response to update the status div
-        hr.send(vars); // Actually execute the request
-        console.log("processing...");
-    },
-        
     update: function() {
        
         if (game.input.activePointer.isDown && !fly && !clicked){
@@ -970,6 +865,114 @@ var gameCircleOne = {
             }
         }
     },
+
+    updateCounter: function() {
+        totalTime++;
+    },
+        
+    overCircle: function(){
+        
+        if(!clicked){
+            for(var i=0;i<numBlocks;i++){
+                if(i<=this.indice){
+                    blocks.children[i].alpha = 1;
+                }else{
+                    blocks.children[i].alpha = 0.5;
+                }
+            }
+        }
+
+    },
+
+    outCircle: function(){
+        if(!clicked){
+            for(var i=0;i<=this.indice;i++){
+                blocks.children[i].alpha = 0.5;
+            }
+        }
+    },
+    
+    clickCircle: function(){
+        if(!clicked){
+            var minusBlocks = 0;
+            
+            for(var i=0;i<numBlocks;i++){
+                if(i<=this.indice){
+                    fractionIndex = this.indice;
+                    blocks.children[i].alpha = 1;
+                }else{
+                    blocks.children[i].visible = false; //Delete unselected block
+                    minusBlocks +=1; //number of blocks to reduce
+                    kid_walk.y += blockSize; //Lowering kid
+                }
+            }
+            
+            numBlocks -= minusBlocks; //Final reduced blocks
+
+            balloon.alpha = 1;
+            clicked = true;
+            animate = true;
+            beepSound.play();
+            if(blockDirection[curBlock]=='Right'){
+                kid_walk.animations.play('right', 6, true);
+            }else{
+                kid_walk.animations.play('left', 6, true);
+            }
+
+            if(oneLabel){ //Hiding labels
+                blockLabel.visible = false;
+                blockSeparator.visible = false;
+            }
+        }
+    },
+
+    setPlace: function(){
+        if(!clicked){
+            
+            balloon.x = game.input.x;
+            basket.x = game.input.x;
+
+            balloon.alpha = 1;
+            clicked = true;
+            animate = true;
+            beepSound.play();
+            if(blockDirection[curBlock]=='Right'){
+                kid_walk.animations.play('right', 6, true);
+            }else{
+                kid_walk.animations.play('left', 6, true);
+            }
+
+            if(oneLabel){ //Hiding labels
+                blockLabel.visible = false;
+                blockSeparator.visible = false;
+            }
+        }
+    },
+
+    postScore: function (){
+        
+        var abst = "numCircles:"+numBlocks+", valCircles: " + detail+" balloonX: " + basket.x + ", selIndex: " + fractionIndex;
+        
+        var hr = new XMLHttpRequest();
+        // Create some variables we need to send to our PHP file
+        var url = "assets/cn/save.php";
+        var vars = "s_ip="+hip+"&s_name="+name+"&s_lang="+lang+"&s_game="+oneShape+"&s_mode="+oneType;
+        vars += "&s_oper="+oneOperator+"&s_leve="+oneDifficulty+"&s_posi="+onePosition+"&s_resu="+result+"&s_time="+totalTime+"&s_deta="+abst;
+        
+        hr.open("POST", url, true);
+        hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
+        hr.onreadystatechange = function() {
+            console.log(hr);
+
+            if(hr.readyState == 4 && hr.status == 200) {
+                var return_data = hr.responseText;
+                console.log(return_data);
+            }
+        }
+        // Send the data to PHP now... and wait for response to update the status div
+        hr.send(vars); // Actually execute the request
+        console.log("processing...");
+    },
     
     //Navigation functions,
     

+ 3 - 1
js/menu.js

@@ -9,6 +9,7 @@ var lbl_game;
     var menuState = {
         create: function(){},
         loadGame: function(){},
+        ---------------------------- end of phaser functions
         showTitle: function(){},
         clearTitle: function(){},
         showOption: function(){},
@@ -137,8 +138,9 @@ var menuState = {
         
     },
     
-    //calls the selected game
+    //calls the selected game menu screen
     loadGame: function(){
+        
         this.beep.play();
         if( (this.num==1 || this.num==2) && this.shape=="Circle"){
             oneShape = this.shape;

+ 134 - 131
js/squareOne.js

@@ -17,6 +17,8 @@
 
     var gameSquareOne = {
         create: function(){},
+        loadState: function(){},
+        ---------------------------- end of phaser functions
         updateCounter: function(){},
         overSquare: function(){},
         outSquare: function(){},
@@ -25,9 +27,9 @@
         postScore: function(){},
         update: function(){},
         showOption: function(){},
-        loadState: function(){},
         viewHelp: function(){},
             //checkOverlap: function(){}
+            //getRndDivisor: function(){}
     };
 
     var endSquareOne = {
@@ -252,7 +254,7 @@ var mapSquareOne = {
         'y': [ 486, 422, 358, 294, 230, 166 ]
         };
 
-          //Garage
+        //Garage
         var garage = game.add.image(this.points.x[0], this.points.y[0], 'garage');
         garage.scale.setTo(0.4);
         garage.anchor.setTo(0.5, 1);
@@ -393,6 +395,7 @@ var curFloor;
 var detail;
 
 var gameSquareOne = {
+
     create: function() {  
         
         //timer
@@ -708,6 +711,135 @@ var gameSquareOne = {
             arrow.alpha = 0.5;
     },
     
+    update: function() {
+                
+        if(!clicked){
+            if(!move){
+                if(oneType=='A'){
+                    //Follow mouse
+                    if (game.physics.arcade.distanceToPointer(arrow, game.input.activePointer) > 8){
+                        var xPos = game.input.mousePointer.x;
+                        arrow.x = xPos;
+                    }                    
+                }
+            }
+        }
+        
+        //Start animation
+        if(animate){
+
+            if(blockDirection[curBlock]=='Right'){
+                tractor.x+=2;
+            }else if(blockDirection[curBlock]=='Left'){
+                tractor.x-=2;
+            }
+                        
+            for(var i=0;i<numBlocks;i++){ //Moving every block
+                if(blockDirection[curBlock]=='Right'){
+                    blocks.children[i].x +=2;
+                }else{
+                    blocks.children[i].x -=2;
+                }
+            }
+            
+            var extra = 80-blockDistance[curBlock];
+            
+            if(blockDirection[curBlock]=='Right'){
+                if(blocks.children[curBlock].x>=nextEnd+extra){
+                    blocks.children[curBlock].alpha = 0;
+                    blocks.y += 40;
+                    curBlock +=1;
+                    nextEnd += blockDistance[curBlock];
+                    for(var i=0; i<=floorIndex; i++ ){
+                        if(floorBlocks.children[i].x<(blocks.children[curBlock-1].x+blockDistance[curBlock-1])){
+                            floorBlocks.children[i].alpha = 0.2;
+                            curFloor = i;
+                        }
+                    }
+                }
+            }else if(blockDirection[curBlock]=='Left'){
+                if(blocks.children[curBlock].x<=(nextEnd-extra)){
+                    blocks.children[curBlock].alpha = 0;
+                    blocks.y += 40;
+                    curBlock+=1;
+                    nextEnd -= blockDistance[curBlock];
+                    for(var i=0; i<=floorIndex; i++ ){
+                        if(floorBlocks.children[i].x>(blocks.children[curBlock-1].x-blockDistance[curBlock-1])){
+                            floorBlocks.children[i].alpha = 0.2;
+                            curFloor = i;
+                        }
+                    }
+                }
+            }
+            
+            if( curBlock>blockIndex || curFloor>=floorIndex){ //Final position
+                animate= false;
+                checkCollide = true;
+            }       
+        }
+        
+        //Check if tractor has blocks left or floor holes
+        if(checkCollide){
+            tractor.animations.stop();
+            timer.stop();
+            //Check left blocks
+            var resultBlock = true;
+            for(var i=0; i<=blockIndex; i++){
+                if(blocks.children[i].alpha==1) resultBlock = false;
+            }
+            
+            //check floor Holes
+            var resultFloor = true;
+            for(var i=0; i<=floorIndex; i++){
+                if(floorBlocks.children[i].alpha==1) resultFloor = false;
+            }
+                        
+            if(resultBlock && resultFloor){
+                result = true;
+            }else{
+                result = false;
+            }
+            this.postScore();
+            move = true;
+            checkCollide = false;
+        }
+        
+        //Continue moving animation
+        if(move){
+            
+            if(moveCounter==0){
+                if(result){
+                    tractor.animations.play('right', 6, true);
+                    okSound.play();
+                    okImg.alpha = 1;
+                }else{
+                    errorSound.play();
+                    errorImg.alpha = 1;
+                }
+            }
+            
+            moveCounter += 1;
+            
+            if(result){
+                if(oneOperator=='Minus'){
+                    tractor.x -=2;
+                }else{
+                    tractor.x +=2;
+                }
+            }
+            
+            if(moveCounter>=moveEnd){
+                if(result){
+                    oneMove = true;
+                }else{
+                    oneMove = false;
+                }
+                game.state.start('mapSOne');
+            }
+        }
+        
+    },
+
     updateCounter: function() {
         totalTime++;
     },
@@ -838,135 +970,6 @@ var gameSquareOne = {
         console.log("processing...");
     },       
     
-    update: function() {
-                
-        if(!clicked){
-            if(!move){
-                if(oneType=='A'){
-                    //Follow mouse
-                    if (game.physics.arcade.distanceToPointer(arrow, game.input.activePointer) > 8){
-                        var xPos = game.input.mousePointer.x;
-                        arrow.x = xPos;
-                    }                    
-                }
-            }
-        }
-        
-        //Start animation
-        if(animate){
-
-            if(blockDirection[curBlock]=='Right'){
-                tractor.x+=2;
-            }else if(blockDirection[curBlock]=='Left'){
-                tractor.x-=2;
-            }
-                        
-            for(var i=0;i<numBlocks;i++){ //Moving every block
-                if(blockDirection[curBlock]=='Right'){
-                    blocks.children[i].x +=2;
-                }else{
-                    blocks.children[i].x -=2;
-                }
-            }
-            
-            var extra = 80-blockDistance[curBlock];
-            
-            if(blockDirection[curBlock]=='Right'){
-                if(blocks.children[curBlock].x>=nextEnd+extra){
-                    blocks.children[curBlock].alpha = 0;
-                    blocks.y += 40;
-                    curBlock +=1;
-                    nextEnd += blockDistance[curBlock];
-                    for(var i=0; i<=floorIndex; i++ ){
-                        if(floorBlocks.children[i].x<(blocks.children[curBlock-1].x+blockDistance[curBlock-1])){
-                            floorBlocks.children[i].alpha = 0.2;
-                            curFloor = i;
-                        }
-                    }
-                }
-            }else if(blockDirection[curBlock]=='Left'){
-                if(blocks.children[curBlock].x<=(nextEnd-extra)){
-                    blocks.children[curBlock].alpha = 0;
-                    blocks.y += 40;
-                    curBlock+=1;
-                    nextEnd -= blockDistance[curBlock];
-                    for(var i=0; i<=floorIndex; i++ ){
-                        if(floorBlocks.children[i].x>(blocks.children[curBlock-1].x-blockDistance[curBlock-1])){
-                            floorBlocks.children[i].alpha = 0.2;
-                            curFloor = i;
-                        }
-                    }
-                }
-            }
-            
-            if( curBlock>blockIndex || curFloor>=floorIndex){ //Final position
-                animate= false;
-                checkCollide = true;
-            }       
-        }
-        
-        //Check if tractor has blocks left or floor holes
-        if(checkCollide){
-            tractor.animations.stop();
-            timer.stop();
-            //Check left blocks
-            var resultBlock = true;
-            for(var i=0; i<=blockIndex; i++){
-                if(blocks.children[i].alpha==1) resultBlock = false;
-            }
-            
-            //check floor Holes
-            var resultFloor = true;
-            for(var i=0; i<=floorIndex; i++){
-                if(floorBlocks.children[i].alpha==1) resultFloor = false;
-            }
-                        
-            if(resultBlock && resultFloor){
-                result = true;
-            }else{
-                result = false;
-            }
-            this.postScore();
-            move = true;
-            checkCollide = false;
-        }
-        
-        //Continue moving animation
-        if(move){
-            
-            if(moveCounter==0){
-                if(result){
-                    tractor.animations.play('right', 6, true);
-                    okSound.play();
-                    okImg.alpha = 1;
-                }else{
-                    errorSound.play();
-                    errorImg.alpha = 1;
-                }
-            }
-            
-            moveCounter += 1;
-            
-            if(result){
-                if(oneOperator=='Minus'){
-                    tractor.x -=2;
-                }else{
-                    tractor.x +=2;
-                }
-            }
-            
-            if(moveCounter>=moveEnd){
-                if(result){
-                    oneMove = true;
-                }else{
-                    oneMove = false;
-                }
-                game.state.start('mapSOne');
-            }
-        }
-        
-    },
-    
     //Navigation functions,
     
     showOption: function(){

+ 155 - 123
js/squareTwo.js

@@ -1,6 +1,7 @@
 /*
     var menuSquareTwo = {
         create: function(){},
+        ---
         showOption: function(){},
         loadState: function(){},
         loadMap: function(){}
@@ -9,6 +10,7 @@
     var mapSquareTwo = {
         create: function(){},
         update: function(){},
+        ---
         showOption: function(){},
         loadState: function(){},
         loadGame: function()
@@ -16,6 +18,8 @@
 
     var gameSquareTwo = {
         create: function(){},
+        loadGame: function(){},
+        ---------------------------- end of phaser functions
         updateCounter: function(){},
         overSquare: function(){},
         outSquare: function(){},
@@ -25,19 +29,20 @@
         update: function(){},
         showOption: function(){},
         loadState: function(){},
-    
-        loadGame: function(){}
-        getRndDivisor
             //viewHelp: function(){},
             //checkOverlap: function(){}
+        getRndDivisor: function(){}
+            
     };
 
     var endSquareTwo = {
         create: function(){},
         update: function(){},
+        ---
         verPrincipal: function(){},
         verMenu: function(){}
     };
+        }
 */
 
 // Fractions Comparison Square states
@@ -45,6 +50,7 @@
 /****************************** MENU ****************************/
 
 var menuSquareTwo = {
+
     create: function() {
         
         // Creating sound variable
@@ -54,16 +60,19 @@ var menuSquareTwo = {
         var words = game.cache.getJSON('dictionary');
           
         // Menu options
-          //information label
+        
+        //information label
         m_info = game.add.text(14, 53, "", { font: "20px Arial", fill: "#330000", align: "center" });
-          // Return to language button
+        
+        // Return to language button
         m_world = game.add.sprite(10, 10, 'world'); 
         m_world.inputEnabled = true;
         m_world.input.useHandCursor = true;
         m_world.events.onInputDown.add(this.loadState, {state: "boot", beep: beepSound});
         m_world.events.onInputOver.add(this.showOption, {message: words.menu_world});
         m_world.events.onInputOut.add(this.showOption, {message: ""});
-          // Return to menu button
+        
+        // Return to menu button
         m_list = game.add.sprite(60, 10, 'list'); 
         m_list.inputEnabled = true;
         m_list.input.useHandCursor = true;
@@ -77,9 +86,9 @@ var menuSquareTwo = {
         title.anchor.setTo(1, 0.5);
         
         //Showing Games and Levels
-        var maxHeight = 120; //Max height of a stair
+        var maxHeight = 120;  //Max height of a stair
         var stairHeight = 29; //height growth of a stair
-        var stairWidth = 80; //Width of a stair
+        var stairWidth = 80;  //Width of a stair
         var startStair = 240;
         var startSymbol = 150;
         var startSquare = (startSymbol/2)+startStair+stairWidth*5;
@@ -89,8 +98,7 @@ var menuSquareTwo = {
             bplus.scale.setTo(0.7);
             bplus.anchor.setTo(0.5,0.5);
             
-         //First stairs, 6 levels
-
+        //First stairs, 6 levels
         var stairsA = [];
         for(var i=1;i<=5;i++){
             //stair
@@ -117,7 +125,8 @@ var menuSquareTwo = {
             var label = game.add.text(xl, yl, i, { font: '25px Arial', fill: '#ffffff', align: 'center' });
                 label.anchor.setTo(0.5, 0.4);
         }
-                
+
+        //second stairs        
         var stairsB = [];
         for(var i=1;i<=5;i++){
             //stair
@@ -145,7 +154,7 @@ var menuSquareTwo = {
                 label.anchor.setTo(0.5, 0.4);
         } 
         
-                
+        //third stair        
         var stairsC = [];
         for(var i=1;i<=5;i++){
             //stair
@@ -184,8 +193,7 @@ var menuSquareTwo = {
     loadState: function(){
         this.beep.play();
         game.state.start(this.state);
-    },
-        
+    },  
         
     //MapLoading function
     loadMap: function(){
@@ -206,6 +214,7 @@ var menuSquareTwo = {
 /****************************** MAP ****************************/
 
 var mapSquareTwo={
+
     create: function() {
                 
         // Creating sound variable
@@ -265,24 +274,16 @@ var mapSquareTwo={
         'y': [ 486, 422, 358, 294, 230, 166 ]
         };
 
-        
-         //Road
-        this.points = {
-        'x': [ 90, 204, 318, 432, 546, 660 ],
-        'y': [ 486, 422, 358, 294, 230, 166 ]
-        };
-        
-          //House
+        //House
         var house = game.add.image(this.points.x[0], this.points.y[0], 'house');
         house.scale.setTo(0.7);
         house.anchor.setTo(0.7, 0.8);
-         //School
+        //School
         var school = game.add.image(this.points.x[5], this.points.y[5], 'school');
         school.scale.setTo(0.35);
         school.anchor.setTo(0.2, 0.7);
         
-         //Trees and Rocks
-        
+        //Trees and Rocks
         this.rocks = {
              'x': [156, 275, 276, 441, 452, 590, 712],
              'y': [309, 543, 259, 156, 419, 136, 316]
@@ -410,6 +411,7 @@ var xA, yA, xB, yB, blockW, blockH;
 var okImg, errorImg;
 
 var gameSquareTwo = {
+
     create: function() {  
         
         //timer
@@ -469,7 +471,8 @@ var gameSquareTwo = {
         result = false; //Game is correct
         animate = null; //Final animation sequence
         
-         //generator
+        //generator
+        console.log("----------");
         console.log("Diff " + twoDifficulty + ", ini " + ((twoDifficulty-1)*2+1) + ", end " + ((twoDifficulty-1)*2+3));
         var rPoint = game.rnd.integerInRange((twoDifficulty-1)*2+1,(twoDifficulty-1)*2+3);
         sizeA = points[rPoint];
@@ -645,40 +648,146 @@ var gameSquareTwo = {
         errorImg.anchor.setTo(0.5);
         errorImg.alpha = 0;
         
+        //error text
+        errorTextA = game.add.text(game.world.centerX, game.world.centerY-225, "", {font: "20px Arial", fill: "#330000", align: "center" });
+        errorTextA.anchor.setTo(0.5, 0.5);
+        errorTextB = game.add.text(game.world.centerX, game.world.centerY-45, "", {font: "20px Arial", fill: "#330000", align: "center" });
+        errorTextB.anchor.setTo(0.5, 0.5);
+
         counter = 0;
         endCounter = 100;
         cDelay = 0;
         eDelay = 60;
     },
     
+    update: function() {
+        
+        // kid walking cycle during the phase
+        if(!(clickA && clickB) && !animate){
+            if(kidDirection=='right'){
+                kid.x += 1;
+                if(kid.x>=800){
+                    kidDirection='left';
+                    kid.animations.play('left', 8, true);
+                }
+            }else{
+                kid.x -= 1;
+                if(kid.x<=100){
+                    kidDirection='right';
+                    kid.animations.play('right', 8, true);
+                }
+            }
+        }
+
+        //If clicked A only, animate
+        if(animateA){
+            for(var i=0;i<valueA;i++){
+                blocksA.children[i].y +=2;
+            }
+            if(blocksA.children[0].y>=auxblqA.children[0].y){
+                animateA = false;
+                fractionA.alpha = 1;
+                fractionA.setText(valueA+"\n"+sizeA);
+                separatorA.alpha = 1;
+            }
+        }
+
+        //If clicked B only, animate
+        if(animateB){ 
+            for(var i=0;i<valueB;i++){
+                blocksB.children[i].y +=2;
+            }
+            if(blocksB.children[0].y>=auxblqB.children[0].y){
+                animateB = false;
+                fractionB.alpha = 1;
+                fractionB.setText(valueB+"\n"+sizeB);
+                separatorB.alpha = 1;
+            }
+        }
+        
+        //if clicked A and B
+        if(clickA && clickB && !this.animate){
+            //Check result
+            timer.stop();
+            cDelay++;
+            if(cDelay>=eDelay){
+                //fractions are equivalent : correct
+                if((valueA/sizeA) == (valueB/sizeB)){
+                    result = true;
+                    twoMove = true;
+                    okSound.play();
+                    okImg.alpha = 1;
+                //fractions are not equivalent
+                }else{
+                    result = false;
+                    twoMove = false;
+                    errorSound.play();
+                    kid.animations.stop();
+                    errorImg.alpha = 1;
+                }
+                this.postScore();
+                clickA = false;
+                clickB = false;
+                animate = true;
+            }
+        }
+        
+        if(animate){
+            counter++;
+            if(result){
+                kid.x += 2;
+                kidDirection='right';
+                kid.animations.play('right', 8, true);
+            }
+            if(counter>endCounter){
+                game.state.start('mapSTwo');
+            }
+        }
+    },
+
     updateCounter: function() {
         totalTime++;
     },
     
     overSquare: function(){
         if(!clickA && this.who=="A"){
-            for(var i=0;i<sizeA;i++){
-                if(i<=this.indice){
-                    blocksA.children[i].alpha = 1;
-                }else{
-                    blocksA.children[i].alpha = 0.5;
+            if(this.indice == sizeA-1){
+                errorTextA.setText(words.error_msg);
+                errorTextB.setText("");
+            }else{    
+                errorTextA.setText("");
+                errorTextB.setText("");
+                for(var i=0;i<sizeA;i++){
+                    if(i<=this.indice){
+                        blocksA.children[i].alpha = 1;
+                    }else{
+                        blocksA.children[i].alpha = 0.5;
+                    }
                 }
+                fractionA.x = xA+((this.indice +1)*(blockW/sizeA))+40;
+                fractionA.alpha = 1;
+                fractionA.setText(this.indice +1);
             }
-            fractionA.x = xA+((this.indice +1)*(blockW/sizeA))+40;
-            fractionA.alpha = 1;
-            fractionA.setText(this.indice +1);
         }
+
         if(!clickB && this.who=="B"){
-            for(var i=0;i<sizeB;i++){
-                if(i<=this.indice){
-                    blocksB.children[i].alpha = 1;
-                }else{
-                    blocksB.children[i].alpha = 0.5;
+            if(this.indice == sizeB-1){
+                errorTextB.setText(words.error_msg);
+                errorTextA.setText("");
+            }else{
+                errorTextA.setText("");
+                errorTextB.setText("");
+                for(var i=0;i<sizeB;i++){
+                    if(i<=this.indice){
+                        blocksB.children[i].alpha = 1;
+                    }else{
+                        blocksB.children[i].alpha = 0.5;
+                    }
                 }
+                fractionB.x = xB+((this.indice +1)*(blockW/sizeB))+40;
+                fractionB.alpha = 1;
+                fractionB.setText(this.indice +1);
             }
-            fractionB.x = xB+((this.indice +1)*(blockW/sizeB))+40;
-            fractionB.alpha = 1;
-            fractionB.setText(this.indice +1);
         }
     },
 
@@ -698,7 +807,7 @@ var gameSquareTwo = {
     },
     
     clickSquare: function(){
-        if(!clickA && this.who=="A"){
+        if(!clickA && this.who=="A" && this.indice!=sizeA-1){
             for(var i=0;i<sizeA;i++){
                 blocksA.children[i].inputEnabled = false;
                 if(i<=this.indice){
@@ -716,7 +825,8 @@ var gameSquareTwo = {
             separatorA.x = fractionA.x
             animateA = true;
         }
-        if(!clickB && this.who=="B"){
+
+        if(!clickB && this.who=="B" && this.indice!=sizeB-1){
             for(var i=0;i<sizeB;i++){
                 blocksB.children[i].inputEnabled = false;
                 if(i<=this.indice){
@@ -761,85 +871,6 @@ var gameSquareTwo = {
         console.log("processing...");
     },
 
-    update: function() {
-        
-        if(!(clickA && clickB) && !animate){
-            if(kidDirection=='right'){
-                kid.x += 1;
-                if(kid.x>=800){
-                    kidDirection='left';
-                    kid.animations.play('left', 8, true);
-                }
-            }else{
-                kid.x -= 1;
-                if(kid.x<=100){
-                    kidDirection='right';
-                    kid.animations.play('right', 8, true);
-                }
-            }
-        }
-
-        
-        if(animateA){ //If clicked A only, animate
-            for(var i=0;i<valueA;i++){
-                blocksA.children[i].y +=2;
-            }
-            if(blocksA.children[0].y>=auxblqA.children[0].y){
-                animateA = false;
-                fractionA.alpha = 1;
-                fractionA.setText(valueA+"\n"+sizeA);
-                separatorA.alpha = 1;
-            }
-        }
-        if(animateB){ //If clicked B only, animate
-            for(var i=0;i<valueB;i++){
-                blocksB.children[i].y +=2;
-            }
-            if(blocksB.children[0].y>=auxblqB.children[0].y){
-                animateB = false;
-                fractionB.alpha = 1;
-                fractionB.setText(valueB+"\n"+sizeB);
-                separatorB.alpha = 1;
-            }
-        }
-        
-        if(clickA && clickB && !this.animate){
-            //Check result
-            timer.stop();
-            cDelay++;
-            if(cDelay>=eDelay){
-                if((valueA/sizeA) == (valueB/sizeB)){
-                    result = true;
-                    twoMove = true;
-                    okSound.play();
-                    okImg.alpha = 1;
-                }else{
-                    result = false;
-                    twoMove = false;
-                    errorSound.play();
-                    kid.animations.stop();
-                    errorImg.alpha = 1;
-                }
-                this.postScore();
-                clickA = false;
-                clickB = false;
-                animate = true;
-            }
-        }
-        
-        if(animate){
-            counter++;
-            if(result){
-                kid.x += 2;
-                kidDirection='right';
-                kid.animations.play('right', 8, true);
-            }
-            if(counter>endCounter){
-                game.state.start('mapSTwo');
-            }
-        }
-    },
-  
     //Navigation functions,
     
     showOption: function(){
@@ -879,6 +910,7 @@ var gameSquareTwo = {
 /****************************** END ****************************/
 
 var endSquareTwo = {
+
     create: function() {  
         
         // Creating sound variable