示例#1
0
        public static ICrossBoard CreateFromStream(Stream s)
        {
            var r     = new StreamReader(s, Encoding.UTF8);
            var lines = new List <string>();

            while (true)
            {
                var line = r.ReadLine();
                if (string.IsNullOrEmpty(line))
                {
                    break;
                }
                lines.Add(line);
            }
            int lineLength = -1;

            for (int i = 0; i < lines.Count; i++)
            {
                if (lineLength == -1)
                {
                    lineLength = lines[i].Length;
                }
                else if (lines[i].Length != lineLength)
                {
                    throw new Exception(string.Format("Line {0} has different length ({1}) then previous lines ({2})",
                                                      i, lines[i], lineLength));
                }
            }
            var board = new CrossBoard();

            board.SetBoardSize(lineLength, lines.Count);
            for (int row = 0; row < lines.Count; row++)
            {
                var line = lines[row];
                for (int col = 0; col < lineLength; col++)
                {
                    if (line[col] == '-')
                    {
                        board.AddStartWord(col, row);
                    }
                }
            }

            return(board);
        }
示例#2
0
        public ICrossBoard Clone()
        {
            var result = new CrossBoard();

            result.SetBoardSize(_sizeX, _sizeY);
            result._startWords.AddRange(_startWords);
            if (_horizontalPatterns != null && _verticalPatterns != null)
            {
                result._horizontalPatterns = new List <CrossPattern>();
                foreach (var patt in _horizontalPatterns)
                {
                    result._horizontalPatterns.Add((CrossPattern)patt.Clone());
                }
                result._verticalPatterns = new List <CrossPattern>();
                foreach (var patt in _verticalPatterns)
                {
                    result._verticalPatterns.Add((CrossPattern)patt.Clone());
                }
                result.BindAdjacentPatterns();
            }
            return(result);
        }