|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <map>
|
|
|
|
#include <array>
|
|
|
|
#include <sstream>
|
|
|
|
#include "fsm.hpp"
|
|
|
|
|
|
|
|
using std::string;
|
|
|
|
|
|
|
|
enum class GameState {
|
|
|
|
START, IDLE, IN_ROUND, DEAD, SUCCESS, FAILURE
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
enum class GameEvent {
|
|
|
|
BUILD_START, BUILD_SUCCESS,
|
|
|
|
BUILD_DONE, BUILD_FAILED, HIT
|
|
|
|
};
|
|
|
|
|
|
|
|
class GameEngine : DeadSimpleFSM<GameState, GameEvent> {
|
|
|
|
|
|
|
|
std::map<string, int> damage_types{
|
|
|
|
{"error", 4},
|
|
|
|
{"warning", 1},
|
|
|
|
{"note", 0},
|
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
|
|
|
int starting_hp = 0;
|
|
|
|
int hit_points = 0;
|
|
|
|
int hits_taken = 0;
|
|
|
|
int rounds = 0;
|
|
|
|
int streak = 0;
|
|
|
|
|
|
|
|
GameEngine(int hp);
|
|
|
|
|
|
|
|
// FOUND BUG: I was accidentally copying this and shouldn't have been
|
|
|
|
GameEngine(GameEngine &g) = delete;
|
|
|
|
|
|
|
|
int determine_damage(string &type);
|
|
|
|
bool is_dead();
|
|
|
|
|
|
|
|
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::SUCCESS, success, ev);
|
|
|
|
FSM_STATE(GameState::FAILURE, failure, ev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// FSM to replace the others
|
|
|
|
void start(GameEvent ev);
|
|
|
|
void idle(GameEvent ev);
|
|
|
|
void in_round(GameEvent ev);
|
|
|
|
void dead(GameEvent ev);
|
|
|
|
void success(GameEvent ev);
|
|
|
|
void failure(GameEvent ev);
|
|
|
|
|
|
|
|
// current API that will die
|
|
|
|
void heal();
|
|
|
|
bool hit(string &type);
|
|
|
|
void reset();
|
|
|
|
};
|