Main menu in a game

Started by
4 comments, last by Zorak 18 years, 8 months ago
Hello, everyone. I was wandering what is the best way to implement main menu from which you could start the game, change some options etc. Should I make another class for the whole game itself? Share your experience on that matter please. :)
Advertisement
Make a small standalone executable that reads in all configurations from disk and let the player do their own settings in a modal dialog. When he/she press OK you fire off a "startGame" function in a DLL where you have your game code and send all configuration into that very function.

Separating the configuration part from the game part is a nifty thing to do imho :).
Domine non secundum peccata nostra facias nobis
What language? c++? Are you having problems with anything in particular? Another thing you could do is just have a variable with the game state and change it around everytime you want to access something in particular for example

 enum GAME_STATE {  /*...*/ }; switch(game_state) {   case GAME_RUNNING:     RunGame();    break;    case GAME_OPTIONS:     ShowOptions();    break;   case GAME_MENU:     ShowMenu();    break; };


I don't really think you would need a class especially not for the whole game :/
Yes, I'm writing in C++. But I haven't made myself familiar with dlls yet. Gamestates is a good idea. The question is then should my game check this state every iteration of the main cycle and make decision based upon that check what to show, how to react to events, how to update itself? Isn't it better to make a class with static members that should keep all that stuff encapsulated?
Quote:Original post by Tamior
Yes, I'm writing in C++. But I haven't made myself familiar with dlls yet. Gamestates is a good idea. The question is then should my game check this state every iteration of the main cycle and make decision based upon that check what to show, how to react to events, how to update itself? Isn't it better to make a class with static members that should keep all that stuff encapsulated?


Yeah just have the switch statement in your main loop and check for the state every iteration. Rather than having the whole game in a class I would rather have a function and smaller functions to carry out smaller tasks for example

void ShowOptions(){  if(HandleInput(..) == EXIT)   change_state();  RenderOptions(..);}


Additionally you could put everything inside a namespace to make it cleaner. Also use classes to handle smaller tasks related to each other for example you might have a class to handle game resources, another class to handle I don't know the player stats. Write the classes in such a way the code is reusable so you can use it in other projects as well, and of course keep everything only the class cares about encapsulated. I'm just saying that a class for the whole game doesn't work I've had bad experiences with that trust me ;)
No. ;)

Make a baseclass and derive every state from that.

ie.
class baseState {  void initState ( void );  void deInitState ( void );  void update ( void );};class introState : public baseState { ...};class gameState : public baseState { ...};class stateManager {  std::vector<baseState*> mvStates;  void changeState ( ... );  void pauseState ( ... );  void addState ( ... );  void removeState ( ... );  ...  void run ( void );   // Game mainloop calls update of current state  void putMsg ( ... ); // Send a message to current state};


Voila. Each state is separated and have different behaviours but the mainloop is still the same (call ->update(), each frame).

EDIT: tags are not named code in this forum.
Domine non secundum peccata nostra facias nobis

This topic is closed to new replies.

Advertisement