-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathARuizLab7.cpp
More file actions
407 lines (294 loc) · 11.2 KB
/
ARuizLab7.cpp
File metadata and controls
407 lines (294 loc) · 11.2 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
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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
//anthony ruiz
//CPSC 121 Lab 7
// 03/25/19
/*this is a simulation of a video game where two gladiators fight*/
#include<iostream>
#include<iomanip>
#include<random>
#include<string>
using namespace std;
struct gladiator {
string name;
double maxHealth;
double currentHealth;
double evasion;
double critical;
double minDamage;
double damageRange;
};
int main()
{
//variables
string gladiator1, gladiator2;
int rStatsOk=0;
int playerOneStats=1,playerTwoStats=1;
int rematch;
int newfightergame;
//prototypes
gladiator createGladiator(string);
void showStats(gladiator);
gladiator taketurn(gladiator attacker, gladiator &defender);
//end of prototypes
//tags for the strucrture
gladiator gladiatorOne;
gladiator gladiatorTwo;
gladiator rematchCharacterTwo;
gladiator rematchCharacterOne;
//end of tags for structures
cout << "You're about to host a fight! good luck!\n";
cout << "what will be the name of your first gladiator?"<< endl;//gladiator 2
getline(cin,gladiator1);//gets name
cout<< endl;
gladiatorOne = createGladiator(gladiator1);//assigns stats to gladiator 1
rematchCharacterOne = gladiatorOne;//makes a copy of the structure to be used in rematch
cout<<endl;
cout << "what will be the name of your second gladiator?"<<endl;//gladiator 1
getline(cin,gladiator2);//gets name
cout<< endl;
gladiatorTwo = createGladiator(gladiator2);//assigns stats to gladiator 2
rematchCharacterTwo = gladiatorTwo;//makes a copy of the structure to be used in rematch
//insert function to display stats
cout<<endl;
showStats(gladiatorOne);
showStats(gladiatorTwo);
cout<< endl;
//cheching if player stats are ok
do{
cout<< "Are the stats for "<< gladiatorOne.name<< " ok?\n";
cout<< "(0 = Yes ,1 = No )\n";
cin >>rStatsOk;
playerOneStats= rStatsOk;
if (rStatsOk == 1)
{
gladiatorOne = createGladiator(gladiator1);
rematchCharacterOne = gladiatorOne;
}
cout << endl;
cout<< "Are the stats for "<< gladiatorTwo.name<< " ok?\n";
cout<< "(0 = Yes ,1 = No )\n";
cin >>rStatsOk;
playerTwoStats=rStatsOk;
if (rStatsOk == 1)
{
gladiatorTwo = createGladiator(gladiator2);
rematchCharacterTwo = gladiatorTwo;
}
cout << "\nYour new stats are...\n";
showStats(gladiatorOne);
showStats(gladiatorTwo);
}while (playerOneStats == 1 || playerTwoStats==1);//loops until players are satisfied with stats.
/********************************************************
both of the gladiators have been created
*********************************************************/
cout<<"\n\n";
cout<<" ****** * ******* * * ******** **\n";
cout<<" * * * * * ** **\n";
cout<<" ****** * * *** ****** ** **\n";
cout<<" * * * * * * ** **\n";
cout<<" * * ******* * * ** \n";
cout<<" **\n\n\n";
do {
taketurn(gladiatorOne, gladiatorTwo);
showStats(gladiatorTwo);
if (gladiatorTwo.currentHealth <= 0)
{
break;
}
taketurn(gladiatorTwo, gladiatorOne);
showStats(gladiatorOne);
}while(gladiatorOne.currentHealth > 0 && gladiatorTwo.currentHealth > 0);
cout<< "\n\n would you like a rematch? With the same characters?( 1 = yes,2 = no)";
cin >> rematch;
cout << "\nwould you like a game with new fighters?(1=yes, 2=no)\n";
cin >> newfightergame;
cout << endl;
//starting a new game with different fighters
//start of new fighter loop
while (newfightergame == 1){
cout << "what will be the name of your first gladiator?"<< endl;//gladiator 2
getline(cin,gladiator1);//gets name
cout<< endl;
gladiatorOne = createGladiator(gladiator1);//assigns stats to gladiator 1
rematchCharacterOne = gladiatorOne;//makes a copy of the structure to be used in rematch
cout<<endl;
cout << "what will be the name of your second gladiator?"<<endl;//gladiator 1
getline(cin,gladiator2);//gets name
cout<< endl;
gladiatorTwo = createGladiator(gladiator2);//assigns stats to gladiator 2
rematchCharacterTwo = gladiatorTwo;//makes a copy of the structure to be used in rematch
//insert function to display stats
cout<<endl;
showStats(gladiatorOne);
showStats(gladiatorTwo);
cout<< endl;
//cheching if player stats are ok
do{
cout<< "Are the stats for "<< gladiatorOne.name<< " ok?\n";
cout<< "(0 = Yes ,1 = No )\n";
cin >>rStatsOk;
playerOneStats= rStatsOk;
if (rStatsOk == 1)
{
gladiatorOne = createGladiator(gladiator1);
rematchCharacterOne = gladiatorOne;
}
cout << endl;
cout<< "Are the stats for "<< gladiatorTwo.name<< " ok?\n";
cout<< "(0 = Yes ,1 = No )\n";
cin >>rStatsOk;
playerTwoStats=rStatsOk;
if (rStatsOk == 1)
{
gladiatorTwo = createGladiator(gladiator2);
rematchCharacterTwo = gladiatorTwo;
}
cout << "\nYour new stats are...\n";
showStats(gladiatorOne);
showStats(gladiatorTwo);
}while (playerOneStats == 1 || playerTwoStats==1);//loops until players are satisfied with stats.
/********************************************************
both of the gladiators have been created
*********************************************************/
cout<<"\n\n";
cout<<" ****** * ******* * * ******** **\n";
cout<<" * * * * * ** **\n";
cout<<" ****** * * *** ****** ** **\n";
cout<<" * * * * * * ** **\n";
cout<<" * * ******* * * ** \n";
cout<<" **\n\n\n";
do {
taketurn(gladiatorOne, gladiatorTwo);
showStats(gladiatorTwo);
if (gladiatorTwo.currentHealth <= 0)
{
break;
}
taketurn(gladiatorTwo, gladiatorOne);
showStats(gladiatorOne);
}while(gladiatorOne.currentHealth > 0 && gladiatorTwo.currentHealth > 0);
cout<< "\n\n would you like a rematch? With the same characters?( 1 = yes,2 = no)";
cin >> rematch;
cout << "\nwould you like a game with new fighters?(1=yes, 2=no)\n";
cin >> newfightergame;
cout << endl;
}//end of new fighter loop
//ending of new fighter game
while(rematch == 1)//this will be the rematch
{
cout<<"\n\n";
cout<<" ****** * ******* * * ******** **\n";
cout<<" * * * * * ** **\n";
cout<<" ****** * * *** ****** ** **\n";
cout<<" * * * * * * ** **\n";
cout<<" * * ******* * * ** \n";
cout<<" **\n\n\n";
do {
taketurn(rematchCharacterOne, rematchCharacterTwo);
showStats(rematchCharacterTwo);
if (rematchCharacterTwo.currentHealth <= 0)
{
break;
}
taketurn(rematchCharacterTwo, rematchCharacterOne);
showStats(rematchCharacterOne);
}while(rematchCharacterOne.currentHealth > 0 && rematchCharacterTwo.currentHealth > 0);
cout<< "\n\n would you like a rematch? With the same characters?( 1 = yes,2 = no)";
cin >> rematch;
}
return 0;
}
/**********************************************************************
start of function defenitions
***********************************************************************/
gladiator createGladiator(string gladname)
{
gladiator gladiatorOne;//structure tag.
/* random number generator */
default_random_engine myEngine {random_device{}()};
uniform_int_distribution<int> onetothreeDistribution {1,3};
uniform_int_distribution<int> eighttoforteenDistribution {8,14};
uniform_int_distribution<int> sixttwentDistribution {16,22};
/* end of the random number generator*/
//temorary structure variable
int randomNum;//stores a random number
/*****************************************************************************/
//getting name
gladiatorOne.name = gladname;//passing the name to the structure
/*****************************************************************************/
//getting health
randomNum = onetothreeDistribution(myEngine);//generates a random number to pick health
if (randomNum==3){ gladiatorOne.maxHealth = 250;}//picks a health
if (randomNum==2){ gladiatorOne.maxHealth = 200;}//picks a health
if (randomNum==1){ gladiatorOne.maxHealth = 150;}//picks a health
gladiatorOne.currentHealth = gladiatorOne.maxHealth;
/*****************************************************************************/
//getting crit
randomNum = onetothreeDistribution(myEngine);//gets new random number
if(randomNum == 1){ gladiatorOne.critical = 5;}//picks a percentage of critical damage
if(randomNum == 2){ gladiatorOne.critical = 10;}//picks a percentage of critical damage
if(randomNum == 3){ gladiatorOne.critical = 15;}//picks a percentage of critical damage
/*****************************************************************************/
//getting min damage
gladiatorOne.minDamage = eighttoforteenDistribution(myEngine);
/*****************************************************************************/
//getting damage range
gladiatorOne.damageRange = sixttwentDistribution(myEngine);
return gladiatorOne; //returns the temporary strucrture variable where everything is stored
}
/*****************************************************************************
end of create gladiator function
*****************************************************************************/
/*****************************************************************************
start of show stats function
*****************************************************************************/
void showStats(gladiator TempStruct)
{
cout <<"Stats for: " << endl;
cout <<"Name: "<< TempStruct.name << endl;
cout <<"Health: "<< TempStruct.currentHealth <<endl;
cout <<"Critical: "<< TempStruct.critical <<"%"<< endl;
cout <<"Min Damage: "<<TempStruct.minDamage << endl;
cout <<"Damage Range: "<<TempStruct.damageRange <<endl;
cout <<"\n\n";
}
/*****************************************************************************/
//end of show stats function
/*****************************************************************************/
gladiator taketurn(gladiator attacker, gladiator &defender)
{
default_random_engine myEngine {random_device{}()};
uniform_int_distribution<int> onetotwoDistribution {1,2};
uniform_int_distribution<int> hundredDistribution {1,100};
int evaluator;//this willl evaluate what happns
int actualDamage; //holds value of the damage about to be inflicted
int numberOneToHundred;//holds a value from one to one hundred
evaluator = onetotwoDistribution(myEngine);
if (evaluator == 1)//you will miss
{
cout<< endl<< attacker.name <<"! You missed!\n";
}
if (evaluator == 2)//you will hit
{
numberOneToHundred = hundredDistribution(myEngine);
if (numberOneToHundred <= attacker.critical)
{
actualDamage = attacker.minDamage * 2;
defender.currentHealth = defender.currentHealth - actualDamage;
cout << "Its a hit!\n";
if (defender.currentHealth <= 0)
{
cout << attacker.name <<" you win!!\n";
}
}
else
{
cout << "Its a hit!\n";
defender.currentHealth = defender.currentHealth - attacker.minDamage;
if (defender.currentHealth <= 0)
{
cout << attacker.name <<" you win!!\n";
}
}
}
return defender;
}