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
|
#include <iostream>
#include <algorithm>
#include <time.h>
using namespace std;
void dailyRoutine (int &num, string &fullName);
void choice1 (int &pStrength, int &bStrength, double &milkMoney);
void outcomes (int &pStrength, int &bStrength, double &milkMoney);
void fight (int &pStrength, int &bStrength, double &milkMoney);
void walk (int &pStrength, int &bStrength, double &milkMoney);
void days (int &num);
void dowStart (int &num);
string playerInfo (int &num);
int main ()
{
srand (time(0));
int num = 0;
string fullName = playerInfo (num);
playerInfo (num);
dailyRoutine (num, fullName);
system ("pause");
return 0;
}
void dailyRoutine (int &num, string &fullName)
{
int pStrength = 100;
int bStrength = 101;
double milkMoney = 1.25;
for (num =1; milkMoney >= .25; num ++)
{
days (num);
cout <<"Your current strength is " << pStrength <<"." << endl;
cout <<"The bully's current strength is "<< bStrength <<"."<< endl;
cout <<"You have "<< milkMoney <<" left to spend on milk." << endl << endl;
choice1 (pStrength, bStrength, milkMoney);
}
if (pStrength > bStrength)
{
cout <<"With Final Strength of " << pStrength <<" our winner is..." << endl << endl << endl;
cout <<" " <<fullName<< endl << endl;
cout <<"CONGRATULATIONS!!! YOU DEFEATED THE BULLY ONCE AND FOR ALL!" << endl;
}
else if (bStrength > pStrength)
{
cout <<"With Final Strength of " << bStrength <<" our winner is..." << endl << endl << endl;
cout <<" THE BULLY" << endl << endl;
cout <<" Tough break kid. You tried, I grant you that. Maybe next week." << endl;
}
else if (pStrength == bStrength)
{
cout <<"With a matching strength of " << pStrength <<" our winner is..." << endl << endl << endl;
cout <<" NO ONE!!!" << endl << endl;
cout <<" Because you and the bully were tied at the end of the game, we have no winner." << endl;
cout <<" Please play the game again to try again at beating the bully." << endl;
}
}
void choice1 (int &pStrength, int &bStrength, double &milkMoney)
{
char choice = ' ';
cout <<"How do you wish to get to school today?" << endl;
do{
cout <<"Please press: " << endl;
cout <<" S to take the school bus" << endl <<" B to ride your bike" << endl;
cout <<" W to walk to school" << endl;
cin >> choice;
choice = toupper(choice);
switch (choice)
{
case 'S':
{
outcomes (pStrength, bStrength, milkMoney);
return;
}
case 'W':
{
outcomes (pStrength, bStrength, milkMoney);
return;
}
case 'B':
{
outcomes (pStrength, bStrength, milkMoney);
return;
}
default:
{
cout << " You've entered an invalid response." << endl;
}
}
}while(true);
}
void outcomes (int &pStrength, int &bStrength, double &milkMoney)
{
int randNum = 0;
randNum = 1 + rand() % (2 - 1 + 1);
if (randNum == 1)
{
cout << "You did not run into the bully today." << endl;
cout << "You bought milk today for 25 cents." << endl;
cout <<"Because you had your milk for the day, your" << endl;
cout << "strength has increased by 1 point." << endl << endl << endl;
pStrength = pStrength + 1;
milkMoney = milkMoney - .25;
}
else if (randNum == 2)
{
walk (pStrength, bStrength, milkMoney);
cout << endl << endl << endl;
}
}
void walk (int &pStrength, int &bStrength, double &milkMoney)
{
char choice2 = ' ';
cout << endl << "Good Grief! You ran into the bully today. What would you like to do?" << endl;
do{
cout <<"Please press: " << endl;
cout <<" F to stand up for yourself and fight" << endl <<" R to run away like think the little girl you are" << endl;
cin >> choice2;
choice2 = toupper(choice2);
switch (choice2)
{
case 'F':
{
fight (pStrength, bStrength, milkMoney);
return;
}
case 'R':
{
cout << "You give the bully your 25 cents. He lets you go but you don't get any milk today." << endl;
cout << "He takes your 25 cents and drinks your milk, adding 1 point to his strength." << endl << endl;
bStrength = bStrength + 1;
milkMoney = milkMoney - .25;
return;
}
default:
{
cout << " You've entered an invalid response." << endl;
}
}
}while(true);
}
void fight (int &pStrength, int &bStrength, double &milkMoney)
{
int pPunch = 0;
int bPunch = 0;
pPunch = 1 + rand() % (pStrength - 1 + 1);
bPunch = 1 + rand() % (bStrength - 1 + 1);
cout <<"You hit the bully with a punch strength of " << pPunch <<"." << endl;
cout <<"The bully hit you with a punch strength of " << bPunch <<"." << endl << endl;
if (pPunch > bPunch)
{
cout << "Yea! You defeated the bully." << endl;
cout << "You bought milk today for 25 cents. Because you had your milk for the day," << endl;
cout << " your strength has increased by 1 point." << endl;
pStrength = pStrength + 1;
bStrength = bStrength - 1;
milkMoney = milkMoney - .25;
}
else if (pPunch < bPunch)
{
cout << "Awww... Poor thing. The bully has defeated you." <<endl <<"And worse yet, he took your 25 cents" << endl << "and drank your milk." << endl;
cout << "He adds 1 point to his strength while you take the day to recover." << endl <<"You lose 1 point." << endl;
pStrength = pStrength - 1;
bStrength = bStrength + 1;
milkMoney = milkMoney - .25;
}
else if (pPunch == bPunch)
{
cout <<"You and the bully fight to a tie." << endl;
cout <<"You lose your 25 cents during the fight." << endl;
cout <<"Neither of you change strength." << endl << endl;
milkMoney = milkMoney - .25;
}
}
void days (int &num)
{
if (num == 1)
{
cout << "Today is Monday." << endl;
}
else if (num == 2)
{
cout << "Today is Tuesday." << endl;
}
else if (num ==3)
{
cout << "Today is Wednesday." << endl;
}
else if (num ==4)
{
cout << "Today is Thrusday." << endl;
}
else if (num ==5)
{
cout << "Today is Friday." << endl;
}
}
void dowStart (int &num)
{
if (num == 1)
{
cout << "Welcome to town. You must be new here." << endl;
}
else
{
while (num != 1)
{
cout << endl << "I said press 1 to start. When you make your game you may have the " << endl <<"player press " << num <<" to start your game. This is my game." << endl;
cout << endl << "Please prese 1 to begin." << endl;
cin >> num;
cout << endl;
}
}
}
|