XJEL2645 (18/19) / Mbed 2 deprecated 2645_Mygame

Dependencies:   mbed Gamepad N5110

Revision:
10:68076e3dcc33
Parent:
9:18b059e5abb9
Child:
11:543c62bed764
--- a/snake/snake.cpp	Sat Apr 20 08:15:10 2019 +0000
+++ b/snake/snake.cpp	Sat Apr 20 15:15:44 2019 +0000
@@ -75,14 +75,19 @@
     srand(time(NULL));
     ball_x = 3 + rand() % (WIDTH - 6); // randomise initial position of ball. 
     ball_y = 3 + rand() % (HEIGHT - 6);
-    for (int i = 0; i < length; i++) {
-        if(ball_x + _size >= _x[i] && ball_x - _size <= _x[i] && ball_y + _size >= _y[i] && ball_y - _size <= _y[i]){
-                srand(time(NULL));
-                ball_x = 3 + rand() % (WIDTH - 6); // randomise initial position of ball. 
-                ball_y = 3 + rand() % (HEIGHT - 6);
-            }
-    }
-
+    int check = 0;
+    do{
+      check = 0;
+      for (int i = 0; i < length; i++) {
+          //if(ball_x == _x[i] && ball_y ==_y[i]) {
+          if(ball_x + _size  >= _x[i] && ball_x - _size <= _x[i] && ball_y + _size >= _y[i] && ball_y - _size <= _y[i]){
+           check = 1;
+          }
+       }
+        //srand(time(NULL));
+        ball_x = 3 + rand() % (WIDTH - 6); // randomise initial position of ball. 
+        ball_y = 3 + rand() % (HEIGHT - 6);
+     } while(check == 1);
 }
 
 void snake::check_eat(Gamepad &pad)