-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassignment.cpp
More file actions
184 lines (152 loc) · 6.3 KB
/
Copy pathassignment.cpp
File metadata and controls
184 lines (152 loc) · 6.3 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/***************************************************************************
* Program Filename: aassignment.cpp
* Author: Tara Massey
* Date: 03/17/2015
*
* Desription: Program creates a choose your own adventure text game. The
* program consists of linked classes. Every room will have four pointers to
* other rooms. The base class for the rooms is abstract. The character will
* have to navigate the maze while picking up items to succeed in the last
* room. The character will be allowed to interact with distinct and unique
* rooms.
*
* Input: The user selects their name and title. The user can select to
* look for someone to talk to, look aroud for items, leave, or read the
* help menu in each room. When selecting someone to talk to, if applicable,
* the user can select various conversation choices. If the user selects to
* look for an item, if applicable, the user can keep the item, use the item,
* throw the item, or look at the item. The program reads texts from three
* seperate files to create the story.
*
* Output: The program prints the stories to the screen, and the various menus.
* The program prints appropriate responses to each menu selection, with
* room dependent options. The program creates new drived classes and assigns
* them to a Room pointer. Appropriate notification regarding health and time
* are printed to the screen.
*
****************************************************************************/
#include "World.h"
#include "Room.h"
#include "Start.h"
#include "Sewer.h"
#include "Secret.h"
#include "Dead.h"
#include "Street.h"
#include "House.h"
#include "JHouse.h"
#include "Final.h"
#include "End.h"
#include "Maggie.h"
#include "Joe.h"
#include "Char.h"
#include "Item.h"
#include <string>
#include <vector>
#include <iostream>
#include <cstdlib>
void readStory(int num);
int main()
{
std::string input;
std::string inputTwo;
int pick = 5;
/* Create a world state of possible rooms */
World* state = new World;
state->createWorld();
/* Begin the introduction to the story */
std::cout << std::string(100, '\n');
readStory(1);
/* Create your hero */
std::cout << "\nYou pull back your shoulders, and in your best attempt to hide your terror you give your name: ";
std::getline(std::cin, input);
std::cout << "\nWhile your at it, you may as well make up an amazing, unforgetable, badass nickname: ";
std::getline(std::cin, inputTwo);
std::cout << std::string(100, '\n');
Char* player = new Char(input, inputTwo);
/* Learn about your predicament and the goal */
std::cout << " 'Right... Mr. " << player->getName() << " the " << player->getDesc() << "'" << std::endl;
std::cout << "\n";
std::cout << std::string(100, '\n');
readStory(2);
std::cout << "\nPRESS ENTER TO BEGIN YOUR JOURNEY" << std::endl;
std::getline(std::cin, input);
std::cout << std::string(100, '\n');
/* Pull up starting room and story characters */
Room* currentRoom = state->startPnt();
Maggie* npc = new Maggie;
Joe* npc2 = new Joe;
/* While the player still has health & time, implement action loop for all rooms but Final/End, Different actions for Final/End, and link to next*/
while(player->getLost() == false){
if(currentRoom->getName() != "Final" && currentRoom->getName() != "End"){
state->addPath(currentRoom);
player->setLocation(currentRoom->getName());
std::cout << std::string(100, '\n');
currentRoom->setDesc();
currentRoom->getDesc();
state->timer(player);
while(pick == 5){
std::cout << "\nPossible Actions: ";
currentRoom->printActions();
std::cout << "\nWhat would you like to do?" << std::endl;
std::getline(std::cin, input);
std::cout << std::string(100, '\n');
pick = atoi(input.c_str());
pick = currentRoom->actions(pick, currentRoom, player, npc, npc2);}
Room* temp = currentRoom->move(pick); // Go to next link
currentRoom = temp;
pick = 5;}
/* Special/Limited Actions for Room Prior to Winning */
if(currentRoom->getName() == "Final"){
player->setKeys();
player->setLocation(currentRoom->getName());
state->timer(player);
state->addPath(currentRoom);
/* Player has the keys to access the final room */
if(player->getKeys() == true){
std::cout << "You take a peek in your bag to see if you can figure out a way up to the grate." << std::endl;
player->viewBag();
std::cout << "\nYou can absolutely work wit that. You did it!" << std::endl;
Item* all = new Item;
currentRoom->interactItem(all, player);
pick = 1;
Room* temp = currentRoom->move(pick); // Go to next link
currentRoom = temp;}
/* Player does not have the keys to get to the final room */
else{
currentRoom->setDesc();
currentRoom->getDesc();
std::cout << "You look desperately through your pack. Unfortunately, you don't have what you need to ";
std::cout << "be able to access the grate so very far above your head." << std::endl;
player->viewBag();
currentRoom->printActions();
std::cout << "\nWhat would you like to do?" << std::endl;
std::getline(std::cin, input);
std::cout << std::string(100, '\n');
pick = atoi(input.c_str());
pick = currentRoom->actions(pick, currentRoom, player, npc, npc2);
Room* temp = currentRoom->move(pick); // Go to next link
currentRoom = temp;
pick = 5;}}
/* Final Room, Access the room, get the description, and Read End file to exit */
if(currentRoom->getName() == "End"){
currentRoom->setDesc();
currentRoom->getDesc();
std::cout << "You take a peek in your pack, thankful you have the hair pins to pick the lock, and the booze to celebrate." << std::endl;
readStory(3);
/* View stats and clean up pointers */
std::cout << "\nGame Choices: " << std::endl;
state->viewWorld();
state->viewPath();
return 0;}}
/* Losing conditions */
if(player->getHP() <= 0){
std::cout << "\nWell... you died. You were warned in the beginning, remember?" << std::endl;}
else{
std::cout << "\nYou drop to your knees, bowing your head in shame and frustration. You can see the sun beginning to rise. " << std::endl;
std::cout << "You tried, but you weren't able to pull off the heist in time. " << std::endl;}
/* View World State, including winning choices and your choices */
std::cout << "\nGame Choices: " << std::endl;
state->viewWorld();
state->viewPath();
return 0;
}