Refined the FSM to allow easily passing in data to the even handler and state functions.
This commit is contained in:
parent
40ba7f0b66
commit
c9425aebf9
7 changed files with 75 additions and 74 deletions
|
@ -48,32 +48,15 @@ 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, const char *hit_type) {
|
||||
string ht{hit_type};
|
||||
event(ev, ht);
|
||||
}
|
||||
|
||||
void event(GameEvent ev) {
|
||||
void event(GameEvent ev, string hit_type="") {
|
||||
switch(_state) {
|
||||
FSM_STATE(GameState, START, start, ev);
|
||||
FSM_STATE(GameState, IDLE, idle, 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 = "";
|
||||
case GameState::IN_ROUND:
|
||||
in_round(ev, hit_type);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue