I am a beginner but my problem with this game is that when i enter east it said it going to north.
here my code for my main and parser also when i enter a word then it quit the game so how do i make it stay open to allow me to enter other words
Main.CPP
#include <iostream>
#include <fstream>
#ifndef Parse_h
#define Parse_h
#include "Parser.h"
#endif
using namespace std;
int main()
{
Parser textparser;
char word[20];
cout<<" Welcome To Text Adventure Game! "<<endl;
cout <<"To move in the game, You will need to type in north, east, south, west";
cout <<"\nThere another command you can use in the game.\nWhich are : 'pick', 'open', 'read', 'drop', 'eat', 'close', 'look', 'search ";
cout <<""<<endl;
cout <<""<<endl;
cout <<"\nYou Woke up and found yourself in Deep Dark Forest and you need to get out" << endl;
cout <<"\nNow what you going to type in > " ;
cin >> word;
textparser.IsWordinCommands(word);
textparser.IsWordinObjects(word);
const char cmds[] = "north";
if ("north")
{
cout <<"\nYou Went North and found yourself in similar postion";
cout <<"\nWhat should you do now? > ";
}
else if ("east")
{
cout <<"\nYou went East and saw House";
cout <<"\nWhat should you do now? > ";
}
else if("south")
{
cout <<"\nYou cannot go backward beacuse there a wall blocking the path";
cout <<"\nWhat should you do now? > ";
}
else if("west")
{
cout <<"\nYou went to west but there are nothing in there.";
cout <<"\nWhat should you do now? > ";
}
system("pause");
return 0;
}
Parser.h
#ifndef parse_h
#define parse_h
#include <string>
//Class definition for Parser Class
class Parser
{
char* commands [50];
char* objects[50];
//how many commands can be used
int numcommands;
//how many objects can be used
int numobjects;
public:
Parser()
{
numcommands = 12;
numobjects = 12;
//a word to do something
char* cmds[] = {"north", "east", "south",
"west", "pick", "open",
"read", "drop", "eat",
"close", "look", "search"};
//an object that can be used to intract with object.
char* objs[] = {"fork", "knife", "sword",
"enemy", "monster", "shield",
"armour", "spoon", "table",
"door", "room", "key"};
//initialise commands array with these valid command words
for(int i=0 ; i<numcommands ; i++)
{
commands[i] = cmds[i];
}
//initialise objects array with these valid object words
for(int i=0 ; i<numobjects ; i++)
{
objects[i] = objs[i];
}
}
char* LowerCase (char* st);
char* RemoveThe(char* sen);
char* GetVerb(char* sen);
char* GetObject(char* sen);
void SortCommands();
void SortObjects();
void PrintCommands();
void PrintObjects();
bool IsWordinCommands(char* target);
bool IsWordinObjects(char* target);
};
#endif