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
|
///////////////////////////////////// CHECK (TEXT) NPC
bool CheckNPC(tRoom &room, string strNPC)
{
for(int i = 0; i < MAX_LOOKS; i++)
{
if(strNPC == room.strTalkArray[i])
return true;
}
return false;
}
///////////////////////////////////// GET TEXT INFO
void GetText(ifstream &fin, tRoom &room, CPlayer &player, string strInput)
{
string strLine = "";
fin.seekg(NULL,ios::beg);
fin.clear();
while(getline(fin, strLine, '\n'))
{
if(strLine == "<" + room.strCurrentRoom + "|" + strInput + ">")
{
getline(fin, room.strNPCText, '*');
return;
}
}
}
///////////////////////////////////// DISPLAY NPC TEXT
void DisplayNPCText(string strNPCText)
{
cout << endl << strNPCText << endl;
}
///////////////////////////////////// GET INPUT
int GetInput(ifstream &fin, tRoom &room, CPlayer &player)
{
string strInput;
string strLine;
cout << endl << ": ";
cin >> strInput;
if(strInput == "look")
{
DisplayRoom(room);
}
else if(strInput == "view")
{
cout << "What do you want to view?" << endl;
cin >> strInput;
if(CheckLook(room, strInput))
{
GetLookInfo(fin, room, strInput);
DisplayLook(room.strLookDescription);
}
else { cout << "There is no such thing to look at..." << endl; }
}
else if(strInput == "status") { DisplayPlayer(player); }
else if(strInput == "north") { Move(fin, room, room.strRoomNorth); }
else if(strInput == "east") { Move(fin, room, room.strRoomEast); }
else if(strInput == "south") { Move(fin, room, room.strRoomSouth); }
else if(strInput == "west") { Move(fin, room, room.strRoomWest); }
else if(strInput == "quit") { cout << "Quitting already?"; return QUIT; }
else if(strInput == "help") { cout << "Console commands: Look, View, Status, North, East, South, West, Quit, Help, Talk, Save/Load." << endl; }
//////////////////////////////// NEW //////////////////////////////// NEW
else if(strInput == "talk")
{
cout << "Who do you want to talk to?" << endl << ": ";
cin >> strInput;
if(CheckNPC(room, strInput))
{
GetText(fin, room, strInput);
DisplayNPCText(room.strNPCText);
}
else { cout << "There is no such person to talk to..." << endl; }
}
//////////////////////////////// NEW //////////////////////////////// NEW
else { cout << "Invalid command." << endl; }
return STILL_PLAYING;
}
|