Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace StateApp
{
static class Program
{
public static Form1 form1 = new Form1();
public static IState[] states = {new IntroState()};
public static IState curState;
public static KeyEventHandler activeKeyHandler;
public static MouseEventHandler activeMouseHandler;
public static int count = 0;
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
curState = states[0];
Application.EnableVisualStyles();
Application.Run(form1);
}
}
}
IntroState.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace StateApp
{
public class IntroState : IState
{
public IntroState()
{
this.Name = "IntroState";
Program.count = 0;
}
public void Update()
{
Program.count++;
Program.form1.BackColor = System.Drawing.Color.Azure;
}
public void Cleanup()
{
Program.count = 0;
}
public void Pause()
{
}
public void Resume()
{
}
public string Name { get; set; }
}
}
IState.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace StateApp
{
/// <summary>
/// A State Object Abstract from drawing and eventhandling
/// by working only with data and external application settings
/// </summary>
public interface IState
{
void Update();
void Cleanup();
void Pause();
void Resume();
string Name { get; set; }
}
}
the idea of the design is that using the Program class each state can select eventhandlers, methods etc and just work on the data aspect of the program selecting the eventhandlers to use, which also change data based upon events such as input.