Thread: Help With My Text Adventure Game?

  1. #16
    Registered User
    Join Date
    Nov 2012
    Posts
    19
    Quote Originally Posted by nonpuz View Post
    This is probably giving you way too much, but I'm bored so here it is:
    Code:
    #include <stdio.h>
    
    #define MAX_SIZE    20
    
    enum map_tile {
        F,  /* Forest */
        G,  /* Girl */
        W,  /* Water */
        R,  /* Road */
        B   /* Beach */
    };
    
    struct level {
        const enum map_tile map[MAX_SIZE][MAX_SIZE];
    };
    
    struct player {
        int x, y; /* position in level */
    };
    
    static const struct level LEVEL[] = {
        /* LEVEL 1 */
        {
            {{ F, F, F, G, F, B, B, B, W },
             { F, R, R, F, R, B, B, B, W },
             { F, R, R, R, R, F, F, B, W },
             { F, R, F, F, B, B, B, B, W }}
        }
        /* LEVEL 2 etc ... */
    };
    
    
    int main(void)
    {
        struct player player1 = {0}; /* start at top-left 0,0 */
        unsigned char move;
    
        /* aquire key input into move  */
    
        switch (move) {
            case NORTH:
                /* bounds checking omitted */
                ++player1.y;
                break;
            case SOUTH:
                /* bounds checking omitted */
                --player1.y;
                break;
            case EAST:
                /* bounds checking omitted */
                ++player1.x;
                break;
            case WEST:
                /* bounds checking omitted */
                --player1.x;
                break;
            default:
                /* invalid input */
        }
    
        /* now you use the coordinates of player (x, y) in the LEVEL[0].map to find out where he is in the level */
    
        return 0;
    }
    Wow thanks for the help If I only want the map to be half the size in width as yours what would I need to changed the define max size to? Also how would I use the coordinates? Like if player 1 == 0,1? And I put the Switch func in a loop right? And are there supposed to be semi colons after some the bracets {}? Sorry if I really sound like a noob cuz im not really 100% sure how i would merge my program into this :P

    I want the map to look like this:
    Code:
    static const struct level LEVEL[] = {    /* LEVEL 1 */
        {
            {{ F, F, G, B, W },
             { F, R, R, R, W },
             { F, R, C, C, W },
             { Z, R, C, C, W }}
        }
    };
    Last edited by evilcubed; 12-02-2012 at 08:03 AM.

  2. #17
    Registered User
    Join Date
    Nov 2012
    Posts
    19
    ugg still stuck, not sure what to do :P

  3. #18
    Ultraviolence Connoisseur
    Join Date
    Mar 2004
    Posts
    555
    To use the player on the map you would probably want to do something like this:
    Code:
    switch(LEVEL[0].map[player.y][player.x]) {
        case F:
            printf("You are in the forest. ");
            break;
        case R:
            printf("You are on a dirt road. ");
            break;
        case W:
            printf("You're in the water! Better go back!");
            break;
        case B:
            printf("You are on the beach. ");
            break;
        case G:
            printf("You see a pretty girl smiling at you. ");
            break;
    
        default:
            /* invalid tile value */
    }
    This is an extremely simple example. You would most likely want to use a separate function to generate the printf() message that may also include checking the neighboring tiles (x+1, x-1, y+1, y-1 ensuring to again do bounds checking) and state what is to the "east, west, north and south" as well. Example: "You are on a dirt road. To the east is the forest. To the west is the girl. To the south is the Beach. To the North is the forest."

    Then you could go a step further and do things like, if the player has Forest on all sides of him, instead of printing "north south east west blah blah" just print "You are surrounded by forest." This is why you want a function as the logic grows more complex instead of having everything in the switch statement.

    As far as changing the size of the map, you dont need to change MAX_SIZE to do that. MAX_SIZE is the MAXIMUM size you can have the map (20x20 in the code above). You can certainly initialize with smaller map without changing MAX_SIZE.

  4. #19
    Registered User
    Join Date
    Nov 2012
    Posts
    19
    could i just make each square on the map a different character, like a,b,c etc and have a case for every character, so i dont have like the same description for forest each time i land on the forest square?

  5. #20
    Registered User
    Join Date
    Nov 2012
    Posts
    19
    I haven't started to make my program simplier with the char map, since i wanted to finish the base program. Here it is. Im pretty sure i can cut the code down by alot, any tips to do so?
    Code:
    #ifdef __unix__
    #include <unistd.h>
    #elif defined _WIN32
    #include <stdio.h>
    #include <stdlib.h>
    #include <windows.h>
    #define sleep(x) Sleep(1000 * x)
    #endif
    char character = 'q';
    int main()
    {
        system("cls");
        printf (" __            ___________    ___________    _____________ \n|  |          |           |  |           |  |             |\n|  |          |    ___    |  |    _______|  |____     ____|\n|  |          |   |   |   |  |   |_______        |   |     \n|  |          |   |   |   |  |_______    |       |   |     \n|  |_______   |   |___|   |   _______|   |       |   |     \n|          |  |           |  |           |       |   |     \n|__________|  |___________|  |___________|       |___|     ©\n");
        sleep(1);
        printf ("Press Any Key And Enter To Start.\nPress X To Exit.\n");
        character = getchar();
        getchar();
        while (character != 'x')
        {
            if (character != '\n')
            {
                system("cls");
                printf ("You are lost in the forest.\nYou can only move forward, backwards, left, and right.\nHere are the controls: 8-Up, 2-Down, 4-Left, 6-Right.\nWhat do you do?\n");
                character = getchar();
                getchar();
                if (character == '8')        //Up
                {
                    system("cls");
                    printf ("Walking...\n");
                    sleep(1);
                    system("cls");
                    printf ("You see an abandoned castle.\n");
                    character = getchar();
                    getchar();
                    if (character == '8')      //Up
                    {
                        system("cls");
                        printf ("Walking...\n");
                        sleep(1);
                        system("cls");
                        printf ("You enter the abandonded castle.\n");
                        character = getchar();
                        getchar();
                        if (character == '8')        //Up
                        {
                            system("cls");
                            printf ("Walking...\n");
                            sleep(1);
                            system("cls");
                            printf ("You see a big window.\n");
                            character = getchar();
                            getchar();
                            if (character == '8')        //Up
                            {
                                system("cls");
                                printf ("Walking...\n");
                                sleep(1);
                                system("cls");
                                printf ("You cannot go through the window silly.\n");
                                character = getchar();
                                getchar();
                                if (character == '8')        //Up
                                {
                                    system("cls");
                                    printf ("Walking...\n");
                                    sleep(1);
                                    system("cls");
                                    printf ("You cannot go through the window silly.\n");
                                    character = getchar();
                                    getchar();
                                }
                                if (character == '2')        //Up
                                {
                                    system("cls");
                                    printf ("Walking...\n");
                                    sleep(1);
                                    system("cls");
                                    printf ("Unfortunatly, the butler of the castle thinks your trespassing and knocks you unconcious.\n");
                                    sleep(2);
                                    system("cls");
                                    printf ("Game Over\n");
                                    sleep(1);
                                    system("cls");
                                    return 0;
                                }
                            }
                            if (character == '2')        //Down
                            {
                                system("cls");
                                printf ("Walking...\n");
                                sleep(1);
                                system("cls");
                                printf ("You fall through a trap door that was triggered when you entered.\n");
                                sleep(2);
                                system("cls");
                                printf ("Game Over\n");
                                sleep(1);
                                return 0;
                            }
                            if (character == '4')        //Left
                            {
                                    system("cls");
                                    printf ("Walking...\n");
                                    sleep(1);
                                    system("cls");
                                    printf ("There is a table blocking your way.\n");
                                    character = getchar();
                                    getchar();
                                    while (character == '4')
                                    {
                                        system("cls");
                                        printf ("Walking...\n");
                                        sleep(1);
                                        system("cls");
                                        printf ("There is a table blocking your way.\n");
                                        character = getchar();
                                        getchar();
                                    }
    
    
                            }
                            if (character == '6')        //Right
                            {
                                    system("cls");
                                    printf ("Walking...\n");
                                    sleep(1);
                                    system("cls");
                                    printf ("There is a wall blocking your way.\n");
                                    character = getchar();
                                    getchar();
                                    while (character == '6')
                                    {
                                        system("cls");
                                        printf ("Walking...\n");
                                        sleep(1);
                                        system("cls");
                                        printf ("There is a wall blocking your way.\n");
                                        character = getchar();
                                        getchar();
                                    }
    
    
                            }
                        }
                        if (character == '2')        //Down
                        {
                            system("cls");
                            printf ("Walking...\n");
                            sleep(1);
                            system("cls");
                            printf ("You fall through a trap door that was triggered when you entered.\n");
                            sleep(2);
                            system("cls");
                            printf ("Game Over\n");
                            sleep(1);
                            return 0;
                        }
                        if (character == '4')        //Left
                        {
                            system("cls");
                            printf ("Walking...\n");
                            sleep(1);
                            system("cls");
                            printf ("You see a staircase.\n");
                            character = getchar();
                            getchar();
                            if (character == '8')        //Up
                            {
                                system("cls");
                                printf ("Walking...\n");
                                sleep(1);
                                system("cls");
                                printf ("There is a wall.\n");
                                character = getchar();
                                getchar();
                            }
                            if (character == '2')        //Down
                            {
                                system("cls");
                                printf ("Walking...\n");
                                sleep(1);
                                system("cls");
                                printf ("There is a wall.\n");
                                character = getchar();
                                getchar();
                            }
                            if (character == '4')        //Left
                            {
                                system("cls");
                                printf ("Walking...\n");
                                sleep(1);
                                system("cls");
                                printf ("You climb up the stair case.\n");
                                character = getchar();
                                getchar();
                                if (character == '8')        //Up
                                {
                                    system("cls");
                                    printf ("Walking...\n");
                                    sleep(1);
                                    system("cls");
                                    printf ("You see an old bookshelf.\n");
                                    character = getchar();
                                    getchar();
                                    if (character == '8')        //Up
                                    {
                                        system("cls");
                                        printf ("Walking...\n");
                                        sleep(1);
                                        system("cls");
                                        printf ("There is nothing special about this bookshelf.\n");
                                        character = getchar();
                                        getchar();
                                    }
                                }
                                if (character == '2')        //Down
                                {
                                    system("cls");
                                    printf ("Walking...\n");
                                    sleep(1);
                                    system("cls");
                                    printf ("You see an old phone.\n");
                                    character = getchar();
                                    getchar();
                                    if (character == '8')        //Up
                                    {
                                        system("cls");
                                        printf ("Walking...\n");
                                        sleep(1);
                                        system("cls");
                                        printf ("You arrive back to the top of the staircase.\n");
                                        character = getchar();
                                        getchar();
                                    }
                                    if (character == '2')        //Down
                                    {
                                        system("cls");
                                        printf ("Walking...\n");
                                        sleep(1);
                                        system("cls");
                                        printf ("You call for help, and the military sends a helicopter to rescue you.\n");
                                        sleep(1);
                                        printf ("You Have Escaped!\nCongratulations!\n");
                                        sleep(2);
                                        printf ("Your prize is the sense of accomplishment.\n");
                                        sleep(2);
                                        system("cls");
                                        printf ("Thank you for playing.\nGoodbye...");
                                        sleep(1);
                                        return 0;
                                    }
                                    if (character == '4')        //Left
                                    {
                                        system("cls");
                                        printf ("Walking...\n");
                                        sleep(1);
                                        system("cls");
                                        printf ("There is nothing here.\n");
                                        character = getchar();
                                        getchar();
                                        if (character == '4')        //Left
                                        {
                                            system("cls");
                                            printf ("Walking...\n");
                                            sleep(1);
                                            system("cls");
                                            printf ("Upon closer inspection, there is nothing here.\n");
                                            character = getchar();
                                            getchar();
                                        }
                                    if (character == '6')        //Right
                                    {
                                        system("cls");
                                        printf ("Walking...\n");
                                        sleep(1);
                                        system("cls");
                                        printf ("There is a couch.\n");
                                        character = getchar();
                                        getchar();
                                        if (character == '6')        //Right
                                        {
                                            system("cls");
                                            printf ("Walking...\n");
                                            sleep(1);
                                            system("cls");
                                            printf ("There is nothing special about the couch.\n");
                                            character = getchar();
                                            getchar();
                                        }
                                    }
                                }
                                if (character == '4')        //Left
                                {
                                    system("cls");
                                    printf ("Walking...\n");
                                    sleep(1);
                                    system("cls");
                                    printf ("There is a wall.\n");
                                    character = getchar();
                                    getchar();
                                    if (character == '4')        //Left
                                    {
                                        system("cls");
                                        printf ("Walking...\n");
                                        sleep(1);
                                        system("cls");
                                        printf ("There is a nothing special about the wall.\n");
                                        character = getchar();
                                        getchar();
                                    }
                                }
                                if (character == '6')        //Right
                                {
                                    system("cls");
                                    printf ("Walking...\n");
                                    sleep(1);
                                    system("cls");
                                    printf ("You climb down the staircase.\n");
                                    character = getchar();
                                    getchar();
                                }
                            }
                            if (character == '6')        //Right
                            {
                                system("cls");
                                printf ("Walking...\n");
                                sleep(1);
                                system("cls");
                                printf ("You arrive back to where you entered.\n");
                                character = getchar();
                                getchar();
                            }
                        }
                        if (character == '6')        //Right
                        {
                            system("cls");
                            printf ("Walking...\n");
                            sleep(1);
                            system("cls");
                            printf ("You see a old painting.\n");
                            character = getchar();
                            getchar();
                            if (character == '6')        //Right
                            {
                                system("cls");
                                printf ("Walking...\n");
                                sleep(1);
                                system("cls");
                                printf ("There is nothing special about the old painting.\n");
                                character = getchar();
                                getchar();
                            }
                        }
                    }
                    if (character == '2')        //Down
                    {
                        system("cls");
                        printf ("Walking...\n");
                        sleep(1);
                        system("cls");
                        printf ("Unfortunatly the rescue helicopter that was comming for you crashes into you and kills you.\n");
                        sleep(2);
                        system("cls");
                        printf ("Game Over\n");
                        sleep(1);
                        system("cls");
                        return 0;
                    }
                    if (character == '4')        //Left
                    {
                        system("cls");
                        printf ("Walking...\n");
                        sleep(1);
                        system("cls");
                        printf ("There is a danger sign blocking your way.\n");
                        character = getchar();
                        getchar();
                        if (character == '4')        //Left
                        {
                            system("cls");
                            printf ("Walking...\n");
                            sleep(1);
                            system("cls");
                            printf ("A train runs you over. Didn't you see the danger sign?\n");
                            sleep(2);
                            system("cls");
                            printf ("Game Over\n");
                            sleep(1);
                            system("cls");
                            return 0;
                        }
                    }
                    if (character == '6')        //Right
                    {
                        system("cls");
                        printf ("Walking...\n");
                        sleep(1);
                        system("cls");
                        printf ("There is a merchant.\n");
                        character = getchar();
                        getchar();
                        if (character == '6')        //Right
                        {
                            system("cls");
                            printf ("Walking...\n");
                            sleep(1);
                            system("cls");
                            printf ("He offers you a ride back to town.\n");
                            character = getchar();
                            getchar();
                            if (character == '6')        //Right
                            {
                                system("cls");
                                printf ("Walking...\n");
                                sleep(1);
                                system("cls");
                                printf ("It was a trap. He kidnaps you and holds you hostage.\n");
                                sleep(2);
                                system("cls");
                                printf ("Game Over\n");
                                sleep(1);
                                system("cls");
                                return 0;
                            }
                            if (character == '4')        //Right
                            {
                                system("cls");
                                printf ("Walking...\n");
                                sleep(1);
                                system("cls");
                                printf ("The merchant was actually a bounty hunter and holds you hostage.\n");
                                sleep(2);
                                system("cls");
                                printf ("Game Over\n");
                                sleep(1);
                                system("cls");
                                return 0;
                            }
                        }
                        if (character == '4')        //Right
                        {
                            system("cls");
                            printf ("Walking...\n");
                            sleep(1);
                            system("cls");
                            printf ("Are you sure you want to disrespect the merchant and walk away?\n");
                            character = getchar();
                            getchar();
                            if (character == '6')        //Right
                            {
                                system("cls");
                                printf ("Walking...\n");
                                sleep(1);
                                system("cls");
                                printf ("It was a trap. He kidnaps you and holds you hostage.\n");
                                sleep(2);
                                system("cls");
                                printf ("Game Over\n");
                                sleep(1);
                                system("cls");
                                return 0;
                            }
                            if (character == '4')        //Right
                            {
                                system("cls");
                                printf ("Walking...\n");
                                sleep(1);
                                system("cls");
                                printf ("The merchant was offended and killed you.\n");
                                sleep(2);
                                system("cls");
                                printf ("Game Over\n");
                                sleep(1);
                                system("cls");
                                return 0;
                            }
                        }
                    }
                }
                if (character == '2')        //Down
                {
                    system("cls");
                    printf ("Walking...\n");
                    sleep(1);
                    system("cls");
                    printf ("You see a crowd of %d zombies.\n", rand());
                    character = getchar();
                    getchar();
                    if (character == '8')      //Up
                    {
                        system("cls");
                        printf ("Walking...\n");
                        sleep(1);
                        system("cls");
                        printf ("The zombies eat you.\n");
                        sleep(1);
                        system("cls");
                        printf ("Game Over\n");
                        sleep(1);
                        break;
                    }
                    if (character == '2')        //Down
                    {
                        system("cls");
                        printf ("Walking...\n");
                        sleep(1);
                        system("cls");
                        printf ("You try and run away but the zombies eat you.\n");
                        sleep(1);
                        system("cls");
                        printf ("Game Over\n");
                        sleep(1);
                        break;
                    }
                    if (character == '4')        //Left
                    {
                        system("cls");
                        printf ("Walking...\n");
                        sleep(1);
                        system("cls");
                        printf ("The zombies eat you.\n");
                        sleep(1);
                        system("cls");
                        printf ("Game Over\n");
                        sleep(1);
                        break;
                    }
                    if (character == '6')        //Right
                    {
                        system("cls");
                        printf ("Walking...\n");
                        sleep(1);
                        system("cls");
                        printf ("The zombies eat you.\n");
                        sleep(1);
                        system("cls");
                        printf ("Game Over\n");
                        sleep(1);
                        break;
                    }
                }
                if (character == '4')        //Left
                {
                    system("cls");
                    printf ("Walking...\n");
                    sleep(1);
                    system("cls");
                    printf ("You see a hot girl. \n");
                    character = getchar();
                    getchar();
                    if (character == '4')       //Up
                    {
                        system("cls");
                        printf ("Walking...\n");
                        sleep(1);
                        system("cls");
                        printf ("She sleeps with you and steals all your money.\n");
                        sleep(2);
                        system("cls");
                        printf ("Game Over\n");
                        sleep(1);
                        break;
                    }
                    if (character != '4')       //Down
                    {
                        while (1)
                        {
                            if (character == '8')        //Up
                            {
                                system("cls");
                                printf ("Walking...\n");
                                sleep(1);
                                system("cls");
                                printf ("She slaps you for walking away.\n");
                            }
                            else if (character == '2')        //Down
                            {
                                system("cls");
                                printf ("Walking...\n");
                                sleep(1);
                                system("cls");
                                printf ("She slaps you for walking away.\n");
                            }
                            else if (character == '4')        //Left
                            {
                                system("cls");
                                printf ("Walking...\n");
                                sleep(1);
                                system("cls");
                                printf ("She slaps you for walking away.\n");
                            }
                            else if (character == '6')        //Right
                            {
                                system("cls");
                                printf ("Walking...\n");
                                sleep(1);
                                system("cls");
                                printf ("She slaps you for walking away.\n");
                            }
                            if (character == 'x')        //Exit
                            {
                                system("cls");
                                printf ("Goodbye...\n");
                                sleep(1);
                                system("cls");
                                return 0;
                            }
                            character = getchar();
                        }
                    }
                }
                if (character == '6')        //Right
                {
                    system("cls");
                    printf ("Walking...\n");
                    sleep(1);
                    system("cls");
                    printf ("You see a Lake.\n");
                    character = getchar();
                    getchar();
                    if (character == '6')       //Right
                    {
                        system("cls");
                        printf ("Walking...\n");
                        sleep(1);
                        system("cls");
                        printf ("You jump into the lake. You think you can swim across to saftey.\n");
                        character = getchar();
                        getchar();
                        if (character == '6')        //Right
                        {
                            system("cls");
                            printf ("Walking...\n");
                            sleep(1);
                            system("cls");
                            printf ("You try to swim but you drown.\n");
                            sleep(1);
                            system("cls");
                            printf ("Game Over\n");
                            sleep(1);
                            break;
                        }
                        if (character == '2')        //Down
                        {
                            system("cls");
                            printf ("Walking...\n");
                            sleep(1);
                            system("cls");
                            printf ("You cant climb out of the water.\n");
                            character = getchar();
                            getchar();
                            if (character == '6')        //Right
                            {
                                system("cls");
                                printf ("Walking...\n");
                                sleep(1);
                                system("cls");
                                printf ("You try to swim but you drown.\n");
                                sleep(1);
                                system("cls");
                                printf ("Game Over\n");
                                sleep(1);
                                break;
                            }
                        }
                        if (character == '4')        //Left
                        {
                            system("cls");
                            printf ("Walking...\n");
                            sleep(1);
                            system("cls");
                            printf ("You cant climb out of the water.\n");
                            character = getchar();
                            getchar();
                            if (character == '6')        //Right
                            {
                                system("cls");
                                printf ("Walking...\n");
                                sleep(1);
                                system("cls");
                                printf ("You try to swim but you drown.\n");
                                sleep(1);
                                system("cls");
                                printf ("Game Over\n");
                                sleep(1);
                                break;
                            }
                        }
                        if (character == '8')        //Up
                        {
                            system("cls");
                            printf ("Walking...\n");
                            sleep(1);
                            system("cls");
                            printf ("You cant climb out of the water.\n");
                            character = getchar();
                            getchar();
                            if (character == '6')        //Right
                            {
                                system("cls");
                                printf ("Walking...\n");
                                sleep(1);
                                system("cls");
                                printf ("You try to swim but you drown.\n");
                                sleep(1);
                                system("cls");
                                printf ("Game Over\n");
                                sleep(1);
                                break;
                            }
                        }
                        //else
                        //{
                        //printf("That is an unknown command.\n");
                        //sleep(1);
                        //}
                    }
                    if (character == '4')        //Down
                    {
                        system("cls");
                        printf ("Walking...\n");
                        sleep(1);
                        system("cls");
                        printf ("Unfortunatly a bear eats you on the way back.\n");
                        sleep(2);
                        system("cls");
                        printf ("Game Over\n");
                        sleep(1);
                        system("cls");
                        return 0;
                    }
                    if (character == '2')        //Left
                    {
                        system("cls");
                        printf ("Walking...\n");
                        sleep(1);
                        system("cls");
                        printf ("There is a fence blocking your way.\n");
                        character = getchar();
                        getchar();
                        if (character == '6')       //Right
                        {
                            system("cls");
                            printf ("Walking...\n");
                            sleep(1);
                            system("cls");
                            printf ("You jump into the lake. You think you can swim across to saftey.\n");
                            character = getchar();
                            getchar();
                            if (character == '6')        //Right
                            {
                                system("cls");
                                printf ("Walking...\n");
                                sleep(1);
                                system("cls");
                                printf ("You try to swim but you drown.\n");
                                sleep(1);
                                system("cls");
                                printf ("Game Over\n");
                                sleep(1);
                                break;
                            }
                            if (character == '2')        //Down
                            {
                                system("cls");
                                printf ("Walking...\n");
                                sleep(1);
                                system("cls");
                                printf ("You cant climb out of the water.\n");
                                character = getchar();
                                getchar();
                                if (character == '6')        //Right
                                {
                                    system("cls");
                                    printf ("Walking...\n");
                                    sleep(1);
                                    system("cls");
                                    printf ("You try to swim but you drown.\n");
                                    sleep(1);
                                    system("cls");
                                    printf ("Game Over\n");
                                    sleep(1);
                                    break;
                                }
                            }
                            if (character == '4')        //Left
                            {
                                system("cls");
                                printf ("Walking...\n");
                                sleep(1);
                                system("cls");
                                printf ("You cant climb out of the water.\n");
                                character = getchar();
                                getchar();
                                if (character == '6')        //Right
                                {
                                    system("cls");
                                    printf ("Walking...\n");
                                    sleep(1);
                                    system("cls");
                                    printf ("You try to swim but you drown.\n");
                                    sleep(1);
                                    system("cls");
                                    printf ("Game Over\n");
                                    sleep(1);
                                    break;
                                }
                            }
                            if (character == '8')        //Up
                            {
                                system("cls");
                                printf ("Walking...\n");
                                sleep(1);
                                system("cls");
                                printf ("You cant climb out of the water.\n");
                                character = getchar();
                                getchar();
                                if (character == '6')        //Right
                                {
                                    system("cls");
                                    printf ("Walking...\n");
                                    sleep(1);
                                    system("cls");
                                    printf ("You try to swim but you drown.\n");
                                    sleep(1);
                                    system("cls");
                                    printf ("Game Over\n");
                                    sleep(1);
                                    break;
                                }
                        }
                        if (character == '2')        //Down
                        {
                            system("cls");
                            printf ("Walking...\n");
                            sleep(1);
                            system("cls");
                            printf ("Unfortunatly a bear eats you on the way back.\n");
                            sleep(2);
                            system("cls");
                            printf ("Game Over\n");
                            sleep(1);
                            system("cls");
                            return 0;
                        }
                    }
                    }
                    if (character == '8')        //Right
                    {
                        system("cls");
                        printf ("Walking...\n");
                        sleep(1);
                        system("cls");
                        printf ("There is a fence blocking your way.\n");
                        character = getchar();
                        getchar();
                        if (character == '6')       //Right
                        {
                            system("cls");
                            printf ("Walking...\n");
                            sleep(1);
                            system("cls");
                            printf ("You jump into the lake. You think you can swim across to saftey.\n");
                            character = getchar();
                            getchar();
                            if (character == '6')        //Right
                            {
                                system("cls");
                                printf ("Walking...\n");
                                sleep(1);
                                system("cls");
                                printf ("You try to swim but you drown.\n");
                                sleep(1);
                                system("cls");
                                printf ("Game Over\n");
                                sleep(1);
                                break;
                            }
                            if (character == '2')        //Down
                            {
                                system("cls");
                                printf ("Walking...\n");
                                sleep(1);
                                system("cls");
                                printf ("You cant climb out of the water.\n");
                                character = getchar();
                                getchar();
                                if (character == '6')        //Right
                                {
                                    system("cls");
                                    printf ("Walking...\n");
                                    sleep(1);
                                    system("cls");
                                    printf ("You try to swim but you drown.\n");
                                    sleep(1);
                                    system("cls");
                                    printf ("Game Over\n");
                                    sleep(1);
                                    break;
                                }
                            }
                            if (character == '4')        //Left
                            {
                                system("cls");
                                printf ("Walking...\n");
                                sleep(1);
                                system("cls");
                                printf ("You cant climb out of the water.\n");
                                character = getchar();
                                getchar();
                                if (character == '6')        //Right
                                {
                                    system("cls");
                                    printf ("Walking...\n");
                                    sleep(1);
                                    system("cls");
                                    printf ("You try to swim but you drown.\n");
                                    sleep(1);
                                    system("cls");
                                    printf ("Game Over\n");
                                    sleep(1);
                                    break;
                                }
                            }
                            if (character == '8')        //Up
                            {
                                system("cls");
                                printf ("Walking...\n");
                                sleep(1);
                                system("cls");
                                printf ("You cant climb out of the water.\n");
                                character = getchar();
                                getchar();
                                if (character == '6')        //Right
                                {
                                    system("cls");
                                    printf ("Walking...\n");
                                    sleep(1);
                                    system("cls");
                                    printf ("You try to swim but you drown.\n");
                                    sleep(1);
                                    system("cls");
                                    printf ("Game Over\n");
                                    sleep(1);
                                    break;
                                }
                            }
                        }
                        if (character =='4')
                        {
                            system("cls");
                            printf ("Walking...\n");
                            sleep(1);
                            system("cls");
                            printf ("Unfortunatly a bear eats you on the way back.\n");
                            sleep(2);
                            system("cls");
                            printf ("Game Over\n");
                            sleep(1);
                            system("cls");
                            return 0;
                        }
                    }
                    //else
                    //{
                    //    printf("That is an unknown command.\n");
                    //    sleep(1);
                    //}
                }
            }
        }
        system("cls");
        printf ("Goodbye...\n");
        sleep(1);
        system("cls");
        return 0;
    }

  6. #21
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Im pretty sure i can cut the code down by alot, any tips to do so?
    Continue on your journey of learning. When you learn some new topics (such as arrays and functions), revisit this program and you'll see yourself where you can cut down the code. We can offer many suggestions, but until you understand those concepts, you won't be able to implement them. This is probably as good as you're going to do with your current knowledge.

    As someone who made many console "adventure" programs on my own learning journey, I can assure you of the following:

    - What you've done so far has served an important purpose - you found a fun way to practice the skills you have already learned.

    - As your skills improve, you can take this idea and build on it in ways you won't even expect. More possibilities will open before your eyes, giving you a chance to exercise the further knowledge you've attained.

    If you're passionate about programming (and it would seem you are), then don't let yourself get too bogged down on any one practice program while you're still new. Take what you can from it, and bring that with you to the next level. And I promise you it will only get better from there.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Text based adventure game.
    By Luminous Lizard in forum C++ Programming
    Replies: 15
    Last Post: 01-06-2012, 11:53 AM
  2. Text adventure game GUI
    By VirtualAce in forum Game Programming
    Replies: 11
    Last Post: 11-07-2007, 06:34 PM
  3. Help with my text adventure game.
    By Haggarduser in forum Game Programming
    Replies: 15
    Last Post: 10-26-2007, 01:53 AM
  4. text adventure game
    By linucksrox in forum Game Programming
    Replies: 18
    Last Post: 07-27-2006, 01:36 PM
  5. Please help (Text Adventure Game)
    By C++angel in forum C++ Programming
    Replies: 9
    Last Post: 02-23-2006, 04:33 PM