private IEnumerator SolveCoroutine(string word)
    {
        char[] characters = word.ToCharArray();
        for (int characterIndex = 0; characterIndex < characters.Length; ++characterIndex)
        {
            if (Canceller.ShouldCancel)
            {
                Canceller.ResetCancel();
                yield break;
            }

            CharSpinner spinner      = _spinners[characterIndex];
            IEnumerator subcoroutine = GetCharacterSpinnerToCharacterCoroutine(spinner, characters[characterIndex]);
            while (subcoroutine.MoveNext())
            {
                yield return(subcoroutine.Current);
            }

            //Break out of the sequence if a column spinner doesn't have a matching character
            if (char.ToLowerInvariant(spinner.GetCurrentChar()) != char.ToLowerInvariant(characters[characterIndex]))
            {
                yield return("unsubmittablepenalty");

                yield break;
            }
        }

        yield return(DoInteractionClick(_submitButton));
    }
    private IEnumerator GetCharacterSpinnerToCharacterCoroutine(CharSpinner spinner, char desiredCharacter)
    {
        MonoBehaviour downButton = spinner.DownButton;

        for (int hitCount = 0; hitCount < 6 && char.ToLowerInvariant(spinner.GetCurrentChar()) != char.ToLowerInvariant(desiredCharacter); ++hitCount)
        {
            yield return(DoInteractionClick(downButton));
        }
    }
Ejemplo n.º 3
0
    private IEnumerator GetCharacterSpinnerToCharacterCoroutine(CharSpinner spinner, char desiredCharacter)
    {
        var options     = spinner.Options;
        var targetIndex = options.IndexOf(char.ToUpperInvariant(desiredCharacter));

        if (targetIndex == -1)
        {
            yield break;
        }

        yield return(SelectIndex(options.IndexOf(spinner.GetCurrentChar()), targetIndex, options.Count, spinner.DownButton, spinner.UpButton));
    }
Ejemplo n.º 4
0
    protected internal override IEnumerator RespondToCommandInternal(string inputCommand)
    {
        Match m;

        if (Regex.IsMatch(inputCommand, @"^\s*toggle\s*$", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase))
        {
            yield return("password");

            for (int i = 0; i < 5; i++)
            {
                yield return(DoInteractionClick(_spinners[i].DownButton));
            }
        }
        else if (Regex.IsMatch(inputCommand, @"^\s*cycle\s*$", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase))
        {
            yield return("password");

            for (int i = 0; i < 5; i++)
            {
                IEnumerator spinnerCoroutine = CycleCharacterSpinnerCoroutine(_spinners[i]);
                while (spinnerCoroutine.MoveNext())
                {
                    yield return(spinnerCoroutine.Current);
                }
            }
        }
        else if ((m = Regex.Match(inputCommand, @"^\s*cycle\s+([ \d]+)\s*$", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase)).Success)
        {
            var slots = new HashSet <int>();
            foreach (var piece in m.Groups[1].Value.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries))
            {
                if (!int.TryParse(piece, out var i) || i < 1 || i > 5)
                {
                    yield return(string.Format("sendtochaterror “{0}” is not a number from 1 to 5.", piece));

                    yield break;
                }
                slots.Add(i);
            }
            if (slots.Count > 0)
            {
                yield return("password");

                foreach (var slot in slots)
                {
                    IEnumerator spinnerCoroutine = CycleCharacterSpinnerCoroutine(_spinners[slot - 1]);
                    while (spinnerCoroutine.MoveNext())
                    {
                        yield return(spinnerCoroutine.Current);
                    }
                }
            }
        }
        else if ((m = Regex.Match(inputCommand, @"^\s*(\S{5})\s*$", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase)).Success)
        {
            yield return("password");

            char[] characters = m.Groups[1].Value.ToLowerInvariant().ToCharArray();
            for (int ix = 0; ix < characters.Length; ++ix)
            {
                CharSpinner spinner      = _spinners[ix];
                IEnumerator subcoroutine = GetCharacterSpinnerToCharacterCoroutine(spinner, characters[ix]);
                while (subcoroutine.MoveNext())
                {
                    yield return(subcoroutine.Current);
                }

                //Break out of the sequence if a column spinner doesn't have a matching character
                if (char.ToLowerInvariant(spinner.GetCurrentChar()) ==
                    char.ToLowerInvariant(characters[ix]))
                {
                    continue;
                }
                yield return("unsubmittablepenalty");

                yield break;
            }

            yield return(DoInteractionClick(_submitButton));
        }
    }