How to make the game return main menu when the had touch the tail ?
I tried to change "gameOver = true with gameOver = false" from the function "void logic()", but seems that the game will go on forever and some bug with the right side of the wall. And a second try was to change the "void logic()"
with an integer something like "int logic()" and add a return value "return 1" to the "end of game" detector and return 0 to the end function, and after I changed
while(!gameOver)
{
Draw();
input();
gameOver = logic();
Sleep(0);
}
from the main function... like someone related to do so.. but seems that is not working...
If someone know how to do it please help me figure out how to jump from it..
And no.. no is not 100% my entire project, I did copy some parts of code from somewhere else but yes I understand what i did.. thank you for your patience.. :)
its automatic. For single threaded programs (the default, you would know if you made threads..)
in main, if you call foo:
main()
{
... foo();
^^ when foo ends, the next statement in main will be executed.
}
foo ends when it executes the last statement in the body OR if there is a return statement (return; for void functions allows you to exit early, or return value; for non void).
you don't need to DO anything
I will look to see if you did something wrong, didn't spot it yet. If foo had an infinite loop, main would never resume... things like that. The code is really challenging to read and deal with because of the globals and gotos. Things like that let you make cool, hard to find and really weird bugs that can take weeks to unravel. You probably should not do this to yourself unless you enjoy debugging those kinds of things. Probably, the logic() function has some path(s) that do not modify gameover global correctly. You need to ensure it actually sets this variable for every possible path that should end the game. check that loop at 160ish ... does it get IN the loop to set the value? can ntail == 0 preventing the loop and preventing the game end?
Thank you Jonnin... but I did mess a bit with this code and i found the problem...I just up declared the void functions and then switched the main function from last to first and then in
void logic() i changed this "gameOver = true" with this " main()".. and now if you play the Snake game whenever you tuch your had with your tail will return to main menu. Ofc. I need to make a brake and to put some message that the game will return to menu. thanks and this is how i did it.
And yahhh another problem just came up... lol.. when returning to main menu if you press again option 1 for the game to start... the game will not start.. The program shows always the main menu so in code is stops going ahead and goes for a infinite loop in to function
int main().. and all of the other options works .... Need to figure out how to make a perfect loop. Probably the goto isn't so perfect I'll try to change that with a switch case statement.. hopefully will work. :)
Ohh.. so the first and the 3rd option that is EXIT doesn't seems to work . is just repeating the main menu.. Soo .. is half done .. I need to see what is wrong with the third option as well...
:\