Is this not your own code?
In either case, the answer is very simple.
It's this if statement that kills the game.
if(S[0].x<=0||S[0].y<=0 ||S[0].x>=600,S[0].x>=600)
{
MessageBox(NULL,L"Game over",L"Game over",MB_OK);
exit(0);
}
Given that the file's called snake.cpp, I'll assume that this is the classic game of snake.
The thing is, you can travel parallel to the walls in the edge cells. The game ends when one of the two conditions are met:
After the next move:
- The snake's head will occupy a cell already occupied by it's body
- The snakes head will occupy a cell that is a wall cell, rather than a game-board cell
Ive just woken up and dont feel like trying to build it. From a quick glance, it would seem that you can prevent the game ending prematurely by changing the above if statement.
if( (S[0].x < 0) || (S[0].y < 0) || (S[0].x > 600) || (S[0].x > 600) )
{
MessageBox(NULL,L"Game over",L"Game over",MB_OK);
exit(0);
}