Final Submission. I have read and agreed with Statement of Academic Integrity.

Dependencies:   mbed Gamepad N5110 Joystick

Revision:
7:72119ea3b3b1
Parent:
6:f02ea8ec42b3
Child:
8:264398d3c610
--- a/Game_engine/Game_engine.cpp	Thu May 09 08:54:39 2019 +0000
+++ b/Game_engine/Game_engine.cpp	Thu May 09 09:09:07 2019 +0000
@@ -46,7 +46,6 @@
     } else if (_direction == 3) {
         snake.set_snake_posX (snake.get_snake_posX()+ 4); 
     }
-    wait(0.01); 
 }
 
 void GameEngine::food_move() {
@@ -54,6 +53,12 @@
     if(snake.get_snake_posX() == snake.get_food_posX() && snake.get_snake_posY() == snake.get_food_posY()) {
         snake.set_food_posX((rand()%(19) + 1) * 4);
         snake.set_food_posY((rand()%(11) + 1) * 4 - 2);
+        for (int k = _body_seg; k > 0; k--) {
+            if((_body_posX[k] == snake.get_food_posX() && _body_posY[k] == snake.get_food_posY()) || (snake.get_snake_posX() == snake.get_food_posX() && snake.get_snake_posY() == snake.get_food_posY())) {
+                snake.set_food_posX((rand()%(19) + 1) * 4);
+                snake.set_food_posY((rand()%(11) + 1) * 4 - 2);   
+            } 
+        }
         _body_seg = _body_seg + 1;
     }    
 }