Click here to Skip to main content
15,888,803 members
Articles / Programming Languages / C#

Finite State Machine with Sub-state

Rate me:
Please Sign up or sign in to vote.
1.67/5 (2 votes)
4 Oct 2008CPOL3 min read 41.2K   737   34  
Implementing Finite State Machine with Sub-state
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace DemoStateModel
{
    public partial class FormMain : Form
    {
        public FormMain()
        {
            InitializeComponent();
        }

        DemoStateMgmt stateMgmt = new DemoStateMgmt();

        private void FormMain_Load(object sender, EventArgs e)
        {
            radInitA.Checked = true;
            txtCurrentState.Text = stateMgmt.GetCurrentState().GetStateName();
        }

        private void radInitA_CheckedChanged(object sender, EventArgs e)
        {
            Configuration.DefaultInit = Configuration.InitA;
        }

        private void radInitB_CheckedChanged(object sender, EventArgs e)
        {
            Configuration.DefaultInit = Configuration.InitB;
        }

        private void btnStart_Click(object sender, EventArgs e)
        {
            stateMgmt.HandleTrigger(DemoStateMgmt.Trigger_Start);
            txtCurrentState.Text = stateMgmt.GetCurrentState().GetStateName();
        }

        private void btnStop_Click(object sender, EventArgs e)
        {
            stateMgmt.HandleTrigger(DemoStateMgmt.Trigger_Stop);
            txtCurrentState.Text = stateMgmt.GetCurrentState().GetStateName();
        }

        private void btnPause_Click(object sender, EventArgs e)
        {
            stateMgmt.HandleTrigger(DemoStateMgmt.Trigger_Pause);
            txtCurrentState.Text = stateMgmt.GetCurrentState().GetStateName();
        }

        private void btnResume_Click(object sender, EventArgs e)
        {
            stateMgmt.HandleTrigger(DemoStateMgmt.Trigger_Resume);
            txtCurrentState.Text = stateMgmt.GetCurrentState().GetStateName();
        }

        private void btnLoadA_Click(object sender, EventArgs e)
        {
            stateMgmt.HandleTrigger(DemoStateMgmt.Trigger_LoadA);
            txtCurrentState.Text = stateMgmt.GetCurrentState().GetStateName();
        }

        private void btnLoadB_Click(object sender, EventArgs e)
        {
            stateMgmt.HandleTrigger(DemoStateMgmt.Trigger_LoadB);
            txtCurrentState.Text = stateMgmt.GetCurrentState().GetStateName();
        }

        private void btnRun_Click(object sender, EventArgs e)
        {
            stateMgmt.HandleTrigger(DemoStateMgmt.Trigger_Run);
            txtCurrentState.Text = stateMgmt.GetCurrentState().GetStateName();
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Vietnam Vietnam
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions