Example #1
0
 public void Act(Action a, IDictionary <string, object> input)
 {
     if (_currentState != null)
     {
         if (_currentState.Allows(a))
         {
             Type t = a.GetActionType();
             if (input == null)
             {
                 input = t.GetInstance();
             }
             a.eval(input);
             a.Present();
             this.SetCurrentState(t.CurrentState());
             _currentState.IsCurrentState();
             this.Finalize(_currentState, t);
         }
         else
         {
             if (_warnOnErroneousAction)
             {
                 if (HasTrace())
                 {
                     _trace.AddTrace(new Property("ActionNotAllowedException()", "Behavior::act(" + a.GetId() + ")"));
                 }
                 System.Console.WriteLine("============= " + a.GetId() + " is not allowed =================");
             }
             else
             {
                 throw new Exception("ActionNotAllowedException() Behavior::act(" + a.GetId() + ")");
             }
         }
     }
 }
Example #2
0
 public Component Walk(int depth)
 {
     _walks = new Dictionary <Behavior, Walk <Type> >();
     foreach (Behavior b in _behaviors)
     {
         Action[] actions = b.GetCurrentState()?.GetActions().ToArray();
         if (actions?.Length > 0)
         {
             Action a = actions[0];
             if (a.GetActionType() != null)
             {
                 Walk <Type> walkThe = new Walk <Type>(a.GetActionType(), depth);
                 walkThe.StartWalking();
                 _walks.Add(b, walkThe);
             }
         }
     }
     return(this);
 }