Пример #1
0
        // pro správný vstup vrací pole se souřadnicemi x a y na prvním
        // a druhém prvku pole, pro špatný vstup vrací null
        private static int[] IsInput(string s)
        {
            if (s.Length == 2)
            {
                char first  = s.ToCharArray() [0];
                char second = s.ToCharArray() [1];

                if (first >= 'a' && first < 'a' + g.GetWidth() &&
                    second >= '1' && second <= '9')
                {
                    return(new int[2] {
                        first - 'a', second - '1'
                    });
                }
                else if (second >= 'a' && second < 'a' + g.GetWidth() &&
                         first >= '1' && first <= '9')
                {
                    return(new int[2] {
                        second - 'a', first - '1'
                    });
                }
            }
            else if (s.Length == 3)
            {
                char first  = s.ToCharArray() [0];
                char second = s.ToCharArray() [1];
                char third  = s.ToCharArray() [2];

                if (first >= 'a' && first < 'a' + g.GetWidth())
                {
                    if ((second >= '0' && second <= '0' + g.GetHeight() / 10) &&
                        (third >= '0' && third <= '9'))
                    {
                        int y = (second - '0') * 10 + (third - '1');
                        if (y > g.GetHeight())
                        {
                            return(null);
                        }
                        return(new int[2] {
                            first - 'a', y
                        });
                    }
                }
                else if (third >= 'a' && third < 'a' + g.GetWidth())
                {
                    if ((first >= '0' && first <= '0' + g.GetHeight() / 10) &&
                        (second >= '0' && second <= '9'))
                    {
                        int y = (first - '0') * 10 + (second - '1');
                        if (y > g.GetHeight())
                        {
                            return(null);
                        }
                        return(new int[2] {
                            third - 'a', y
                        });
                    }
                }
            }
            return(null);
        }