Main menu to call on instructions/game

Hey guys so I am making Hangman, I am almost done. I have a menu and the game itself as well as instructions. But the menu and the game are both separate files. How can I make it so the menu calls on the game when the user makes an input?

Would it be better for the menu to call on the hangman.cpp file or integrate them all together or make the game a function?

1. Menu calls on other files
2. All in one
3. Or put the game and instructions into separate functions?


Which would be easier?
Last edited on
Without posting your code and what your using to compile, I don't think your going to get a complete answer.

Normally you would create a project. include both files. Then when the user chooses a menu option, you would call the game function. You can do it in one file but there is no need to do so.

Once the game is ended, it will return control to the main/menu part of the code.

something like this;

// File one
1
2
3
4
5
#include something
int game()
{
// Play
}


// File two
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include something
string UserChoice;  // Global Var

void menu()
{
// Get User choice
UserChoice=Play;
}

int main()
{
char playagain="Y";
While (playagain=="Y")
{
menu();
game();
cout << "play again Y/N ? ";

}
return 0;
}
Last edited on
Deleted
Last edited on
I would personally recommend that you build a simple state manager and swap between states have an instructions state,menu state and a play game state

http://gamedevgeek.com/tutorials/managing-game-states-in-c/ this link will give you an overview on states.

Best thing about states is you can always add more if you feel like extending your game =D
Thank you I will read up :)

EDIT: I notice that this is for C. I assume that this also applies to c++?
Last edited on
yeah works just as well for c++
Topic archived. No new replies allowed.