-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrpg.cpp
More file actions
83 lines (77 loc) · 2.41 KB
/
rpg.cpp
File metadata and controls
83 lines (77 loc) · 2.41 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
#include <stdio.h>
#include <time.h>
#include <iostream>
#include "Character.h"
using namespace std;
//CS-3100-02, John McGuff, Project-2
//This is a program that simulates an rpg battle between two characters created by the user.
//Function that creates the character
Character characterCreate(){
//instantiate necessary variables to avoid making the computer upset
string plyrName = "";
string plyrRole = "";
int plyrHealth = 0;
int plyrAtkBonus = 0;
int plyrDmgBonus = 0;
int plyrAC = 0;
cout << "What is your character's name?" << endl;
//Prompt for, and store the input for all the character information
cin >> plyrName;
cout << "What is your character's role?" << endl;
cin >> plyrRole;
cout << "What is your character's Health Total?" << endl;
cin >> plyrHealth;
cout << "What is your character's Attack Bonus?" << endl;
cin >> plyrAtkBonus;
cout << "What is your character's Damage Bonus?" << endl;
cin >> plyrDmgBonus;
cout << "What is your character's Armor Class?" << endl;
cin >> plyrAC;
//Return the character that was made
return Character(plyrName, plyrRole, plyrHealth, plyrAtkBonus, plyrDmgBonus, plyrAC);
}
void combat(Character player, Character enemy)
{
while(player.getHealth() != 0 && enemy.getHealth() != 0)
{
int turnOrder = rand() % 2;
if(turnOrder < 1)
{
player.attack(enemy);
if(enemy.getHealth() != 0)
{
enemy.attack(player);
}
}
else
{
enemy.attack(player);
if(player.getHealth() != 0)
{
player.attack(enemy);
}
}
}
if(player.getHealth() < 1)
{
cout << player.getName() << " has perished!" << endl;
}
else
{
cout << enemy.getName() << " has been vanquished!" << endl;
}
}
int main()
{
//Instatiate, then print both characters to the console
Character playerChar = characterCreate();
playerChar.print(cout);
Character enemyChar = characterCreate();
enemyChar.print(cout);
//getting that random seed going
srand(time(nullptr));
//Commence the battle
cout << "Simulated combat:" << endl;
combat(playerChar, enemyChar);
return 0;
}