You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
1.5 KiB
75 lines
1.5 KiB
#pragma once
|
|
|
|
#include <string>
|
|
#include <map>
|
|
#include <array>
|
|
#include <sstream>
|
|
#include "fsm.hpp"
|
|
#include <fmt/core.h>
|
|
|
|
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,
|
|
TASK_DONE, TIMER_EXPIRED
|
|
};
|
|
|
|
enum class GameBonus {
|
|
MORE_HP, FREE_DEATH
|
|
};
|
|
|
|
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 deaths = 0;
|
|
int streak = 0;
|
|
float hp_bonus = 1.0f;
|
|
bool free_death = false;
|
|
|
|
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, string hit_type="") {
|
|
switch(_state) {
|
|
FSM_STATE(GameState, START, ev);
|
|
FSM_STATE(GameState, IDLE, ev);
|
|
FSM_STATE(GameState, DEAD, ev);
|
|
FSM_STATE(GameState, SUCCESS, ev);
|
|
FSM_STATE(GameState, FAILURE, ev);
|
|
FSM_STATE(GameState, IN_ROUND, ev, hit_type);
|
|
}
|
|
}
|
|
|
|
void START(GameEvent ev);
|
|
void IDLE(GameEvent ev);
|
|
void IN_ROUND(GameEvent ev, string &hit_type);
|
|
void DEAD(GameEvent ev);
|
|
void SUCCESS(GameEvent ev);
|
|
void FAILURE(GameEvent ev);
|
|
|
|
void heal();
|
|
bool hit(string &type);
|
|
void reset();
|
|
void add_bonus(GameBonus bonus);
|
|
int max_hp();
|
|
};
|
|
|