Re: Separation of the game from the menu

@magurp244: I'm going to go with the OP may need something really down to basics here.

The way I'd do it is to have a menu class, and have the members, choices of that menu, within each menu you set up. Then you'd want something responsible for getting a user's input from that menu, you might call it a menu manager, or similar. You could probably shove them in the same class, but there's a good Object Oriented Programming Principal known as "Single Responsibility", which is often really good advice.

So, have two classes, here's some psudo code, in a C# ish fashion, but it should apply to any other language.

public class Menu
{
    List<string> Choices = new List<string>();

    public Menu(List<string> choices)
    {
        this.Choices = choices;
    }
}

public class MenuManager
{
    public void Render(Menu menu)
    {
        foreach (var menuItem of menu.Choices)
        {
            // render this menuItem on screen for the user somehow
        }
    }

    public void Close()
    {
        // remove any onscreen menu however you'd like
    }
}

How you then choose to handle that user picking an option is up to you. You may either have an event, or store a chosen value and periodically check for a choice in the game loop, or a callback function, etc. Usage may look like this with the first option, an event based approach.

// you'd probably only want one of these in your whole app, even if you have many menus
var menuManager = new MenuManager();
var menu = new Menu(new List<string> { "New game", "Load game", "Cheat menu", "Quit" });
menuManager.Render(menu);
// you'll have to add this event to the menu manager. You may choose not to, so I didn't provide this in the code
menuManager.OnMenuChoice += (menu, choice) =>
{
    // determine what you're doing somehow
};

There's lots of ways you can do it. I do recommend separating it from the game code though! You're absolutely on the right lines there. Good luck. I hope I've helped rather than hindered here

_______________________________________________
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
  • ... AudioGames . net Forum — Developers room : jonikster via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : magurp244 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : jonikster via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : magurp244 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : magurp244 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : truecraig via Audiogames-reflector

Reply via email to