-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVampire.cpp
More file actions
85 lines (69 loc) · 1.92 KB
/
Copy pathVampire.cpp
File metadata and controls
85 lines (69 loc) · 1.92 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
/*********************************************************************
** Program name: Project4
** Author: James Scanlon
** Date: March 3, 2019
** Description: Implementation for the Vampire class. Inherits from character and has a 50% chance to charm the opponent and take no damage.
*********************************************************************/
#include <cstdlib>
#include "Character.hpp"
#include "Vampire.hpp"
#include <iostream>
using namespace std;
Vampire::Vampire() : Character::Character(){
attackValue = 12;
defenseValue = 6;
armor = 1;
strength = 18;
attackDice = 1;
defendDice = 1;
type = "Vampire";
specialMessage = false;
}
int Vampire::attack(){
int damage = 0;
for (int i = 0; i < attackDice; i++)
{
damage += ((rand() % attackValue) + 1);
}
currentAttack = damage;
return damage;
}
void Vampire::defense(int damage)
{
int charmChance = rand() % 2;
if (charmChance) // 50% of the time Vampire will have 99 defend via "charm"
{
currentDefend = 99;
specialMessage = true; // enables special message when charm hits
}
else
{
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)
{
strength = 0;
}
}
currentDefend = roll;
}
}
void Vampire::recovery()
{
strength += .5 * (baseStrength - strength);
}
void Vampire::specialNotice(){ // charm message; resets bool after invoked
if (specialMessage){
cout << "Vampire used charm to defend itself!" << endl;
specialMessage = false;
}
}
Vampire::~Vampire()
{
}