Snake vs Block Game to be run upon K64F.

Dependencies:   mbed

Revision:
50:3cf9a94a264e
Parent:
49:441c32f6603e
--- a/SnakevsBlock/SnakevsBlock.cpp	Fri Apr 26 17:16:22 2019 +0000
+++ b/SnakevsBlock/SnakevsBlock.cpp	Fri Apr 26 18:04:19 2019 +0000
@@ -116,11 +116,6 @@
         blockbuff = -11;
     }
     //_statset.read(sd); //to read the currently stored value.
-    if(_length >= 20)  {
-        SnakevsBlock::reset();
-        level = _wl.LevelComplete(lcd, pad, level);
-        _Setstats.write(level, sd);
-    }
     if(_length == 0)  {
         _wl.GameOver(lcd,pad);
     }
@@ -131,6 +126,12 @@
     else {
         back = 0;
     }
+    printf("%d\n",_length);
+    if(_length >= 20)  {
+        level = _wl.LevelComplete(lcd, pad, level);
+        _Setstats.write(level, sd);
+        SnakevsBlock::reset();
+    }
     return back;
 }
 
@@ -250,8 +251,8 @@
 {
     //If statements check if the snake sprite has collided with any
     //of the blocks' sides and then stop the snake moving in x axis
-        
-    if(_length>=10) {_length = 10;} //to stop the snake length virtually at 10 when it goes past it.
+    int length = _length;
+    if(_length>=10) {length = 10;} //to stop the snake length virtually at 10 when it goes past it.
     
     for(int i=0; i<=9; i++)  {
         b[i] = 1;
@@ -266,11 +267,11 @@
                     //For West side of walls 
                     if(
                         ((snake_pos[i].x == b_pos.x + b_x_combination+2) ||  //W
-                        (snake_pos[i].x + 1 == b_x_combination+2))&&(_d != E)&&(_length > i) //W
+                        (snake_pos[i].x + 1 == b_x_combination+2))&&(_d != E)&&(length > i) //W
                         ) {
                         //code makes sure that the colliding part doesn't move in x axis.
                         for(int snake_beed_num=0; snake_beed_num<=10; snake_beed_num++)  {
-                            if(_length == snake_beed_num + i)  {
+                            if(length == snake_beed_num + i)  {
                                 b[snake_beed_num - 1] = 0;
                             }
                         }
@@ -278,11 +279,11 @@
                     //for East side of walls
                     else if (
                         ((snake_pos[i].x + 1 == b_x_combination) ||  //E
-                        (snake_pos[i].x + 2 == b_x_combination))&&(_d != W)&&(_length > i) //E
+                        (snake_pos[i].x + 2 == b_x_combination))&&(_d != W)&&(length > i) //E
                     ) {
                         //code makes sure that the colliding part doesn't move in x axis.
                         for(int snake_beed_num=0; snake_beed_num<=10; snake_beed_num++)  {
-                            if(_length == snake_beed_num + i)  {
+                            if(length == snake_beed_num + i)  {
                                 b[snake_beed_num - 1] = 0;
                             }
                         }