Пример #1
0
 public InputSequenceMatcher(InputSequence sequence)
 {
     this.sequence = sequence.Inputs.GetEnumerator();
     // Start by advancing the enumerator, makes match() logic simpler
     if (this.sequence.MoveNext() == false)
     {
         // Indicates empty InputSequence
         complete = true;
     }
 }
Пример #2
0
        public bool Match(InputSequence sequence)
        {
            var now = DateTime.Now;

            if (now > lastAttackTime.AddSeconds(secondsBetweenAttacks))
            {
                lastAttackTime = now;
                return(true);
            }
            return(false);
        }
Пример #3
0
        public bool Match(InputSequence sequence)
        {
            // TODO: Thread safety concerns?
            int index = find(sequence);

            if (index != -1)
            {
                var newLen = buffer.Count - (index + 1);
                trimBuffer(newLen);
            }
            return(index != -1);
        }
Пример #4
0
        /// <summary>
        /// Finds the index of the first (i.e oldest) InputState matching
        /// the provided sequence, or -1 if not found.
        /// </summary>
        private int find(InputSequence sequence)
        {
            var matcher = new InputSequenceMatcher(sequence);

            foreach ((InputState state, int index) in buffer.Select((x, i) => (x, i)))
            {
                if (matcher.isMatch(state))
                {
                    if (matcher.isComplete())
                    {
                        return(index);
                    }
                }
                else
                {
                    matcher = new InputSequenceMatcher(sequence);
                }
            }
            return(-1);
        }
Пример #5
0
 public bool Peek(InputSequence sequence)
 {
     return(false);
 }
Пример #6
0
 public bool Peek(InputSequence sequence)
 {
     return(find(sequence) != -1);
 }
Пример #7
0
 public bool Peek(InputSequence sequence)
 {
     return(buffer.Peek(sequence));
 }
Пример #8
0
 public bool Match(InputSequence sequence)
 {
     return(buffer.Match(sequence));
 }