-
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathProgram.cs
More file actions
60 lines (49 loc) · 1.79 KB
/
Program.cs
File metadata and controls
60 lines (49 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using SimpleStateMachineLibrary;
using System;
using System.Collections.Generic;
namespace Examples
{
class Program
{
static void Action1(State state, Dictionary<string, object> parameters)
{
state.StateMachine.InvokeTransition("Transition1");
}
static void Action2(State state, Dictionary<string, object> parameters)
{
state.StateMachine.InvokeTransition("Transition2");
}
static void Action3(State state, Dictionary<string, object> parameters)
{
state.StateMachine.InvokeTransition("Transition3");
}
static void Action4(State state, Dictionary<string, object> parameters)
{
}
static void Main(string[] args)
{
StateMachine stateMachine = new StateMachine();
//Add states
State state1 = stateMachine.AddState("State1");
State state2 = stateMachine.AddState("State2");
State state3 = stateMachine.AddState("State3");
State state4 = stateMachine.AddState("State4");
//Add transitions three ways:
//Standart way
Transition transition1 = stateMachine.AddTransition("Transition1", state1, state2);
//From state
Transition transition2 = state2.AddTransitionFromThis("Transition2", state3);
//To state
Transition transition3 = state4.AddTransitionToThis("Transition3", state3);
//Add action on entry or/and exit
state1.OnExit(Action1);
state2.OnEntry(Action2);
state3.OnExit(Action3);
state4.OnExit(Action4);
//Set start state
state1.SetAsStartState();
//Start work
stateMachine.Start();
}
}
}