-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcombatstate.cpp
More file actions
93 lines (79 loc) · 2.48 KB
/
combatstate.cpp
File metadata and controls
93 lines (79 loc) · 2.48 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
90
91
92
#include "combatstate.h"
CombatState::CombatState(){
combatProbability = 0;
enemy = Npc(10,5,0,3,"orc","fluffy");
enemy.printStats();
choices[ATTACK_OPTION] = "Attack the enemy.";
choices[FLEE_OPTION] = "Try to run away.";
choices[POWER_ATTACK_OPTION] = "Swing wildly.";
};
void CombatState::printOptions() {
wprintw(Display::text_win, "The enemy prepares to attack!\n");
for(auto i = choices.begin(); i != choices.end(); ++i){
wprintw(Display::text_win, "%c. %s\n", i->first, i->second.c_str());
}
};
void CombatState::handleInput(int choice, std::stack<GameState*>& stack, Player& p, World& w) {
GameState* tmpState;
Logger::debug("Combat state input: %d\n", choice);
char c = choice;
Logger::debug("Combat state input: %c\n", c);
switch(c){
case ATTACK_OPTION:
wprintw(Display::text_win, "You attack the enemy...\n");
p.attack(enemy);
if (enemy.isDead()){
wprintw(Display::text_win, "The enemy is dead! Collect your loot.\n");
// TODO: state to loot the body(s)?
p.lootItem();
tmpState = stack.top();
stack.pop();
delete tmpState;
return;
}
wprintw(Display::text_win, "The enemy attacks you...\n");
enemy.attack(p);
if (p.isDead()){
// TODO: endGameState
wprintw(Display::text_win, "You have died :(\n");
endwin();
exit(0);
}
break;
case FLEE_OPTION:
wprintw(Display::text_win, "You attempt to flee from the fight...\n");
if (rand()%100 + 1 > 50){
wprintw(Display::text_win, "You successfully retreat from the fight...\n");
tmpState = stack.top();
stack.pop();
delete tmpState;
} else {
wprintw(Display::text_win, "You could not escape, and the enemy attacks you!\n");
enemy.attack(p);
}
break;
case POWER_ATTACK_OPTION:
wprintw(Display::text_win, "You swing wildly!\n");
p.powerAttack(enemy);
if (enemy.isDead()){
wprintw(Display::text_win, "The enemy is dead!\n");
// TODO: state to loot the body(s)?
tmpState = stack.top();
stack.pop();
delete tmpState;
return;
}
wprintw(Display::text_win, "The enemy attacks you...\n");
enemy.attack(p);
if (p.isDead()){
// TODO: endGameState
wprintw(Display::text_win, "You have died :(\n");
endwin();
exit(0);
}
default:
break;
};
p.printStats();
enemy.printStats();
};