Text Adventure game help.

We are attempting to code a Text Adventure, similar to Zork... Mainly, we suck. :D

So, yeah. Do you guy's see anything wrong with this code?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <windows.h>
#include <stdio.h>
#include <string.h>
using namespace std;

int main(int argc, char *argv[])
{
    SetConsoleTitle( "Office Survival" );
    /* Intro title */

    char loop1a[20];
    char hall_1[81];
    char donow[] = "\nWhat would you like to do? ";
    char help[] = "\nExamine (object), move (left, right, forward, back) \npick up, use (object), attack/kick (object)\n\nWhat would you like to do now? ";
    
    cout<<"                                                                               "<<endl;
    cout<<" ##############################################################################"<<endl;
    cout<<" #                                                       ver. 0.3.8 Alpha(C++)#"<<endl;
    cout<<" #                         Welcome To Office Survival!                        #"<<endl;
    cout<<" #                                                                            #"<<endl;
    cout<<" #  Coding By: Austin, Josh & Neil.                                           #"<<endl;
    cout<<" #  Music & Sound By: Josh.                                                   #"<<endl;
    cout<<" #  Storyline By: Austin & Neil                                               #"<<endl;
    cout<<" #                                                                            #"<<endl;
    cout<<" #                         Press Enter To Start Game.                         #"<<endl;
    cout<<" #                                                                            #"<<endl;
    cout<<" # You wake up in a dark closet after   |  Commands Used In Office Survival;  #"<<endl;
    cout<<" # a long night of partying with        |  (DO NOT USE CAPITALS)              #"<<endl;
    cout<<" # co-workers. Regaining your sober     |                                     #"<<endl;
    cout<<" # state, you realize you are locked    |  examine (what you are examining)   #"<<endl;
    cout<<" # inside a janitors closet, inside the |  pick up (what you are picking up)  #"<<endl;
    cout<<" # office. You notice it is early       |  use item                           #"<<endl;
    cout<<" # morning because of the small window  |  move (direction)                   #"<<endl;
    cout<<" # that lay just out of reach. You must |  typing 'i' will show your inventory#"<<endl;
    cout<<" # find a way out of here and get home. |  type 'help' to receive a list of   #"<<endl;
    cout<<" #                                      |  commands                           #"<<endl;
    cout<<" #                                      |                                     #"<<endl;
    cout<<" ##############################################################################"<<endl;
    system("PAUSE");
    system("CLS");
    // Define Location Pwease. 
    // y=1000+rand()%(9999)
    // make it funtional (wut?)
{
    cout << "You wake up in a dark room. \nThe only light source is trickling through a split in the door. \nAlmost as if someone has slashed it with some type of sharp object.\n\nWhat would you like to do? ";
    cin >> loop1a;
    bool done = false;
    while (!done){
          if (loop1a == "kick door"){
                     cout << "\nYou kick down the door and walk through it, You are now in a hallway.";
                     cout << donow;             
          }
          else if (loop1a == "pick up"){ 
                 cout << "\nThere is nothing but dust around you.";
                 cout << donow;            
          }
          else if (loop1a == "examine room"){
                 cout << "\nThe room is dark and stuffy. You feel around and find nothing to grab onto. The door appears to be weak however. You should try to kick it down.";
                 cout << donow;
                 cin >> loop1a;
          }
          else if (loop1a == "move left"){
                 cout << "\nThe closet is really small which hinders your movement. Ultimately, you fail to move anywhere.";
                 cin >> loop1a;
                 cout << donow;
          }
          else if (loop1a == "move right"){
                 cout << "\nThe miniscule space of the closet prevents your movement..";
                 cin >> loop1a;
                 cout << donow;
          }
          else if (loop1a == "move forward"){
                cout << "\nThe closet is too small to move anywhere.";
                cin >> loop1a;
                cout << donow;
          }
          else if (loop1a == "move back"){
               cout << "\nYou bump into the wall immediately behind you... The closet is too small.";
                cin >> loop1a;
                cout << donow;
          }
          else if (loop1a == "go home"){
                cout << "\n\n\n\n\n\n\n\nYou Win :D";
                cin >> loop1a;
                cout << donow;
          }
          else if (loop1a == "help"){
                cout << help;
                cin >> loop1a;
                cout << donow;
                      }
          else{
                cout << "Unknown Command. Please try again. \n";
                cout << donow;
              }
                cin >> loop1a;
                 }
}    
      {
                 }
            while (hall_1 != "move left", "move right", "move back"){
                  if (hall_1 == "move forward"){
                             cout << "\nThe closet is too small to move anywhere.";
                             cin >> hall_1;
                             system("CLS");
                             cout << donow;
                   }
      }
       return EXIT_SUCCESS;
}

Last edited on
You are comparing c strings with ==. That will only compare the pointers. To compare to c strings use std::strcmp.
if (strcmp(loop1a, "kick door") == 0){
Or better, use std::string. Then you can use ==.
Avoid the system commands, they are very memory heavy and bad programming practice. instead use either Getch() or a cin to pause, and this function to clear the screen:
note: you will need to include <windows.h>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
void cls() //windows h function to replace screen with nulls
{
  DWORD n;
  DWORD size;
  COORD coord = {0};
  CONSOLE_SCREEN_BUFFER_INFO csbi;
  HANDLE h = GetStdHandle ( STD_OUTPUT_HANDLE );
  GetConsoleScreenBufferInfo ( h, &csbi );
  size = csbi.dwSize.X * csbi.dwSize.Y;
  FillConsoleOutputCharacter ( h, TEXT ( ' ' ), size, coord, &n );
  GetConsoleScreenBufferInfo ( h, &csbi );
  FillConsoleOutputAttribute ( h, csbi.wAttributes, size, coord, &n );
  SetConsoleCursorPosition ( h, coord );
}
and use cin.getline(loop1a, 20); and cin.getline(hall_1, 81); (20 and 81 is the length of loop1a and hall_1 instead of cin >> loop1a; or cin >> hall_1; since you need to get the space character as well...
Thank you for the help we got the program working kinda but we got past that mind-block.
Topic archived. No new replies allowed.