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
|
#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;
};
int main()
{
int choice;
Vars v;
cout << "1) New" << endl;
cout << "2) Load\n" << endl;
cin >> choice;
if(choice == 1)
{
ofstream file;
file.open("prison.txt");
cin.ignore(1000, '\n');
cout << "Hello please enter your name" << endl;
getline(cin, v.playerName);
file << v.playerName << endl;
cout << "\n";
cout << "Thank you " << v.playerName << " now please enter the name of your prison" << endl;
getline(cin, v.prisonName);
file << v.prisonName << endl;
cout << "\n";
cout << "Ok thank you lets start the game" << endl;
cin.get();
v.money = 50000;
v.prisoners = 0;
file << v.money << endl;
file << v.prisoners << endl;
file.close();
v.Game();
}
else if(choice == 2)
{
ifstream file;
file.open("prison.txt");
file >> v.playerName;
file >> v.prisonName;
file >> v.money;
file >> v.prisoners;
file.close();
v.Game();
}
}
void Vars::Game()
{
int choice;
string vect;
cout << "Main Menu\n" << endl;
cout << "What do you want to do?\n" << endl;
cout << "1) View list of prisoners" << endl;
cout << "2) View list of executed prisoners" << endl;
cout << "3) View prison statistics" << endl;
cout << "4) Execute Prisoner(s)" << endl;
cin >> choice;
switch(choice)
{
case 1:
cout << "Inmate list, maximum 25 inmates\n" << endl;
vector<string> nameVect;
vector<string> crimeVect;
for(int i = 0; i < 11; i++)
{
nameVect.push_back(randNames());
crimeVect.push_back(randCrimes());
}
cout << "Name " << "Crime\n" << endl;
for(int i = 0; i < 11; i++)
{
cout << nameVect[i] << " ";
cout << crimeVect[i] << endl;
}
}
}
string Vars::randNames()
{
string names[17] =
{
"Jerry",
"Mike",
"Phill",
"Robert",
"Allen",
"Alex",
"Tim",
"Steven",
"Ronald",
"David",
"Harold",
"Thomas",
"Andrew",
"Carlito",
"Frank",
"Dale",
"John"
};
srand(time(0x0));
return names[rand() % 17];
}
string Vars::randCrimes()
{
string crimes[9] =
{
"Rape",
"Child Abuse",
"Murder",
"Assault",
"Breaking and Entering",
"Domestic Violence",
"Unlawful Posession of a Firearm",
"Destruction of private property",
"Kidnapping"
};
srand(time(0x0));
return crimes[rand() % 9];
}
|