当前位置: 首页>>代码示例>>C#>>正文


C# StateMachine.CreatePseudoState方法代码示例

本文整理汇总了C#中StateMachine.CreatePseudoState方法的典型用法代码示例。如果您正苦于以下问题:C# StateMachine.CreatePseudoState方法的具体用法?C# StateMachine.CreatePseudoState怎么用?C# StateMachine.CreatePseudoState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在StateMachine的用法示例。


在下文中一共展示了StateMachine.CreatePseudoState方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Run

		public static void Run () {
			var model = new StateMachine<StateMachineInstance>("Model");
			var initial = model.CreatePseudoState("Initial", PseudoStateKind.Initial);
			var on = model.CreateState("On");
			var off = model.CreateState("Off");
			var clean = model.CreateState("Clean");
			var final = model.CreateFinalState("Final");

			var history = on.CreatePseudoState("History", PseudoStateKind.ShallowHistory);
			var idle = on.CreateState("Idle");
			var moveItem = on.CreateState("MoveItem");
			var showItemMovePattern = on.CreateState("ShowItemMovePattern");
			var hideItemMovePattern = on.CreateState("HideItemMovePattern");

			initial.To(idle);
			on.To(clean).When<string>(s => s == "DestroyInput");
			off.To(clean).When<string>(s => s == "DestroyInput");
			on.To(off).When<string>(s => s == "Disable");
			off.To(history).When<string>(s => s == "Enable");
			clean.To(final);
			idle.To(moveItem).When<string>(s => s == "TransformInput");
			moveItem.To(idle).When<string>(s => s == "ReleaseInput");
			idle.To(showItemMovePattern).When<string>(s => s == "ReleaseInput");
			showItemMovePattern.To(hideItemMovePattern).When<string>(s => s == "ReleaseInput");
			hideItemMovePattern.To(idle);

			model.Validate();

			var instance = new StateMachineInstance("instance");

			model.Initialise(instance);

			model.Evaluate(instance, "ReleaseInput");
			model.Evaluate(instance, "Disable");
			model.Evaluate(instance, "Enable");

			Trace.Assert(instance.GetCurrent(on.DefaultRegion) == showItemMovePattern, "History semantics should set current state to " + showItemMovePattern.Name);

			model.Evaluate(instance, "ReleaseInput");
			model.Evaluate(instance, "Disable");
			model.Evaluate(instance, "Enable");

			Trace.Assert(instance.GetCurrent(on.DefaultRegion) == idle, "History semantics should set current state to " + idle.Name);
		}
开发者ID:steelbreeze,项目名称:state.cs,代码行数:44,代码来源:Florent.cs

示例2: Main

		static void Main () {
			// create the state machine model
			var model = new StateMachine<Player>("model");

			// create the vertices within the model
			var initial = model.CreatePseudoState("initial", PseudoStateKind.Initial);
			var operational = model.CreateState("operational");
			var choice = model.CreatePseudoState("choice", PseudoStateKind.Choice);
			var flipped = model.CreateState("flipped");
			var final = model.CreateFinalState("final");

			var history = operational.CreatePseudoState("history", PseudoStateKind.DeepHistory);
			var stopped = operational.CreateState("stopped");
			var active = operational.CreateState("active").Entry(i => i.EngageHead()).Exit(i => i.DisengageHead());

			var running = active.CreateState("running").Entry(i => i.StartMotor()).Exit(i => i.StopMotor());
			var paused = active.CreateState("paused");

			// create the transitions between vertices of the model
			initial.To(operational).Effect(i => i.DisengageHead()).Effect(i => i.StopMotor());
			history.To(stopped);
			stopped.To(running).When<string>(command => command == "play");
			active.To(stopped).When<string>(command => command == "stop");
			running.To(paused).When<string>(command => command == "pause");
			running.To().When<string>(command => command == "tick").Effect((Player instance) => instance.Count++);
			paused.To(running).When<string>(command => command == "play");
			operational.To(final).When<string>(command => command == "off");
			operational.To(choice).When<string>(command => command == "rand");
			choice.To(operational).Effect(() => Console.WriteLine("- transition A back to operational"));
			choice.To(operational).Effect(() => Console.WriteLine("- transition B back to operational"));
			operational.To(flipped).When<string>(command => command == "flip");
			flipped.To(operational).When<string>(command => command == "flip");

			// validate the model for correctness
			model.Validate();

			// create a blocking collection make events from multiple sources thread-safe
			var queue = new System.Collections.Concurrent.BlockingCollection<Object>();

			// create an instance of the player - enqueue a tick message for the machine while its playing
			var player = new Player(() => queue.Add("tick"));

			// initialises the players initial state (enters the region for the first time, causing transition from the initial PseudoState)
			model.Initialise(player);

			// create a task to capture commands from the console in another thread
			System.Threading.Tasks.Task.Run(() => {
				string command = "";

				while (command.Trim().ToLower() != "exit") {
					queue.Add(command = Console.ReadLine());
				}

				queue.CompleteAdding();
			});

			// write the initial command prompt
			Console.Write("{0:0000}> ", player.Count);

			// process messages from the queue
			foreach (var message in queue.GetConsumingEnumerable()) {
				// process the message
				model.Evaluate(player, message);

				// manage the command prompt
				var left = Math.Max(Console.CursorLeft, 6);
				var top = Console.CursorTop;
				Console.SetCursorPosition(0, top);
				Console.Write("{0:0000}>", player.Count);
				Console.SetCursorPosition(left, top);
			}
		}
开发者ID:steelbreeze,项目名称:state.cs,代码行数:72,代码来源:Program.cs


注:本文中的StateMachine.CreatePseudoState方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。