Snake vs Block Game to be run upon K64F.

Dependencies:   mbed

Revision:
87:871d9fecb593
Parent:
83:329da564799a
Child:
99:4841f326200f
--- a/GameObjects/Snake/Snake-test.h	Tue May 07 00:02:11 2019 +0000
+++ b/GameObjects/Snake/Snake-test.h	Wed May 08 16:39:24 2019 +0000
@@ -15,7 +15,7 @@
 
 //GLOBALS//
 Direction d; //represents the direction of movement of the snake.
-int b[10];  //each element in this array represents the beed number in the snake.
+int immobile_bead_n[10];  //each element in this array represents the beed number in the snake.
 bool success_flag; //stores success / failure from a test.
 
 /**
@@ -64,15 +64,15 @@
 bool check_west_movement()
 {
 
-    // Set the direction to W and set snake motion free by setting b as 1;
+    // Set the direction to W and set snake motion free by setting immobile_bead_n as 1;
     d = W;
 
     for(int i=0; i<=9; i++)  {
-        b[i] = 1;
+        immobile_bead_n[i] = 1;
     }
 
     // Update the snake position
-    snake.update(d, b);
+    snake.update(d, immobile_bead_n);
 
     // Read the position
     Vector2D read_pos_2 = snake.get_pos(0); //getting the position of the first beed
@@ -88,15 +88,15 @@
 bool check_east_movement()
 {
 
-    // Set the direction to E and set snake motion free by setting b as 1;
+    // Set the direction to E and set snake motion free by setting immobile_bead_n as 1;
     d = E;
 
     for(int i=0; i<=9; i++)  {
-        b[i] = 1;
+        immobile_bead_n[i] = 1;
     }
 
     // Update the snake position
-    snake.update(d, b);
+    snake.update(d, immobile_bead_n);
 
     // Read the position
     Vector2D read_pos_3 = snake.get_pos(0); //getting the position of the first beed
@@ -113,24 +113,24 @@
 bool check_freeze_movement()
 {
 
-    // Set the direction to W, length and speed both to 10 and set snake motion stopped by setting b as 0 (simulates block sides collision) ;
+    // Set the direction to W, length and speed both to 10 and set snake motion stopped by setting immobile_bead_n as 0 (simulates block sides collision) ;
     d = W;
     snake._setLength(10);
     snake._setSpeed(10);
 
     for(int i=0; i<=9; i++)  {
-        b[i] = 0;
+        immobile_bead_n[i] = 0;
     }
 
     // Update the snake position
-    snake.update(d, b);
+    snake.update(d, immobile_bead_n);
 
     // Read the position
     Vector2D read_pos_4 = snake.get_pos(0); //getting the position of the first beed
     printf("%f, %f\n", read_pos_4.x, read_pos_4.y);
 
-    // Fail the test if the final position after moving West but stopping motion using b[i] = 0; is wrong.
-    if (read_pos_4.x != ((WIDTH/2)) || read_pos_4.y != 18) { //18 because I'm testing the position of the first snake beed, from the top and ((WIDTH/2)) because it is not meant to moove.
+    // Fail the test if the final position after moving West but stopping motion using immobile_bead_n[i] = 0; is wrong.
+    if (read_pos_4.x != ((WIDTH/2)) || read_pos_4.y != 18) { //18 because I'm testing the position of the first snake beed, from the top and ((WIDTH/2)) because it is not meant to move.
         success_flag = false;
     }
     return success_flag;
@@ -139,26 +139,26 @@
 bool check_chain_reaction()
 {
 
-    // Set the direction to W, length to 20 and speed to 2 and set snake motion free by setting b as 1;
+    // Set the direction to W, length to 20 and speed to 2 and set snake motion free by setting immobile_bead_n as 1;
     d = W;
     snake._setLength(20);
     snake._setSpeed(2);
 
     for(int i=0; i<=9; i++)  {
-        b[i] = 1;
+        immobile_bead_n[i] = 1;
     }
 
-    // Update the snake position 3 times because i want to read the position of the third bead that only mooves with a chain reaction.
-    snake.update(d, b);
-    snake.update(d, b);
-    snake.update(d, b);
+    // Update the snake position 3 times because i want to read the position of the third bead that only moves with a chain reaction.
+    snake.update(d, immobile_bead_n);
+    snake.update(d, immobile_bead_n);
+    snake.update(d, immobile_bead_n);
 
     // Read the position
     Vector2D read_pos_5 = snake.get_pos(2); //getting the position of the third beed
     printf("%f, %f\n", read_pos_5.x, read_pos_5.y);
 
     // Fail the test if the final position of the third beed after moving West and after 3 itterations; is wrong.
-    if (read_pos_5.x != ((WIDTH/2)-2) || read_pos_5.y != 24) { //24 because I'm testing the position of the third snake beed, from the top and ((WIDTH/2)) because it is not meant to moove.
+    if (read_pos_5.x != ((WIDTH/2)-2) || read_pos_5.y != 24) { //24 because I'm testing the position of the third snake beed, from the top and ((WIDTH/2)) because it is not meant to move.
         success_flag = false;
     }
     return success_flag;
@@ -167,21 +167,21 @@
 bool check_block_collision_and_relative_movement()
 {
 
-    // Set the direction to E, length to 8 and set snake motion free by setting b as 1;
+    // Set the direction to E, length to 8 and set snake motion free by setting immobile_bead_n as 1;
     d = E;
     snake._setLength(8);
 
     for(int i=0; i<=9; i++)  {
-        b[i] = 1;
+        immobile_bead_n[i] = 1;
     }
 
     // Update the snake position 2 times and then reduce length to 7 (this can simulate block collision of number 1).
-    snake.update(d, b);
-    snake.update(d, b);
+    snake.update(d, immobile_bead_n);
+    snake.update(d, immobile_bead_n);
 
     snake._setLength(7);
     d = E;//now direction is set to east as it continues to move after collision and then update snake object again.
-    snake.update(d, b);
+    snake.update(d, immobile_bead_n);
 
     // Read the position
     Vector2D read_pos_6 = snake.get_pos(0); //getting the position of the first beed
@@ -189,7 +189,7 @@
 
     // Fail the test if the final position of the first beed after moving East 3 times and colliding with block numbered 1; is wrong.
     if (read_pos_6.x != ((WIDTH/2)+2) || read_pos_6.y != 27) { //27 because I'm testing the position of the first snake beed of length 8, from the top
-        // and colliding once with a block numbered 1, read_pos_6.x = ((WIDTH/2)+2) because the 7th beed from bottom mooved only 2 times in effect.
+        // and colliding once with a block numbered 1, read_pos_6.x = ((WIDTH/2)+2) because the 7th beed from bottom moved only 2 times in effect.
         success_flag = false;
     }
     return success_flag;
@@ -198,21 +198,21 @@
 bool check_food_collision_and_relative_movement()
 {
 
-    // Set the direction to W, length to 7 and set snake motion free by setting b as 1;
+    // Set the direction to W, length to 7 and set snake motion free by setting immobile_bead_n as 1;
     d = W;
     snake._setLength(7);
 
     for(int i=0; i<=9; i++)  {
-        b[i] = 1;
+        immobile_bead_n[i] = 1;
     }
 
     // Update the snake position 2 times (2 game  loops) and then increase length to 9 (this can simulate food collision of 2 times).
-    snake.update(d, b);
-    snake.update(d, b);
+    snake.update(d, immobile_bead_n);
+    snake.update(d, immobile_bead_n);
 
     snake._setLength(9);
     d = W;//now direction is set to west as it continues to move after food collision and then update snake object again.
-    snake.update(d, b);
+    snake.update(d, immobile_bead_n);
 
     // Read the position
     Vector2D read_pos_7 = snake.get_pos(0); //getting the position of the first beed
@@ -220,7 +220,7 @@
 
     // Fail the test if the final position of the first beed after moving East 3 times and colliding with block numbered 1; is wrong.
     if (read_pos_7.x != ((WIDTH/2)-4) || read_pos_7.y != 21) { //21 because I'm testing the position of the first snake beed of length 9, from the top
-        // and colliding twice with food, read_pos_7.x = ((WIDTH/2)-4) because the current top beed mooved same number of times to the top beed before it ate food.
+        // and colliding twice with food, read_pos_7.x = ((WIDTH/2)-4) because the current top beed moved same number of times to the top beed before it ate food.
         success_flag = false;
     }
     return success_flag;