Esempio n. 1
0
        private bool ParseValue(string input, TekBoard board)
        {
            int   row, col, value;
            Match match = valuePattern.Match(input);

            if (match.Success &&
                Int32.TryParse(match.Groups["row"].Value, out row) &&
                Int32.TryParse(match.Groups["col"].Value, out col) &&
                Int32.TryParse(match.Groups["value"].Value, out value)
                )
            {
                if (!board.IsInRange(row, col) || value <= 0 || value > Const.MAXTEK)
                {
                    ParseError("Invalid value line {0}: ({1},{2}", input, row, col);
                }
                TekField field = board.Fields[row, col];
                field.Value   = value;
                field.Initial = match.Groups["initial"].Value == "i";
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 2
0
        private bool ParseAreaField(string rowS, string colS, TekBoard board, List <TekField> fields)
        {
            int row, col;

            if (Int32.TryParse(rowS, out row) && Int32.TryParse(colS, out col))
            {
                if (board.IsInRange(row, col))
                {
                    fields.Add(board.Fields[row, col]);
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 3
0
        private bool ParseMultiValues(string input, TekBoard board, MultiValues mvType)
        {
            int      row, col, value;
            TekField field = null;
            Regex    pattern1 = null, pattern2 = null;


            switch (mvType)
            {
            case MultiValues.mvNotes:
                pattern1 = notesPattern1;
                pattern2 = notesPattern2;
                break;

            case MultiValues.mvExcludes:
                pattern1 = excludesPattern1;
                pattern2 = excludesPattern2;
                break;
            }

            Match match = pattern1.Match(input);

            if (match.Success)
            {
                if (field == null && Int32.TryParse(match.Groups["row"].Value, out row) &&
                    Int32.TryParse(match.Groups["col"].Value, out col))
                {
                    if (!board.IsInRange(row, col))
                    {
                        ParseError("Invalid field in {0} line {1}: ({2},{3})", MultiValueString[(int)mvType], input, row, col);
                    }
                    field = board.Fields[row, col];
                }
                if (field != null && Int32.TryParse(match.Groups["value"].Value, out value))
                {
                    switch (mvType)
                    {
                    case MultiValues.mvNotes:
                        field.ToggleNote(value);
                        break;

                    case MultiValues.mvExcludes:
                        field.ExcludeValue(value);
                        break;
                    }
                    match = pattern2.Match(match.Groups["rest"].Value);
                    while (match.Success)
                    {
                        if (Int32.TryParse(match.Groups["value"].Value, out value))
                        {
                            switch (mvType)
                            {
                            case MultiValues.mvNotes:
                                field.ToggleNote(value);
                                break;

                            case MultiValues.mvExcludes:
                                field.ExcludeValue(value);
                                break;
                            }
                            match = match.NextMatch();
                        }
                        else
                        {
                            ParseError("Invalid value in {0} line {1}: ({2})", MultiValueString[(int)mvType], input, match.Groups["value"].Value);
                        }
                    }
                }
            }
            return(field != null);
        }