-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHarryPotter.cpp
More file actions
93 lines (78 loc) · 2.01 KB
/
Copy pathHarryPotter.cpp
File metadata and controls
93 lines (78 loc) · 2.01 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
/*********************************************************************
** Program name: Project4
** Author: James Scanlon
** Date: March 3, 2019
** Description: Implementation for the HarryPotter class. Inherits from character and when his health hits 0, he comes back at 20 strength one time.
*********************************************************************/
#include <cstdlib>
#include "HarryPotter.hpp"
#include <iostream>
using namespace std;
HarryPotter::HarryPotter() : Character::Character(){
attackValue = 6;
defenseValue = 6;
armor = 0;
strength = 10; // regens to 20
attackDice = 2;
defendDice = 2;
type = "Harry Potter";
hogwartsLeft = true;
specialMessage = false;
}
int HarryPotter::attack(){
int damage = 0;
for (int i = 0; i < attackDice; i++)
{
damage += ((rand() % attackValue) + 1);
}
currentAttack = damage;
return damage;
}
void HarryPotter::defense(int damage)
{
int roll = 0;
for (int i = 0; i < defendDice; i++)
{
roll += ((rand() % defenseValue) + 1);
}
if (damage > (roll - armor))
{
strength -= (damage - roll - armor);
if (strength <= 0)
{
if (hogwartsLeft) // hogwarts ability check
{
strength = 20;
specialMessage = true;
hogwartsLeft = false;
}
else
{
strength = 0;
}
}
}
currentDefend = roll;
}
void HarryPotter::recovery()
{
if (strength > baseStrength)
{
strength += .5 * (2 * baseStrength - strength);
}
else
{
strength += .5 * (baseStrength - strength);
}
}
//hogwarts special message
void HarryPotter::specialNotice()
{
if (specialMessage){
cout << "Harry Potter revived himself with Hogwarts! He now has 20 strength." << endl;
specialMessage = false;
}
}
HarryPotter::~HarryPotter()
{
}