Minesweeper.Board.ToLines C# (CSharp) Method

ToLines() public method

public ToLines ( ) : IList
return IList
        public IList<string> ToLines()
        {
            IList<string> lines = new List<string>();

            for (var nrow = 0; nrow < this.nrows; nrow++)
                lines.Add(this.ToLine(nrow));

            return lines;
        }

Usage Example

Example #1
0
        private object Generate(int nrows, int ncols, int height, int width, int rest)
        {
            Board board = new Board(nrows, ncols);
            board.SetEmpty(height, width);
            board.SetClick(0, 0);

            int y = 0;
            int x = width;

            while (rest >= 2 && y + 1 < height && x < ncols)
            {
                board.SetEmptyCell(y, x);
                board.SetEmptyCell(y + 1, x);
                rest -= 2;
                x++;

                if (x >= ncols)
                {
                    y += 2;
                    x = width;

                    if (y >= height)
                        break;
                }
            }

            if (rest > 0 && y == 0)
            {
                y = 2;
                x = width;
            }

            while (rest > 0 && y < height && x < ncols)
            {
                board.SetEmptyCell(y, x++);
                rest--;

                if (x >= ncols)
                {
                    y++;
                    x = width;
                }
            }

            return board.ToLines();
        }