-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclasses.cpp
67 lines (59 loc) · 2.08 KB
/
classes.cpp
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
#include "classes.h"
#include <string>
#include <iostream>
void GameStructure::Help() {} // virtual empty method
// CHARACTER STUFF
int Character::getHealth() { // health getter method
return Health;
}
void Character::setHealth(int health) { // health setter method
Health = health;
if (Health <= 0) { // character is dead if health is less than or equal to zero
Health = 0; // in case health is less than zero, reset it to zero
cout << Name << " has Expired..." << endl;
}
}
void Character::defend(int hitPoints) {
int newHealth = getHealth() - hitPoints; // what will the health be after attack?
setHealth(newHealth); // set the new health
}
void Character::Talk(string stuffToSay) { // method for character to speak
cout << endl << stuffToSay << endl << endl;
}
void Character::Talk(string name, string stuffToSay) { // another method for character to speak, but allows name to be passed in as well
cout << endl << "I'm " << name << ", and " << stuffToSay << endl << endl;
}
int Character::Attack() { // default attack method for character results in 10 hit points
return 10; // attack returns 10 hit points
}
void Character::Help() {} // overriding help method
// NINJA STUFF:
Ninja::Ninja(string N, int H) { // constructor
Name = N; // define name
setHealth(H); // initialize starting health
}
void Ninja::ThrowStars() {
Talk(Name, "I am throwing stars!");
}
int Ninja::Attack() {
ThrowStars(); // throw some stars
return 25; // overrride superclass method
}
void Ninja::Help() {
cout << endl << "Ninjas are quiet and swift; you can use them to throw stars!" << endl << endl;
}
// PIRATE STUFF:
Pirate::Pirate(string N, int H) { // constructor
Name = N; // define name
setHealth(H); // initialize starting health
}
void Pirate::UseSword() {
Talk(Name, "I am Swooshing my Sword!");
}
int Pirate::Attack() {
UseSword(); // use the sword
return 25; // overrride superclass method
}
void Pirate::Help() {
cout << endl << "Pirates are loud and forceful; you can use them to attack with swords!" << endl << endl;
}