private bool CheckForAnything(Memory memory, Face face, string line1, string line2, int timeoutMS, out Interaction i)
 {
     i = face.RememberSingleValue(memory, line1, line2, false, timeoutMS);
     if (i.playerAnswer != Interaction.Answer.DidNotAnswer)
         return true;
     else
         return false;
 }
Beispiel #2
0
 public Interaction SlowTalk(Memory memory, string line1, string line2 = "", int msTypingDelay = 200, int millisecondTimeout = 5000)
 {
     Interaction result = new Interaction() { player = memory.GetCurrentPlayer() };
     _renderer.Clear();
     _renderer.SlowType(line1, line2, msTypingDelay);
     result.displayText = (line1 + " " + line2).Trim();
     Thread.Sleep(millisecondTimeout);
     return result;
 }
        void consoleListener_InteractionHandled(object sender, InteractionEventArgs e)
        {
            lock (_interaction)

            {
                _interaction = e.interaction;
                _interactionHappened = true;
                getInput.Set();
            }
        }
Beispiel #4
0
 protected virtual RoutineResult MakeRoutineResult(Memory memory, RoutineFinalState finalState, Interaction finalInteraction)
 {
     RoutineResult result = new RoutineResult()
     {
         FinalState = finalState,
         FinalInteraction = finalInteraction,
         RoutineType = this.GetType().ToString()
     };
     memory.AddToMemory(result);
     return result;
 }
 public int GetInteger(int millisecondTimeout)
 {
     using (var consoleListener = new ConsoleListener())
     {
         _interaction = new Interaction();
         consoleListener.InteractionHandled += consoleListener_InteractionHandled;
         consoleListener.Start();
         getInput.WaitOne(millisecondTimeout);
         return _interaction.resultValue;
     }
 }
Beispiel #6
0
        public void AddToMemory(Interaction interaction, bool longTerm = false)
        {
            interaction.timestamp = DateTime.Now;
            _shortTerm.Add(interaction);
            if (longTerm)
            {
                DBContext.Interactions.Add(interaction);
            }

            _textMemory[MakeMemoryKey(interaction)] = interaction;
        }
 public bool TryGetInteger(out int value, int millisecondTimeout)
 {
     using (var consoleListener = new ConsoleListener())
     {
         _interactionHappened = false;
         _interaction = new Interaction();
         consoleListener.InteractionHandled += consoleListener_InteractionHandled;
         consoleListener.Start();
         getInput.WaitOne(millisecondTimeout);
         value = _interaction.resultValue;
         return _interactionHappened;
     }
 }
Beispiel #8
0
        public Interaction GetSingleValue(Memory memory, string line1, string line2 = "", int millisecondTimeout = 5000)
        {
            Interaction result = new Interaction() { player = memory.GetCurrentPlayer() };
            _renderer.Clear();
            _renderer.Write(line1, line2);
            result.displayText = (line1 + " " + line2).Trim();
            int intResult;
            if (_input.TryGetInteger(out intResult, millisecondTimeout))
            {
                result.resultValue = intResult;
            }

            return result;
        }
Beispiel #9
0
 protected virtual RoutineResult MakeRoutineResult(Memory memory, Interaction finalInteraction)
 {
     RoutineResult result = new RoutineResult()
     {
         FinalState = RoutineFinalState.Abandoned,
         FinalInteraction = finalInteraction,
         RoutineType = this.GetType().ToString()
     };
     if (finalInteraction.playerAnswer != Interaction.Answer.DidNotAnswer)
     {
         result.FinalState = finalInteraction.success ? RoutineFinalState.Success : RoutineFinalState.Failure;
     }
     memory.AddToMemory(result);
     return result;
 }
Beispiel #10
0
        protected override RoutineResult RunConsciousRoutine()
        {
            using (var memory = new Memory())
            {
                var nouns = new List<string>() { "Sheep", "Trees", "Birds", "Cars", "Pillows", "Leaves", "PB&J", "Books", "Cookie", "Monsters", "Whaaa?!" };

                var face = new Face(RendererFactory.GetPreferredRenderer(), InputFactory.GetPreferredInput());
                Interaction i = new Interaction();
                foreach (string noun in nouns)
                {
                    if (CheckForAnything(memory, face, noun, "", out i)) return MakeRoutineResult(memory, i);
                }
                return MakeRoutineResult(memory, i);
            }
        }
 public MenuItem ChooseFromMenu(Menu menu, int millisecondTimeout)
 {
     using (var consoleListener = new ConsoleListener())
     {
         _interactionHappened = false;
         _interaction = new Interaction();
         consoleListener.InteractionHandled += consoleListener_InteractionHandled;
         consoleListener.Start();
         Console.Write("Enter choice: ");
         getInput.WaitOne(millisecondTimeout);
         if (menu.ValidChoice(_interaction.resultValue))
             return menu.GetMenuItem(_interaction.resultValue);
         else
             return null;
     }
 }
Beispiel #12
0
        public Interaction RememberSingleValue(Memory memory, string line1, string line2 = "", bool longTerm = false, int millisecondTimeout = 5000)
        {
            Interaction result = new Interaction() { player = memory.GetCurrentPlayer() };
            _renderer.Clear();
            _renderer.Write(line1, line2);
            result.displayText = (line1 + " " + line2).Trim();
            int intResult;
            if (_input.TryGetInteger(out intResult, millisecondTimeout))
            {
                result.resultValue = intResult;
            }

            if(result.resultValue != -1)
                memory.AddToMemory(result, longTerm);

            return result;
        }
Beispiel #13
0
 public Interaction TalkInCircles(Memory memory, int millisecondTimeout = 5000, params string[] textLines)
 {
     if (null == _incrementer) _incrementer = new IndexIncrement(textLines.Length, true);
     string text = textLines[_incrementer.Next];
     Interaction result = new Interaction() { player = memory.GetCurrentPlayer() };
     _renderer.Clear();
     _renderer.Write(text, "");
     result.displayText = text;
     Thread.Sleep(millisecondTimeout);
     return result; ;
 }
Beispiel #14
0
 private static MemoryKey MakeMemoryKey(Interaction i)
 {
     return new MemoryKey() { player = i.player, line1 = i.displayText };
 }
Beispiel #15
0
        public Interaction Talk(Memory memory, string line1, string line2 = "", int millisecondTimeout = 5000)
        {
            Interaction result = new Interaction() { player = memory.GetCurrentPlayer() };
            _renderer.Clear();
            _renderer.Write(line1, line2);
            result.displayText = (line1 + " " + line2).Trim();

            int oneFifth = millisecondTimeout / 5;
            for (int i = 0; i <= 5; i++)
            {
                _renderer.WriteProgressIndicator(5, 0, i);
                Thread.Sleep(oneFifth);
            }
            return result;
        }
Beispiel #16
0
 public Interaction Fade(Memory memory, char c, int millisecondsBetweenSteps = 0)
 {
     Interaction result = new Interaction() { player = memory.GetCurrentPlayer() };
     _renderer.Fade(c, millisecondsBetweenSteps);
     return result;
 }
 public InteractionEventArgs(Interaction pinteraction)
 {
     interaction = pinteraction;
 }
Beispiel #18
0
        public Interaction YesNo(Memory memory, string line1, bool longTerm = false, int millisecondTimeout = 10000)
        {
            Menu menu = new MenuYesNo(line1);
            Interaction result = new Interaction() { player = memory.GetCurrentPlayer() };
            _renderer.Clear();
            _renderer.DisplayMenu(menu);
            result.displayText = line1;
            MenuItem item = _input.ChooseFromMenu(menu, millisecondTimeout);
            if(null != item) result.resultValue = item.choiceNumber;

            if (result.resultValue != -1)
                memory.AddToMemory(result, longTerm);

            return result;
        }
 public InteractionEventArgs(int result)
 {
     interaction = new Interaction(result);
 }