Exemplo n.º 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(
                              $"Line {i} has different length ({lines[i]}) then previous lines ({lineLength})");
                }
            }

            ICrossBoard board = new CrossBoard(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);
        }
Exemplo n.º 2
0
        public ICrossBoard Clone()
        {
            var result = new CrossBoard(_sizeX, _sizeY);

            result._startWords.AddRange(_startWords);
            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);
        }
Exemplo n.º 3
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 horPattern in _horizontalPatterns)
                {
                    result._horizontalPatterns.Add((CrossPattern)horPattern.Clone());
                }

                result._verticalPatterns = new List <CrossPattern>();
                foreach (var verPattern in _verticalPatterns)
                {
                    result._verticalPatterns.Add((CrossPattern)verPattern.Clone());
                }
                result.BindAdjacentPatterns();
            }
            return(result);
        }