Game engine now handles damage types but Ineed to refine the state machines so some of them can take additional data.

This commit is contained in:
Zed A. Shaw 2024-09-12 01:25:23 -04:00
parent 9e6c05eccd
commit 4b2ed2951e
3 changed files with 35 additions and 17 deletions

View file

@ -5,6 +5,7 @@
#include <array>
#include <sstream>
#include "fsm.hpp"
#include <fmt/core.h>
using std::string;
@ -41,21 +42,35 @@ class GameEngine : DeadSimpleFSM<GameState, GameEvent> {
int determine_damage(string &type);
bool is_dead();
void event(GameEvent ev, string &hit_type) {
switch(_state) {
case GameState::IN_ROUND:
in_round(ev, hit_type);
break;
default:
event(ev);
}
}
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);
case GameState::IN_ROUND: {
string hit_type = "";
in_round(ev, hit_type);
}
break;
}
}
// FSM to replace the others
void start(GameEvent ev);
void idle(GameEvent ev);
void in_round(GameEvent ev);
void in_round(GameEvent ev, string &hit_type);
void dead(GameEvent ev);
void success(GameEvent ev);
void failure(GameEvent ev);