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

master
Zed A. Shaw 2 months ago
parent 9e6c05eccd
commit 4b2ed2951e
  1. 2
      builder.cpp
  2. 17
      game_engine.cpp
  3. 19
      game_engine.hpp

@ -91,7 +91,7 @@ void Builder::building(BuildEvent ev) {
if(m.match) {
gui.output(format("HIT WITH {} @ {}:{}:{} {}", m.type, m.file_name, m.lnumber, m.col, m.message));
game.event(GameEvent::HIT);
game.event(GameEvent::HIT, m.type);
}
state(READING);
}

@ -61,20 +61,23 @@ void GameEngine::idle(GameEvent ev) {
}
}
void GameEngine::in_round(GameEvent ev) {
if(ev == GameEvent::HIT) {
string er_type = "error";
hit(er_type); // FIXME: bring back error type
void GameEngine::in_round(GameEvent ev, string &hit_type) {
switch(ev) {
case GameEvent::HIT:
hit(hit_type); // FIXME: bring back error type
if(is_dead()) {
state(GameState::DEAD);
} else {
state(GameState::IN_ROUND);
}
} else if(ev == GameEvent::BUILD_SUCCESS) {
break;
case GameEvent::BUILD_SUCCESS:
state(GameState::SUCCESS);
} else if(ev == GameEvent::BUILD_FAILED) {
break;
case GameEvent::BUILD_FAILED:
state(GameState::FAILURE);
} else {
break;
default:
state(GameState::IN_ROUND);
}
}

@ -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);

Loading…
Cancel
Save