-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmonster.cpp
More file actions
89 lines (71 loc) · 1.99 KB
/
monster.cpp
File metadata and controls
89 lines (71 loc) · 1.99 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
#include <iostream>
using namespace std;
#include "main.h"
#include "unit.h"
#include "monster.h"
#include "pet.h"
#include "board.h"
//------------------------------------------------------------------------------
// class Monster
//------------------------------------------------------------------------------
Monster::Monster() : Unit(MONSTER_SHAPE, MONSTER_ROW, MONSTER_COL, MONSTER_DIR, MONSTER_HP, MONSTER_MAX_HP, MONSTER_MP, MONSTER_MAX_MP, MONSTER_ATK, MONSTER_DEF, MONSTER_GOLD, MONSTER_EXP) {
}
Monster::Monster(char shape, int row, int col, int dir, int hp, int maxHp, int mp, int maxMp, int atk, int def, int gold, int exp)
: Unit(shape, row, col, dir, hp, maxHp, mp, maxMp, atk, def, gold, exp) {
}
Monster::~Monster() {
}
void Monster::move(int dir) {
if (died || frozen) {
return;
}
this->dir = dir;
bool moved = false;
int prevRow = row;
int prevCol = col;
int nextRow = row;
int nextCol = col;
if (dir == DIR_N) {
nextRow--;
}
else if (dir == DIR_E) {
nextCol++;
}
else if (dir == DIR_S) {
nextRow++;
}
else if (dir == DIR_W) {
nextCol--;
}
if (nextRow >= 0 && nextRow < board->getRowSize() &&
nextCol >= 0 && nextCol < board->getColSize() &&
board->getUnit(nextRow, nextCol) == NULL &&
board->getProp(nextRow, nextCol) == NULL) {
board->setUnit(prevRow, prevCol, NULL);
board->setUnit(nextRow, nextCol, this);
moved = true;
}
}
bool Monster::isMonster() {
return true;
}
//battle
void Monster::interact(Unit *unit) {
if (unit == NULL) {
cout << "Monster::interact(): error: unit == NULL" << endl;
exit(1);
}
if (isDead()) {
return;
}
decHp(unit->getAtk()); //ADD hero hits mon
if (!isDead()) {
unit->decHp(atk);
}
else {
unit->incGold(gold);
unit->incExp(exp);
decGold(gold);
decGold(exp);
}
}