-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBattleField.cpp
86 lines (70 loc) · 1.89 KB
/
BattleField.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 "BattleField.hpp"
void BattleField :: showBattleFieldStatus() {
std::cout << "<BattleFieldStatus>" << std::endl;
std::cout << "FGIHTER : " << fighter->getName() << std::endl;
std::cout << "MONSTER : " << monster->getName() << std::endl;
std::cout << std::endl;
}
void BattleField :: initBattleField() {
initTurn();
cycleTurn();
}
void BattleField :: cycleTurn() {
fighter->showStatus();
monster->showStatus();
startTurn();
switchTurn();
if(canEndBattle()) {
endBattle();
return;
}
cycleTurn();
}
void BattleField :: initTurn() {
int fighterSpd = fighter->getSpd();
int monsterSpd = monster->getSpd();
if(fighterSpd == monsterSpd) {
// 両者が同じ速さだった場合にランダムにターンを決定する
isFighterTurn = GeneralMethod::generateRandomSeed(0, 1);
} else if(monsterSpd < fighterSpd) {
isFighterTurn = true;
} else if(fighterSpd < monsterSpd) {
isFighterTurn = false;
}
}
void BattleField :: startTurn() {
if(isFighterTurn) {
fighter->attack(*monster);
} else {
monster->randomAttack(*fighter);
}
}
void BattleField :: switchTurn() {
isFighterTurn = !(isFighterTurn);
}
void BattleField :: endBattle() {
if(isVictory()) {
win();
} else {
lose();
}
}
bool BattleField :: canEndBattle() {
if(fighter->isAlive() == false || monster->isAlive() == false) return true;
return false;
}
bool BattleField :: isVictory() {
if(fighter->isAlive() && monster->isAlive() == false) {
return true;
}
return false;
}
void BattleField :: win() {
std::cout << "you win!!!" << std::endl;
// provide exp for fighter
fighter->earnExpFromEnemy(monster->getDropExpAmount());
fighter->updateLevel();
}
void BattleField :: lose() {
std::cout << "you lose..." << std::endl;
}