新随笔  :: 联系 :: 订阅 订阅  :: 管理

有限状态自动机编译器(Finite State Machine Complier)

Posted on 2009-12-15 14:57  sakiwer  阅读(296)  评论(0)    收藏  举报

闲来无聊...

根据鲍勃大叔的思路...

做了这么一个东西...

有限状态自动机编译器...

知道状态机的都知道这玩意是干啥的...

自动生成状态机类和抽象类...

重写抽象类TrunstileActions即可...

public class AppAction : TrunstileActions
{
protected internal override void Unlock()
{
System.Console.WriteLine("Unlock called");
}
protected internal override void Alarm()
{
System.Console.WriteLine("Alarm called");
}
protected internal override void Tankyou()
{
System.Console.WriteLine("Tankyou called");
}
protected internal override void Lock()
{
System.Console.WriteLine("Lock called");
}
protected internal override void Locked_Entry()
{
System.Console.WriteLine("Locked_Entry called");
}
protected internal override void Locked_Exit()
{
System.Console.WriteLine("Locked_Exit called");
}
protected internal override void Unlocked_Entry()
{
System.Console.WriteLine("Unlocked_Entry called");
}
protected internal override void Unlocked_Exit()
{
System.Console.WriteLine("Unlocked_Exit called");
}
}

运行结果...

class Program
{
static void Main(string[] args)
{
AppClass t = new AppClass();
System.Console.WriteLine(t.GetCurrentState().ToString());
t.EnterStartState();
t.Coin();
t.Pass();
t.Coin();
t.Pass();
t.Coin();
t.Pass();
t.Coin();
t.Pass();
t.Coin();
t.Pass();
t.Coin();
t.Pass();
t.Coin();
t.Pass();
t.Coin();
t.Pass();
t.Coin();
t.Pass();
System.Console.ReadKey();
}
}

 


类别:.net 查看评论