-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHarryP.cpp
More file actions
90 lines (61 loc) · 2.24 KB
/
HarryP.cpp
File metadata and controls
90 lines (61 loc) · 2.24 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
/****************************************************************************************************
* * Program name: CS162 Project3
* * Author: Taekyoung Kim
* * Date: 02/05/2019
* * Description: This is HarryP.cpp file for CS162 Project3
* * This project demonstrates a fantasy combat game.
* * There are 5 characters that have different ability and power.
* * The real game is done with a dice.
******************************************************************************************************/
#include "HarryP.h"
#include <iostream>
HarryP::HarryP() //= default;
:Character("Harry Potter", 10, 0)
{}
HarryP::~ HarryP() = default;
int HarryP::getNewLife() const{
return this->newLife;
}
void HarryP::setNewLife(int nLife){
newLife = nLife;
}
int HarryP::Attack() {
int roll = Character::Dice(2, 6);
std::cout << "Attacker: "<<getName()<<" Attacker's roll: "<<roll<<std::endl;
return roll;
}
void HarryP::Defense(int at) {
Character::Dice(2, 6);
int numOfDef = Character::Dice(2, 6);
int damage;
damage = at -(numOfDef + armor);
std::cout<<"Defender: "<<name;
std::cout<<" Defender's roll: "<<numOfDef<<std::endl;
std::cout<<"Defender's Armor: "<<armor<<" Strength: "<<getStrength()<<std::endl;
if ((getStrength() <= damage) && getNewLife() > 0 ) {
if(damage >= getStrength()) {
std::cout << "Total inflicted Damage: " <<getStrength();
}
else if(damage > 0 && damage < getStrength()){
std::cout<<"Total inflicted Damage: "<< damage;
}
setStrength(getNewLife());
std::cout<<" He lost all his strength."<<std::endl;
std::cout <<"But Harry Potter activates 'Hogwarts' and now his strength is 20." << std::endl;
setNewLife(0);
}
else {
if(damage >= getStrength()) {
std::cout << "Total inflicted Damage: " << getStrength() << std::endl;
setStrength(0);
}
else if (damage > 0 && damage < getStrength()) {
std::cout << "Total inflicted Damage: " << damage << std::endl;
setStrength(strength - damage);
}
else if(damage <= 0)
{
std::cout << "Damage: " << 0 << std::endl;
}
}
}