Skip to content

Instantly share code, notes, and snippets.

@eastmad
Last active August 29, 2022 12:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eastmad/60601442500c07aab19d20762319f387 to your computer and use it in GitHub Desktop.
Save eastmad/60601442500c07aab19d20762319f387 to your computer and use it in GitHub Desktop.
Simple State Machine for a cycle
namespace TheNewStack
{
public enum SeasonalState { Spring, Summer, Autumn, Winter }
public class SimpleStateMachine
{
public Season CurrentSeason;
public SimpleStateMachine()
{
CurrentSeason = new Season(SeasonalState.Spring);
Season season = CurrentSeason.NextSeason = new Season(SeasonalState.Summer);
season = season.NextSeason = new Season(SeasonalState.Autumn);
season = season.NextSeason = new Season(SeasonalState.Winter);
season.NextSeason = CurrentSeason;
}
public Season Next()
{
return CurrentSeason = CurrentSeason.NextSeason;
}
public class Season
{
readonly SeasonalState seasonstate;
public Season NextSeason;
public Season(SeasonalState seasonstate)
{
this.seasonstate = seasonstate;
}
public void Welcome()
{
Console.WriteLine("This is " + seasonstate);
}
}
}
}
public class Program
{
static void Main(String[] args)
{
SimpleStateMachine s = new SimpleStateMachine();
for (int i = 0; i < 6; i++)
{
s.CurrentSeason.Welcome();
s.Next();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment