Thread: Help with a game?

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    1

    Help with a game?

    I'm a freshman engineering student, and attempting to write a simple game in the C programming language. The basic concept is that of an adventure story; you are given several options to choose from and each option leads you down a different path. I want to create a type of loop so that if a person is to choose an incorrect option, they are able to repeat the previous prompt. I have copied and pasted an excerpt from my code below. How would I proceed to create this type of loop? If you need clarification on what I am trying to do, I will attempt to provide it.



    printf("You enter into a circular room. There are seven doors on the wall.");
    printf(" Which door would you like to enter?\n");
    printf("\n");

    printf("1: Door 1\n");
    printf("2: Door 2\n");
    printf("3: Door 3\n");
    printf("4: Door 4\n");
    printf("5: Door 5\n");
    printf("6: Door 6\n");
    printf("7: Door 7\n");
    printf("\n");

    printf("Which door do you choose?\n");
    printf("\n");
    scanf("%lf", &CHOICE3);

    if (CHOICE3 == 1)
    {
    printf("\n");
    printf("You open Door 1. There is nothing behind it. You leave and go back");
    printf(" to the room with the doors.\n");
    }
    if (CHOICE3 == 2)
    {
    printf("\n");
    printf("You open Door 2. There is a shirtless man behind it. He turns around");
    printf(" and says 'Hello.' You say hi back, and then tell him that");
    printf(" you're leaving now. He says 'Okay.' You leave. How awkward.");
    printf(" You go back to the room with the doors.\n");
    }
    if (CHOICE3 == 3)
    {
    printf("\n");
    printf("You open Door 3. Behind it stands a sphinx, and behind him stands");
    printf(" an archway. He will not let you pass unless you correctly answer");
    printf(" his riddle. The riddle reads:\n");
    printf("\n");
    }



    And thus you get what I'm trying to do. How would I code it so that if the person chose Door 2, they would end up back in the room with the doors?

  2. #2
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Here is a tutorial on loops. There are plenty others if you Google around. You will probably want to use a do-while loop:
    Code:
    do
        print menu
        get input
        open door
    while you want to keep playing

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how do the game engine and the api interact?
    By Shadow12345 in forum Game Programming
    Replies: 9
    Last Post: 12-08-2010, 12:08 AM
  2. Replies: 15
    Last Post: 10-20-2009, 09:39 AM
  3. Open Source / Semi Open source game idea. Help needed
    By CaptainPatent in forum Projects and Job Recruitment
    Replies: 10
    Last Post: 05-16-2007, 10:44 AM
  4. game engine advice?
    By stien in forum Game Programming
    Replies: 0
    Last Post: 01-23-2007, 03:46 PM
  5. My Maze Game --- A Few Questions
    By TechWins in forum Game Programming
    Replies: 18
    Last Post: 04-24-2002, 11:00 PM