-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHarryPotter.cpp
More file actions
78 lines (60 loc) · 2.05 KB
/
HarryPotter.cpp
File metadata and controls
78 lines (60 loc) · 2.05 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
/****************************
**Program: Final Project
**Name: Kirsten Carter
**Date: 6/3/2019
**Description: HarryPotter Class - Holds the attack and defend functions related to the character. Based directly on the game mechanics from Project3.
*****************************/
#include "HarryPotter.hpp"
#include <iostream>
HarryPotter::HarryPotter()
{
setArmor(0);
setStrength(14);
setCharacterType("Harry Potter");
}
/****************************
**attack: rolls two dice to get attack value.
*****************************/
int HarryPotter::attack()
{
int dice1 = (rand() % (6 + 1));
int dice2 = (rand() % (6 + 1));
int attackValue = dice1 + dice2;
setAttackRoll(attackValue);
std::cout << "Harry has attacked with Stupify that has an attack value of " << attackValue << "." << std::endl;
return attackValue;
}
/****************************
**defense: rolls two dice to get defense value.
*****************************/
int HarryPotter::defense(int oppAttack)
{
int defenseValue;
int dice1 = (rand() % (6 + 1));
int dice2 = (rand() % (6 + 1));
defenseValue = dice1 + dice2;
setDefendRoll(defenseValue);
int totalDamage = oppAttack - getArmor() - defenseValue;
if (totalDamage <= 0)
{
std::cout << "Harry used a Pergeo with a defense value of " << defenseValue << ". No damage to Harry's health. \n" << std::endl;
return 0;
}
else
{
int currentS = getStrength() - totalDamage;
if (currentS <= 0)
{
std::cout << "Harry has has been stunned and must to be escorted to the hospital wing by Hermione." << std::endl;
std::cout << "Better luck next time. \n" << std::endl;
currentS = 0; //set current Strength to 0 so there is no negative Strength
}
std::cout << "Harry used a Pergeo with a defense value of " << defenseValue << "." << std::endl;
std::cout << "Harry suffered a total damage of: " << totalDamage << " leaving him with a Health of: " << currentS << "\n" << std::endl;
setStrength(currentS);
return currentS;
}
}
HarryPotter::~HarryPotter()
{
}