Setting up for a redesign of the engine to have the real game mechanics. Using the fsm.hpp code.
This commit is contained in:
parent
7c9bea81b2
commit
1c89afaee2
3 changed files with 56 additions and 10 deletions
2
Makefile
2
Makefile
|
@ -16,7 +16,7 @@ test:
|
|||
meson test -C builddir --suite turings_tarpit
|
||||
|
||||
# make an install for real maybe copy dll and .exe to dir and zip?
|
||||
install: build
|
||||
install: build test
|
||||
powershell "cp ./builddir/subprojects/libgit2-1.8.1/liblibgit2package.dll ."
|
||||
powershell "cp ./builddir/subprojects/efsw/libefsw.dll ."
|
||||
powershell "cp builddir/escape_turings_tarpit.exe ."
|
||||
|
|
|
@ -59,3 +59,23 @@ void GameEngine::heal() {
|
|||
bool GameEngine::is_dead() {
|
||||
return hit_points <= 0;
|
||||
}
|
||||
|
||||
void GameEngine::start(GameEvent ev) {
|
||||
state(GameState::IDLE);
|
||||
}
|
||||
|
||||
void GameEngine::idle(GameEvent ev) {
|
||||
state(GameState::IDLE);
|
||||
}
|
||||
|
||||
void GameEngine::in_round(GameEvent ev) {
|
||||
state(GameState::IN_ROUND);
|
||||
}
|
||||
|
||||
void GameEngine::dead(GameEvent ev) {
|
||||
state(GameState::DEAD);
|
||||
}
|
||||
|
||||
void GameEngine::alive(GameEvent ev) {
|
||||
state(GameState::ALIVE);
|
||||
}
|
||||
|
|
|
@ -4,10 +4,21 @@
|
|||
#include <map>
|
||||
#include <array>
|
||||
#include <sstream>
|
||||
#include "fsm.hpp"
|
||||
|
||||
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{
|
||||
{"error", 4},
|
||||
{"warning", 1},
|
||||
|
@ -20,6 +31,7 @@ class GameEngine {
|
|||
int hits_taken = 0;
|
||||
int rounds = 0;
|
||||
int streak = 0;
|
||||
GameState _state = GameState::START;
|
||||
|
||||
GameEngine(int hp);
|
||||
|
||||
|
@ -27,16 +39,30 @@ class GameEngine {
|
|||
GameEngine(GameEngine &g) = delete;
|
||||
|
||||
int determine_damage(string &type);
|
||||
|
||||
void start_round();
|
||||
|
||||
void end_round();
|
||||
|
||||
bool hit(string &type);
|
||||
|
||||
bool is_dead();
|
||||
|
||||
void heal();
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
||||
|
||||
// current API that will die
|
||||
void start_round();
|
||||
void end_round();
|
||||
void heal();
|
||||
bool hit(string &type);
|
||||
void reset();
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue