Jump to content
  • Advertisement
Sign in to follow this  
Vegetable411

First game error

This topic is 4887 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Been coding a text adventure game like Zork. It's my first attempt at any programming. I've been coding a maze, and I have a problem with one of my dead ends (d7). It's the one with the rope. When I try to go back to the fork I came from (f2), it says I've gone back, but I'm still at the dead end (d7). If anyone could tell me what I've done wrong, it would help a lot. If you have any suggestions on how I could improve/clean up the code in areas, that would be helpful as well. Thanks.
#include <stdio.h>
#include <iostream.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
  int intro=0;
  int intro2=0;
  int scene1=0;
  int scene2=0;
  int scene3=0;
  int scene4=0;
  int scene5=0;
  int boxopen=0;
  int holeopen=0;
  int maze=0;
  int gotrocks=0;
  int b=0;
  int d1=0;
  int d2=0;
  int d3=0;
  int d4=0;
  int d5=0;
  int d6=0;
  int d7=0;
  int f1=0;
  int f2=0;
  int f3=0;
  int f4=0;
  int rope=0;
  int hook=0;
  int mazefinish=0;
  int red1=0;
  int blue2=0;
  int green3=0;
  int yellow4=0;
  int gameover=0;
  char password[50];

//----intro---//
  if (intro==0)

     {
     cout<<"You find yourself sitting up against a wall in a white, almost empty room with\na throbbing headache. There's a small red button sitting in the middle of the \nwall opposite you."<<endl;
     intro = 1;
     }

     else
       cin.getline (password,100);

//---first-room---//
  while(scene1!=1)
  {
     cin.getline (password,100);

     if(strcmp(password,"press button")==0)
       {
       scene1=1;
       }

     else if(strcmp(password,"press the button")==0)
       {
       scene1=1;
       }

     else if(strcmp(password,"look at button")==0)
       {
       cout<<"The button is small. A bit bigger than a quarter.\n";
       }

     else if(strcmp(password,"examine button")==0)
       {
       cout<<"The button is small. A bit bigger than a quarter.\n";
       }

     else if(strcmp(password,"press it")==0)
       {
       scene1=1;
       }

     else if(strcmp(password,"push button")==0)
       {
       scene1=1;
       }

     else if(strcmp(password,"push it")==0)
       {
       scene1=1;
       }

     else if(strcmp(password,"push the button")==0)
       {
       scene1=1;
       }

     else if(strcmp(password,"fart")==0)
       cout<<"You make sure nobody is looking, and do a beefy, almost manly fart. Smells like brocolli.\n";

     else
       cout<<"You can't " << password <<" right now!\n";

  }
//---second-room---//

  if (intro2!=1)
      {
      system("CLS");
      cout << "You walk over to the button and press it. The corner to your right opens outwards, revealing a blue room with a corridor in it. You walk into the room.\n";
      cout << "In the room, you see a man that looks like Jesus, holding a candle in the shape of a cross. He asks you to follow him. Will you?";
      intro2=1;
      }

      else
      cin.getline (password,100);

  while(scene2!=1)
  {
       cin.getline (password,100);

       if(strcmp(password,"yes")==0)
         {
         system("CLS");
         cout<<"You follow the man down the corridor. You reach a bend, which goes down a flight of stairs. On the way down, you notice that the man's legs are hairy.\n";
         cout<<"You finally reach the bottom of the stairs, which open into another room. The room is, maybe twenty feet deep, and fifteen feet wide, with soft green carpet. The walls are lined with columns, and situated on them, are small statues.\n";
         scene2=1;
         }

       else if(strcmp(password,"no")==0)
         {
         cout<<"The man suddenly breaks into tears and runs down the corridor, crying.\n";
         gameover=1;
         }

       else
         cout<<"You can't " << password <<" right now!\n";

       if (gameover==1)
         {
         cout<<"Gameover.";
         system("PAUSE");
         return EXIT_SUCCESS;
         }

  }
//---third-room---//

  while (scene3!=1)
    {
       cin.getline (password,100);

       if (strcmp(password,"examine statues")==0)
         cout<<"They're about a foot high, and they look exactly like the armor you would find in medieval times. One of the statues is holding a sword upright infront of itself, it seems to be loose\n";

       else if (strcmp(password,"look at statues")==0)
         cout<<"They're about a foot high, and they look exactly like the armor you would find in medieval times. One of the statues is holding a sword upright infront of itself, it seems to be loose\n";

       else if (strcmp(password,"push sword")==0)
         cout<<"It won't budge. Maybe if you rotate it?\n";

       else if (strcmp(password,"take sword")==0)
         cout<<"It's not that loose!\n";

       else if (strcmp(password,"hold sword")==0)
         cout<<"It's not that loose!\n";

       else if (strcmp(password,"take sword")==0)
         cout<<"You grab the sword, but you can't remove it from the statue's hands.\n";

       else if (strcmp(password,"pull sword")==0)
         cout<<"It won't budge. Maybe if you rotate it?\n";

       else if (strcmp(password,"jiggle sword")==0)
         cout<<"It won't budge. Maybe if you rotate it?\n";

       else if (strcmp(password,"rotate sword")==0)
         {
          system("CLS");
          cout<<"You rotate the sword, and the statue flips over into a trapdoor, revealing on the other side, a small, wooden box.\n";
          scene3=1;
         }

       else
         cout<<"You can't " << password <<" right now!\n";

     }
//---third-room-box---//
  while (scene4!=1)
     {
        cin.getline (password,100);

        if (strcmp(password,"open box")==0)
          {
          cout<<"You open the box, and there's a circular object inside.\n";
          boxopen=1;
          }

       else if (strcmp(password,"open the box")==0)
          {
          cout<<"You open the box, and there's a circular object inside.\n";
          boxopen=1;
          }

       else if (strcmp(password,"examine the box")==0)
          cout<<"The box is simplistic, it looks as if it were made by an amateur carpenter. It's size is similar to that of a jewellry case, and there's a strange symbol on the top.\n";

       else if (strcmp(password,"examine box")==0)
          cout<<"The box is simplistic, it looks as if it were made by an amateur carpenter. It's size is similar to that of a jewellry case, and there's a strange symbol on the top.\n";

       else if (strcmp(password,"look at the box")==0)
          cout<<"The box is simplistic, it looks as if it were made by an amateur carpenter. It's size is similar to that of a jewellry case, and there's a strange symbol on the top.\n";

       else if (strcmp(password,"look at box")==0)
          cout<<"The box is simplistic, it looks as if it were made by an amateur carpenter. It's size is similar to that of a jewellry case, and there's a strange symbol on the top.\n";

//---the if (boxopen==1) statement checks if the box has been opened, and then acts accordingly---//

       else if (strcmp(password,"look at object")==0)
          {
          if (boxopen==1)
             cout<<"It's a round, convex object, with four buttons on the front, each a different color. Red, yellow, blue, green.\n";

          else
             cout<<"You can't "<< password <<" right now!";
          }

       else if (strcmp(password,"examine object")==0 || strcmp(password,"look at object")==0)
          {
          if (boxopen==1)
             cout<<"It's a round, convex object, with four buttons on the front, each a different color. Red, yellow, blue, green. Looks like a puzzle.\n";
          }
             if (strcmp(password,"press red button")==0 || strcmp(password,"press red")==0 || strcmp(password,"push red button")==0 || strcmp(password,"push red")==0)
                {
                if (boxopen==1 && red1==0 && blue2==0 && green3==0 && yellow4==0)
                  {
                  cout<<"You press the red button, and hear a bolt click into place.\n";
                  red1=1;
                  }

                else
                  {
                  cout<<"You press the red button, and you hear a loud click.\n";
                  red1=0;
                  blue2=0;
                  green3=0;
                  yellow4=0;
                  }
                }

             else if (strcmp(password,"press blue button")==0 || strcmp(password,"press blue")==0 || strcmp(password,"push blue")==0 || strcmp(password,"push blue button")==0)
                {
                if (boxopen==1 && red1==1 && blue2==0 && green3==0 && yellow4==0)
                  {
                  cout<<"You press the blue button, and hear a bolt click into place.\n";
                  blue2=1;
                  }
                else
                  {
                  cout<<"You press the blue button, and you hear a loud click.\n";
                  red1=0;
                  blue2=0;
                  green3=0;
                  yellow4=0;
                  }
                }

             else if (strcmp(password,"press green button")==0 || strcmp(password,"press green")==0 || strcmp(password,"push green button")==0 || strcmp(password,"push green")==0)
                {
                if (boxopen==1 && red1==1 && blue2==1 && green3==0 && yellow4==0)
                  {
                  cout<<"You press the green button, and hear a bolt click into place.\n";
                  green3=1;
                  }
                else
                  {
                  cout<<"You press the green button, and you hear a loud click.\n";
                  red1=0;
                  blue2=0;
                  green3=0;
                  yellow4=0;
                  }
                }

             else if (strcmp(password,"press yellow button")==0 || strcmp(password,"press yellow")==0 || strcmp(password,"push yellow button")==0 || strcmp(password,"push yellow")==0)
                {
                if (boxopen==1 && red1==1 && blue2==1 && green3==1 && yellow4==0)
                  {
                  system("CLS");
                  cout<<"You press the yellow button, and the top half of the puzzle flips open.\n";
                  cout<<"Inside the puzzle are two rocks.\n";
                  yellow4=1;
                  scene4=1;
                  }


                else
                  {
                  cout<<"You press the yellow button, and you hear a loud click.\n";
                  red1=0;
                  blue2=0;
                  green3=0;
                  yellow4=0;
                  }
                }



     }
while (scene5!=1)
   {
   cin.getline (password,100);

    if (strcmp(password,"examine rocks")==0 || strcmp(password,"look at rocks")==0)
      cout<<"The rocks are jagged, and coarse. They feel very strong.\n";

    else if (strcmp(password,"smash rocks together")==0 || strcmp(password,"bang rocks together")==0 || strcmp(password,"hit rocks together")==0)
      {
      system("CLS");
      cout<<"You smash the rocks together, and on collision, a large spark flies off of the two rocks, and hits the ground, lighting a small fire on the carpet.\n";
      cout<<"The fire quickly burns through the floor, revealing a deep hole.\n";
      holeopen=1;
      }

    if (holeopen==1 && (strcmp(password,"enter hole")==0 || strcmp(password,"go down hole")==0) || strcmp(password,"jump in hole")==0 || strcmp(password,"jump down hole")==0 || strcmp(password,"go in hole")==0 || strcmp(password,"get in hole")==0)
      {
      system("CLS");
      cout<<"You jump down the hole. It seems to be very deep. After about twenty seconds of descent, you hit the bottom. Strangely enough, you survived the fall with no injuries.\n";
      cout<<"It seems you've landed in a maze. There's a corridor north, west, and east of you.\n";
      b=1;
      scene5=1;
      }

    else if (holeopen==1 && strcmp(password,"examine hole")==0 || strcmp(password,"look at hole")==0)
      cout<<"The hole looks very deep. It begins to get dark about 15 meters down, and you can't see the bottom.\n";

    else if (holeopen==1 && gotrocks==0 && strcmp(password,"toss rock in hole")==0 || strcmp(password,"toss rocks in hole")==0 || strcmp(password,"toss rock in the hole")==0 || strcmp(password,"toss rocks in the hole")==0 || strcmp(password,"throw rock in hole")==0 || strcmp(password,"throw rocks in hole")==0 || strcmp(password,"throw rock in the hole")==0 || strcmp(password,"throw rocks in hole")==0 || strcmp(password,"toss rocks in the hole")==0)
      {
      cout<<"You pick up the rocks and throw it into the hole. It takes twenty seconds for it to hit the bottom. You contemplate whether you want to go down it.\n";
      gotrocks=1;
      }

    else if (holeopen==1 && gotrocks==1 && strcmp(password,"toss rock in hole")==0 || strcmp(password,"toss rocks in hole")==0 || strcmp(password,"toss rock in the hole")==0 || strcmp(password,"toss rocks in the hole")==0 || strcmp(password,"throw rock in hole")==0 || strcmp(password,"throw rocks in hole")==0 || strcmp(password,"throw rock in the hole")==0 || strcmp(password,"throw rocks in hole")==0 || strcmp(password,"toss rocks in the hole")==0)
      cout<<"You don't have any more rocks!.\n";

    else
      cout<<"You can't "<< password <<" right now!\n";
   }

   while (maze!=1)
   {
    cin.getline (password,100);

//south-west area//

    if (b==1 && (strcmp(password,"go west")==0 || strcmp(password,"west")==0 || strcmp(password,"move west")==0))
      {
      cout<<"You go down the west corridor, and go around a corner to the right. You see some statues of cupid, and another two corridors. One north of you, and one east of you.\n";
      b=0;
      f2=1;
      }

    else if ((f2==1 || f1==1)  && (strcmp(password,"go west")==0 || strcmp(password,"west")==0 || strcmp(password,"move west")==0))
      cout<<"There's a solid wall, west of you.\n";

    else if (f3==1  && (strcmp(password,"go north")==0 || strcmp(password,"north")==0 || strcmp(password,"move north")==0))
      cout<<"There's a solid wall, north of you.\n";

    else if (f2==1  && (strcmp(password,"go north")==0 || strcmp(password,"north")==0 || strcmp(password,"move north")==0))
      {
      cout<<"You move down the northern corridor and take a right at the corner. It's a dead end.\n";
      f2=0;
      d7=1;
      }

    else if (f2==1 && rope==0 && (strcmp(password,"go east")==0 || strcmp(password,"east")==0 || strcmp(password,"move east")==0))
      {
      cout<<"You go down the eastern corridor, take a right at the corner, then another right. It's a dead end, but there's a pile of rope sitting on the ground.\n";
      f2=0;
      d3=1;
      }

    else if (f2==1 && rope==1 && (strcmp(password,"go east")==0 || strcmp(password,"east")==0 || strcmp(password,"move east")==0))
      {
      cout<<"You go down the eastern corridor, take a right at the corner, then another right. It's a dead end, you already took the rope.\n";
      f2=0;
      d3=1;
      }

    else if (d3==1 && rope==0 && (strcmp(password,"take rope")==0 || strcmp(password,"pick up rope")==0 || strcmp(password,"acquire rope")==0))
      {
      cout<<"You walk up to the rope, and put it in your pocket.\n";
      rope=1;
      }

    else if ((d3==1 || d1==1 || d2==1 || d5==1 || (d6==1 || d7==1) && (strcmp(password,"go east")==0 || strcmp(password,"east")==0 || strcmp(password,"move east")==0) ||(strcmp(password,"go west")==0 || strcmp(password,"west")==0 || strcmp(password,"move west")==0) || (strcmp(password,"go south")==0 || strcmp(password,"south")==0 || strcmp(password,"move south")==0) || (strcmp(password,"go north")==0 || strcmp(password,"north")==0 || strcmp(password,"move north")==0))
      cout<<"There's no way to go but back.\n";

    else if (d3==1 && (strcmp(password,"go back")==0 || strcmp(password,"move back")==0 || strcmp(password,"back")==0))
      {
      cout<<"You go back to the fork with the statues.\n";
      d3==0;
      f2==1;
      }

    else if (d7==1 && (strcmp(password,"go back")==0 || strcmp(password,"move back")==0 || strcmp(password,"back")==0))
      {
      cout<<"You go back to the fork with the statues.\n";
      d7==0;
      f2==1;
      }

    else if (f2==1 && (strcmp(password,"go south")==0 || strcmp(password,"south")==0 || strcmp(password,"move south")==0))
      {
      cout<<"You go south, and take a left. You're now back where you fell from the hole.\n";
      f2=0;
      b=1;
      }

//end of south-west area//

    else if (b==1 && (strcmp(password,"go north")==0 || strcmp(password,"north")==0 || strcmp(password,"move north")==0))
      {
      cout<<"You go into the north corridor, and reach a fork. There's a chandelier hanging from the ceiling, and two corridors. One north of you, and one east of you.\n";
      b=0;
      f1=1;
      }

    else if (f1==1 && (strcmp(password,"go north")==0 || strcmp(password,"north")==0 || strcmp(password,"move north")==0))
      {
      cout<<"You walk down the north corridor. It's a dead end.\n";
      f1=0;
      d1=1;
      }

    else if (d1==1 && (strcmp(password,"go back")==0 || strcmp(password,"back")==0 || strcmp(password,"move back")==0))
      {
      cout<<"You move back to the fork with the chandelier.\n";
      d1=0;
      f1=1;
      }

   }


  return 0;
}

Share this post


Link to post
Share on other sites
Advertisement
When your passing the new values to your rooms, try putting just one equals sign, the other is for value comparisions.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!