|
|
@ -4,10 +4,21 @@ |
|
|
|
#include <map> |
|
|
|
#include <map> |
|
|
|
#include <array> |
|
|
|
#include <array> |
|
|
|
#include <sstream> |
|
|
|
#include <sstream> |
|
|
|
|
|
|
|
#include "fsm.hpp" |
|
|
|
|
|
|
|
|
|
|
|
using std::string; |
|
|
|
using std::string; |
|
|
|
|
|
|
|
|
|
|
|
class GameEngine { |
|
|
|
enum class GameState { |
|
|
|
|
|
|
|
START, IDLE, IN_ROUND, DEAD, ALIVE |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
enum class GameEvent { |
|
|
|
|
|
|
|
BUILD_START, BUILD_END, |
|
|
|
|
|
|
|
HIT |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class GameEngine : DeadSimpleFSM<GameState, GameEvent> { |
|
|
|
std::map<string, int> damage_types{ |
|
|
|
std::map<string, int> damage_types{ |
|
|
|
{"error", 4}, |
|
|
|
{"error", 4}, |
|
|
|
{"warning", 1}, |
|
|
|
{"warning", 1}, |
|
|
@ -20,6 +31,7 @@ class GameEngine { |
|
|
|
int hits_taken = 0; |
|
|
|
int hits_taken = 0; |
|
|
|
int rounds = 0; |
|
|
|
int rounds = 0; |
|
|
|
int streak = 0; |
|
|
|
int streak = 0; |
|
|
|
|
|
|
|
GameState _state = GameState::START; |
|
|
|
|
|
|
|
|
|
|
|
GameEngine(int hp); |
|
|
|
GameEngine(int hp); |
|
|
|
|
|
|
|
|
|
|
@ -27,16 +39,30 @@ class GameEngine { |
|
|
|
GameEngine(GameEngine &g) = delete; |
|
|
|
GameEngine(GameEngine &g) = delete; |
|
|
|
|
|
|
|
|
|
|
|
int determine_damage(string &type); |
|
|
|
int determine_damage(string &type); |
|
|
|
|
|
|
|
bool is_dead(); |
|
|
|
|
|
|
|
|
|
|
|
void start_round(); |
|
|
|
void event(GameEvent ev) { |
|
|
|
|
|
|
|
switch(_state) { |
|
|
|
|
|
|
|
FSM_STATE(GameState::START, start, ev); |
|
|
|
|
|
|
|
FSM_STATE(GameState::IDLE, idle, ev); |
|
|
|
|
|
|
|
FSM_STATE(GameState::IN_ROUND, in_round, ev); |
|
|
|
|
|
|
|
FSM_STATE(GameState::DEAD, dead, ev); |
|
|
|
|
|
|
|
FSM_STATE(GameState::ALIVE, alive, ev); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void end_round(); |
|
|
|
// FSM to replace the others
|
|
|
|
|
|
|
|
void start(GameEvent ev); |
|
|
|
|
|
|
|
void idle(GameEvent ev); |
|
|
|
|
|
|
|
void in_round(GameEvent ev); |
|
|
|
|
|
|
|
void dead(GameEvent ev); |
|
|
|
|
|
|
|
void alive(GameEvent ev); |
|
|
|
|
|
|
|
|
|
|
|
bool hit(string &type); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool is_dead(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// current API that will die
|
|
|
|
|
|
|
|
void start_round(); |
|
|
|
|
|
|
|
void end_round(); |
|
|
|
void heal(); |
|
|
|
void heal(); |
|
|
|
|
|
|
|
bool hit(string &type); |
|
|
|
void reset(); |
|
|
|
void reset(); |
|
|
|
}; |
|
|
|
}; |
|
|
|