Thread: another text game question

  1. #1
    Unregistered
    Guest

    another text game question

    hi,

    im also trying to make a text game but its kind of like a "choose your own adventure" type. im using the cout "choose this" thing with if and else statements but i ran into some problems..first, i cant get it to recognize between the if and the else outputs. if i use "if (first == '1')" then whatever input i give it, it tells me the 'if' statement output, but when i use "if(first != '1') then i only get the 'else' statement output. second, whats an easy way to get my game to branch out so if i choose "left" then the game can go this way, but if i choose "right" then it goes this way instead of ending if i choose the wrong way. i used to do this stuff with line code like "goto 100" but now that i have no line numbers i cant seem to get a game plan going (i know..still stuck in the past) any help will be appreciated!

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    129
    Code:
    char c;
    c = getchar();
    if(c == '1')
        do_something();
    else if(c == '2')
        do_something_else();
    else if(c == '3')
        do_something_completely_different();
    else
        printf("Invalid option, you silly\n");
    For the rest you asked, I didn't quite understand...

  3. #3
    Unregistered
    Guest
    thanks for the help. it looks similar to what i tried but maybe i was missing a word or mark. my code is at home so i cant get to check it until later. what i was talking about for the second part was how to get the game to continue in different directions. lets say my output says "choose left or right" then i use the if statements so if you choose "left" then it will bring up another output code so you can make another decision but if you choose "right" then a different output shows up and gives you another decision. i may be able to figure it out but since i couldnt get the first part of the if/then statements to work right i couldnt play around with the rest of it. im trying to make this kind of large so each choice you make brings up another set and the game can go off into several directions. thanks again!

  4. #4
    Unregistered
    Guest
    what i was hoping will work is something like this:

    if char == "left" then
    "choose this"
    if char == "right" then
    "choose another"
    if char == "left" then
    "you lose" end
    else if char == "right" then
    "you win" end
    else if char == "left" then
    "choose again"
    if char == "up" then
    "you win" end
    else if char == "down" then
    "you lose" end
    else if char == "right" then
    "game over" end

    so in other words, can i start off coding the if statements first then follow up with the else statements or do they have to be placed one after another. it may look confusing here but the first cout would say "choose direction" and the if at the top and the else at the bottom would be the ones refering to that question so if you chose left it says "choose this" and another choice needs to be made but if you chose right, it would say "game over". hopefully someone can figure out what im trying to do here. thanks again!

  5. #5
    markv
    Guest
    Hi,

    I also read the choose your own adventure books as a kid. I've been designing a web-based story with the same theme for about a year (an off and on thing).

    I would suggest ditching the attempt to use C or C++ in favor of HTML unless you are genuinely interested in learning more about C... so in other words, if your motivation for writing the choose your own adventure thing is more to find an interesting way to learn the language as opposed to just writing the story.

    If you are interested in writing a game like the old text-based Zork where you pick up items and open doors, there are great tools out there you can use. I can't remember the tool name, but look a the google groups under Interactive Fiction and you're bound to find a reference.

    If you want to stick to designing this thing in C then try posting you code here.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Text based game
    By wipeout4wh in forum C Programming
    Replies: 12
    Last Post: 03-26-2009, 04:39 PM
  2. 20q game problems
    By Nexus-ZERO in forum C Programming
    Replies: 24
    Last Post: 12-17-2008, 05:48 PM
  3. LaTeX Question: Displaying Text and Images
    By Reisswolf in forum Tech Board
    Replies: 0
    Last Post: 06-30-2006, 08:01 AM
  4. Game Engine Link Prob
    By swgh in forum Game Programming
    Replies: 2
    Last Post: 01-26-2006, 12:14 AM
  5. Game Independent Anti-cheat Project Needs Programmers
    By GIA Project Lea in forum Projects and Job Recruitment
    Replies: 3
    Last Post: 09-15-2005, 07:41 PM