示例#1
0
        /// <summary>
        /// Parses the file contents into an object of type SBoard.
        /// </summary>
        /// <param name="fileName">Name and path of the file to be parsed.</param>
        /// <returns>A board object containing the puzzle data.</returns>
        public static SBoard parseFile(string fileName)
        {
            string input = File.ReadAllText(fileName);
            SBoard board = new SBoard();

            int currentCharIndex = 0;

            for (int row = 0; row < SBoard.ROW_SIZE; row++)
            {
                for (int col = 0; col < SBoard.COL_SIZE; col++)
                {
                    int value = -1;
                    while (value == -1)
                    {
                        if (input[currentCharIndex] >= ZERO && input[currentCharIndex] <= NINE)
                        {
                            int.TryParse(input[currentCharIndex].ToString(), out value);
                        }
                        else if (input[currentCharIndex] == DOT)
                        {
                            value = 0;
                        }
                        currentCharIndex++;
                    }
                    board.setCell(value, row, col);
                }
            }

            return(board);
        }
示例#2
0
        /// <summary>
        /// Returns the up-to-date version of the game board.
        /// </summary>
        /// <returns>The up-to-date version of the game board.</returns>
        public SBoard getUpdatedBoard()
        {
            SBoard updatedBoard = new SBoard();

            for (int row = 0; row < SBoard.ROW_SIZE; row++)
            {
                for (int col = 0; col < SBoard.COL_SIZE; col++)
                {
                    updatedBoard.setCell(boardControl[row, col].getValue(), row, col);
                }
            }

            return(updatedBoard);
        }