-
Notifications
You must be signed in to change notification settings - Fork 0
/
combatLibrary.h
101 lines (76 loc) · 1.98 KB
/
combatLibrary.h
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
94
95
96
97
98
99
100
101
// Combat Library for NateScape
using namespace std;
#include <iostream>
#include <cstdio>
#include <unordered_map>
// Generic Class Template
class Class {
// Access Specifiers
private:
// Private Attributes and Methods
public:
// Public Attributes and Methods
};
// base/super creature class
class Creature {
// Access Specifiers
private:
// Private Atributes and Methods
int hitpoints;
int attack;
int defense;
public:
// Constructor
Creature(int hp, int atk, int def) {
hitpoints = hp;
attack = atk;
defense = def;
}
// change hitpoints
void modifyHP(int change){
hitpoints += change;
// hitpoints cannot be negative
if(hitpoints <= 0) {
hitpoints = 0;
}
}
// change attack
void modifyAttack(int change){
attack += change;
// attack cannot be negative
if(attack <= 0) {
attack = 0;
}
}
// change defense
void modifyDefense(int change){
defense += change;
}
// get hitpoints
int getHitpoints() {
cout << hitpoints << endl;
return hitpoints;
}
// get attack
int getAttack() {
cout << attack << endl;
return attack;
}
// get defense
int getDefense() {
cout << defense << endl;
return defense;
}
}
// Skeleton (5 hp, 3 atk, 0 def)
class Skeleton: public Creature(5, 3, 0) {
}
// Goblin (10 hp, 2 atk, 1 def)
class Goblin: public Creature(10, 2, 1) {
}
// Orc (15 hp, 1 atk, 2 def)
class Orc: public Creature(15, 1, 2) {
}
// Troll (20 hp, 0 atk, 3 def)
class Troll: public Creature(20, 0, 3) {
}