-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGame2
153 lines (152 loc) · 4.54 KB
/
Game2
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
#include <iostream>
#include <string>
#include <unistd.h>
using namespace std;
int main()
{
string pItems[10], pChoice, itemName1, itemName2, itemName3, inventChoice, lChoice, preciousItem, checkItem;
int i=0,totalItems=0;
bool foundItem = false;
cout<<"Welcome to SURVIVAL CHOICES\n";
sleep(1);
cout<<"You will start the game with 3 items. \n";
sleep(1);
//Add 3 items to the array:
pItems[totalItems++] = "Sword";
pItems[totalItems++] = "Bow";
pItems[totalItems++] = "Arrow";
cout<<"As you progress through the game, you will gain more items, each of which shall be named by you.";
sleep(1);
cout<<"Before the game ends, you have to use atleast one item.";
sleep(1);
cout<<"As you approach the bridge, you will have to give one of your most treasured items of the 5 that you now have, to the bridge troll!";
sleep(1);
cout<<"Do you wish to play the game? ('yes' or 'no')\n";
sleep(2);
cin>>pChoice;
if(pChoice == "yes")
{
cout<<"You have the following items in your inventory:\n";
for(i=0;i<totalItems;i++)
{
if(pItems[i] != "")
cout<< "-" <<pItems[i]<<"\n";
}
cout<<"As you are walking down the lonely path in the forest, you find an item!\n";
sleep(1);
cout<<"What would you like to name this item?(one word only!)\n";
cin>>itemName1;
cout<<"You now have "<<itemName1<<"\n";
//Add the item entered by user to the array:
pItems[totalItems++] = itemName1;
cout<<"Do you wish to see your inventory?\n";
cin>>inventChoice;
if(inventChoice == "yes")
{
for(i=0;i<totalItems;i++)
{
if(pItems[i] != "")
cout<< "-" <<pItems[i]<<"\n";
}
}
cout<<"Moving On! As you walk further down the road, you encounter a Lion on the path! To proceed, you shall have to kill the lion using your arrow. However, doing so shall remove the arrow from your inventory! Do you wish to use your arrow to kill the lion?\n";
sleep(1);
cin>>lChoice;
if(lChoice == "yes")
{
cout<<"You have killed the lion and survived!\n";
//Remove one item from the array:
pItems[2] = "";
}
else
{
cout<<"Game Over!";
return 0;
}
cout<<"Do you wish to see your inventory? \n";
cin>>inventChoice;
if(inventChoice == "yes")
{
for(i=0;i<totalItems;i++)
{
if(pItems[i] != "")
cout<< "-" <<pItems[i]<<"\n";
}
}
cout<<"As you move along the path, near the pond you find an item! What would you like to name it?(One word only!)\n";
cin>>itemName2;
cout<<"You have now acquired: "<<itemName2<<"\n";
//Add the item entered by user to the array:
pItems[totalItems++] = itemName2;
cout<<"Do you wish to see your inventory? \n";
cin>>inventChoice;
if(inventChoice == "yes")
{
for(i=0;i<totalItems;i++)
{
if(pItems[i] != "")
cout<< "-" <<pItems[i]<<"\n";
}
}
cout<<"Once again, moving along the path, you find a third and final item! What would you like to name this item?(One word only!)\n";
cin>>itemName3;
cout<<"You have now acquired: "<<itemName3<<"\n";
//Add the item entered by user to the array:
pItems[totalItems++] = itemName3;
cout<<"Do you wish to see your inventory? \n";
cin>>inventChoice;
if(inventChoice == "yes")
{
for(i=0;i<totalItems;i++)
{
if(pItems[i] != "")
cout<< "-" <<pItems[i]<<"\n";
}
}
cout<<"What is your most precious item from the inventory?\n";
cin>>preciousItem;
//Used a while loop to check that the item entered is in the inventory:
while(!foundItem)
{
for(i=0; i<totalItems;i++)
{
if(pItems[i] == preciousItem)
{
foundItem = true;
break;
}
else if(i == totalItems - 1)
{
cout<<"Item is not in the list! Please try again:\n";
cin>>preciousItem;
}
}
}
cout<<"Finally after a long journey, you have reached the bridge! The bridge troll is waiting for his fee to let you pass! You have to forsake your most precious item as the fee to pass the bridge! Please enter the item: ";
cin>>checkItem;
//used a while loop to ensure the player enters the correct item to exit the bridge/game:
while(checkItem != preciousItem)
{
cout<<"That is not your most precious item!\n";
cout<<"Please enter the most precious item to forsake: \n";
cin>>checkItem;
if(checkItem == preciousItem)
{
cout<<"You have successfully finished the game! Adios until next time Hooman!\n";
break;
}
}
for(i=0; i<totalItems; i++)
{
if(pItems[i] == checkItem)
//Removed another item from the array:
pItems[i] = "";
}
cout<<"Your inventory is at the end of game is: \n";
for(i=0;i<totalItems;i++)
{
if(pItems[i] != "")
cout<< "-" <<pItems[i]<<"\n";
}
}
}