-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenergy.cpp
86 lines (74 loc) · 895 Bytes
/
energy.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "energy.h"
#include "map.h"
#include <QDebug>
Energy::Energy()
{
energy = 100;
}
Energy::Energy(int e)
{
energy = e;
}
bool Energy::sub_time()
{
return sub(1);
// qDebug()<<energy;
}
bool Energy::attack()
{
return sub(3);
}
bool Energy::pick()
{
return sub(2);
}
bool Energy::eat(int n)
{
if(n==9) {
return sub(5);
} else if(n==10) {
return add(20);
}
}
bool Energy::die()
{
if(energy<=0) {
map->show_die();
return true;
} else {
return false;
}
}
int Energy::get_energy()
{
return energy;
}
bool Energy::set_energy(int e)
{
energy = e;
}
bool Energy::add(int e)
{
if(energy == 100) {
return false;
} else {
energy+=e;
if(energy > 100) {
energy = 100;
}
return true;
}
}
bool Energy::sub(int e) {
energy -= e;
if(energy <= 0) {
energy = 0;
return !die();
} else {
return true;
}
}
void Energy::set_map(Map *m)
{
map = m;
}