A stealth-based 2D platformer where you don't have to kill anyone unless you want to. https://www.semicolin.games
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.
 
 
 

37 lines
946 B

using System.Collections.Generic;
namespace SemiColinGames {
public interface IState<T> {
public void Enter();
// Returns the name of the new state, or null if we should stay in the same state.
public string Update(T obj, float modelTime, World world);
}
public class FSM<T> {
Dictionary<string, IState<T>> states;
IState<T> state;
public FSM(Dictionary<string, IState<T>> states, string initial) {
this.states = states;
StateName = initial;
Transition(StateName);
}
public string StateName { get; private set; }
public void Update(T obj, float modelTime, World world) {
string newState = state.Update(obj, modelTime, world);
if (newState != null) {
Transition(newState);
}
}
void Transition(string state) {
StateName = state;
IState<T> newState = states[state];
this.state = newState;
this.state.Enter();
}
}
}