snake: Remove random goto statements when regenerating apple's position
This commit is contained in:
parent
b1fe24bb57
commit
46b34817d2
|
@ -65,13 +65,16 @@ Point get_random_point()
|
||||||
|
|
||||||
void update_apple()
|
void update_apple()
|
||||||
{
|
{
|
||||||
regenerate:
|
for (;;)
|
||||||
g_apple = get_random_point();
|
{
|
||||||
if (g_head == g_apple)
|
g_apple = get_random_point();
|
||||||
goto regenerate;
|
if (g_head == g_apple)
|
||||||
for (auto point : g_tail)
|
continue;
|
||||||
if (point == g_apple)
|
for (auto point : g_tail)
|
||||||
goto regenerate;
|
if (point == g_apple)
|
||||||
|
continue;
|
||||||
|
break;
|
||||||
|
}
|
||||||
set_grid_tile(g_apple, "\e[31mO");
|
set_grid_tile(g_apple, "\e[31mO");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue