-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtextgamemain.cpp
More file actions
93 lines (91 loc) · 2.68 KB
/
textgamemain.cpp
File metadata and controls
93 lines (91 loc) · 2.68 KB
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
#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <cstdlib>
#include <cctype>
#include <string>
#include <fstream>
#include "textgame.h"
using namespace std;
int main() {
World world;
ifstream inFS;
string fileText;
int fileInt;
inFS.open("rooms.txt");
if (!inFS.is_open()) {
cout << "Could not open file numFile.txt." << endl;
return 1;
}
while (!inFS.eof()) {
inFS >> fileText;
if (fileText == "Room:") {
Room room;
world.AddRoom(room);
inFS >> fileInt;
room.SetRoomNumber(fileInt);
}
else if (fileText == "Desc:") {
Room* room = world.GetLastRoom();
getline(inFS, fileText);
room->SetDescription(fileText);
}
else if (fileText == "Option:") {
Room* room = world.GetLastRoom();
Option option;
inFS >> fileText;
option.SetOptionKeyword(fileText);
room->AddOption(option);
}
else if (fileText == "Stat:") {
Room* room = world.GetLastRoom();
Option* option = room->GetLastOption();
inFS >> fileText;
option->SetStat(fileText);
}
else if (fileText == "Pass:") {
Room* room = world.GetLastRoom();
Option* option = room->GetLastOption();
getline(inFS, fileText);
option->SetPassText(fileText);
}
else if (fileText == "Pexit:") {
Room* room = world.GetLastRoom();
Option* option = room->GetLastOption();
inFS >> fileInt;
option->SetPexit(fileInt);
}
else if (fileText == "Fail:") {
Room* room = world.GetLastRoom();
Option* option = room->GetLastOption();
getline(inFS, fileText);
option->SetFailText(fileText);
}
else if (fileText == "Fexit:") {
Room* room = world.GetLastRoom();
Option* option = room->GetLastOption();
inFS >> fileInt;
option->SetFexit(fileInt);
}
else if (fileText == "Damage:") {
Room* room = world.GetLastRoom();
Option* option = room->GetLastOption();
inFS >> fileText;
option->SetFailDamage(fileText);
}
}
inFS.close();
string userInput;
cout << "Type \"Begin\" to start or anything else to quit." << endl;
cin >> userInput;
for (int i = 0; i < userInput.length(); i++) {
userInput[i] = tolower(userInput[i]);
}
if (userInput == "begin") {
world.Play();
}
else {
cout << "Finish" << endl;
}
return 0;
}