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 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
|
#include <iostream>
#include <string>
#include <fstream>
#include <ctime>
#include <cstdlib>
#include <vector>
using namespace std;
struct Vars
{
void Game();
string randNames();
string randCrimes();
long int money;
int prisoners;
string playerName;
string prisonName;
ofstream namesOut; // Saves the prisoners list
ofstream fileOut; // Saves the player info
ifstream fileIn;
ifstream namesIn;
string fileStr;
};
int main()
{
int choice;
srand(time(0x0));
Vars v;
cout << "1) New" << endl;
cout << "2) Load\n" << endl;
cin >> choice;
if(choice == 1)
{
v.fileOut.open("prison.txt");
cin.ignore(1000, '\n');
cout << "Hello please enter your name" << endl;
getline(cin, v.playerName);
v.fileOut << v.playerName << endl;
cout << "\n";
cout << "Thank you " << v.playerName << " now please enter the name of your prison" << endl;
getline(cin, v.prisonName);
v.fileOut << v.prisonName << endl;
cout << "\n";
cout << "Ok thank you lets start the game" << endl;
cin.get();
v.money = 50000;
v.prisoners = 0;
v.fileOut << v.money << endl;
v.fileOut << v.prisoners << endl;
v.fileOut.close();
v.Game();
}
else if(choice == 2)
{
v.fileIn.open("prison.txt");
getline(v.fileIn, v.playerName);
getline(v.fileIn, v.prisonName);
v.fileIn >> v.money;
v.fileIn >> v.prisoners;
v.fileIn.close();
v.namesIn.open("prisonersList.txt");
while(!v.namesIn.eof())
{
getline(v.namesIn, v.fileStr);
}
v.namesIn.close();
v.Game();
}
}
void Vars::Game()
{
int choice;
int random;
int inMnum;
bool endLoop = true;
cout << "Main Menu\n" << endl;
cout << "What do you want to do?\n" << endl;
cout << "1) Add prisoners" << endl;
cout << "2) View list of executed prisoners" << endl;
cout << "3) View prison statistics" << endl;
cout << "4) Execute Prisoner(s)" << endl;
cout << "5) List of current inmates" << endl;
while(endLoop != false)
{
cin >> choice;
switch(choice)
{
case 1:
{
namesOut.open("prisonersList.txt");
cout << "INMATE LIST" << endl;
vector<string> nameVect;
vector<string> crimeVect;
cout << "Enter how many inmates you would like to take in." << endl;
cout << "Your current prisoner count is: " << prisoners << endl;
cout << "You may not exceed 25 prisoners at this time" << endl;
cin >> inMnum;
if((inMnum > 0) && (inMnum < 26))
{
for(int i = 0; i < inMnum; i++)
{
nameVect.push_back(randNames());
crimeVect.push_back(randCrimes());
}
cout << "Name " << "Crime\n" << endl;
for(int i = 0; i < inMnum; i++)
{
cout << nameVect[i] << " ";
cout << crimeVect[i] << endl;
namesOut << nameVect[i] << " ";
namesOut << crimeVect[i] << endl;
}
}
else
{
cout << "Error" << endl;
endLoop = false;
}
namesOut.close();
}
break;
case 2:
cout << "Executed Prisoners\n" << endl;
break;
case 3:
cout << "Prison Statistics\n" << endl;
cout << "Warden Name: " << playerName << endl;
cout << "Prison Name: " << prisonName << endl;
cout << "Current Money: " << money << endl;
cout << "Prisoners: " << prisoners << endl;
break;
case 4:
cout << "EXECUTE A PRISONER\n" << endl;
break;
case 5:
cout << "CURRENT INMATES\n" << endl;
while(!namesIn.eof())
{
getline(namesIn, fileStr);
}
break;
}
}
}
string Vars::randNames()
{
string names[20] =
{
"Jerry",
"Mike",
"Phill",
"Robert",
"Allen",
"Alex",
"Tim",
"Steven",
"Ronald",
"David",
"Harold",
"Thomas",
"Andrew",
"Carlito",
"Frank",
"Dale",
"John",
"Mark",
"Josh",
"Martin"
};
return names[rand() % 20];
}
string Vars::randCrimes()
{
string crimes[20] =
{
" - Sexual Assault",
" - Child Abuse",
" - Murder",
" - Assault",
" - Breaking and Entering",
" - Domestic Violence",
" - Unlawful Posession of a Firearm",
" - Destruction of private property",
" - Kidnapping",
" - Armed Robbery",
" - Petty Theft",
" - Disorderly Conduct",
" - Indecent Exposure",
" - Stalking",
" - Shoplifting",
" - Trespassing",
" - Battery on and Officer",
" - Forgery",
" - Grand Theft Auto",
" - Probation Violation"
};
return crimes[rand() % 20];
}
|