Thread: Switch Case

  1. #1
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719

    Thumbs up 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.

    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.
    Videogame Memories!
    A site dedicated to keeping videogame memories alive!

    http://www.videogamememories.com/
    Share your experiences with us now!

    "We will game forever!"

  2. #2
    Hi ay_okay's Avatar
    Join Date
    Dec 2004
    Location
    Here
    Posts
    69
    For a text based game, I don't think you can really use a different method. Sorry.

  3. #3
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719
    Thats cool. At least I don't have to change anything now.
    Videogame Memories!
    A site dedicated to keeping videogame memories alive!

    http://www.videogamememories.com/
    Share your experiences with us now!

    "We will game forever!"

  4. #4
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    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.
    You're only born perfect.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How can I make this code more elegant?
    By ejohns85 in forum C++ Programming
    Replies: 3
    Last Post: 04-02-2009, 08:55 AM
  2. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 05:42 PM
  3. Replies: 27
    Last Post: 10-11-2006, 04:27 AM
  4. Problems with switch()
    By duvernais28 in forum C Programming
    Replies: 13
    Last Post: 01-28-2005, 10:42 AM
  5. rand()
    By serious in forum C Programming
    Replies: 8
    Last Post: 02-15-2002, 02:07 AM