-
Switch Case
Hello, I am making a text-based game right now, and I have to ask a question. I am finding that I am using a lot of switch cases in my game. Such as those found in the tutorial on this site. It is getting really repetitive, making switch cases at every menu screen. Also, my program is becoming very long because of this. Are their any other ways to make an interface, or am I stuck with switch cases. :confused:
My program output is like this:
Code:
1. Play Game
2. Load Game
3. Exit Game
Note: This not my actual game menu , just an example ;)
So how can I use this concept without using switchcases?
I don't know API or anything like that either.
-
For a text based game, I don't think you can really use a different method. Sorry.
-
Thats cool. At least I don't have to change anything now. :p
-
If you mean you are writing a given menu or a given switch statement over and over then you can put it in a function and call the function repetitively rather than rewriting the menu or switch statement over and over. If you have to adjust the menu/switch statements or use completely new menus/switch statements, then you have no choice but to write them out, but only once. If you have pseudocoded your program before writing the code itself, you'll know which menus/switch statements will be repetitive and which aren't, otherwise, if you're writing on the fly, cut/paste words works wonders.