Esempio n. 1
0
        /**
         * Load puzzle from file.
         * @see SudokuStore#loadBoard(String)
         */
        private void loadFromFile()
        {
            JanetConsole.print("File path: ");
            String   filePath = JanetConsole.readLine();
            FileInfo file     = new FileInfo(filePath);

            if (file.Exists == false)
            {
                JanetConsole.println(">>> !!! Error - file does not exist !!! <<<");
                return;
            }
            DirectoryInfo dir = new DirectoryInfo(filePath);

            if (dir.Exists == true)
            {
                JanetConsole.println(">>> !!! Error - not a file !!! <<<");
                return;
            }
            int[,] puzzleLoaded = SudokuStore.loadBoard(filePath);
            if (puzzleLoaded == null)
            {
                JanetConsole.println(">>> !!! Error - incorrect file content !!! <<<");
                return;
            }
            trackPuzzleUndo();
            puzzle = puzzleLoaded;
        }
Esempio n. 2
0
 /**
  * 13 rows keyboard input (4 supporting) - 0 or '.' as empty cell.
  * Any other character is being filtered out.
  *
  * @see SudokuStore#loadBoardFromStrings(String...)
  * @see SudokuStore#loadBoard(String[])
  */
 private void inputPuzzleFromKeyboard13rows()
 {
     JanetConsole.println("You will be asked for inputting 13 rows (4 supporting).");
     JanetConsole.print("Row  1/13: "); String r1  = JanetConsole.readLine();
     JanetConsole.print("Row  2/13: "); String r2  = JanetConsole.readLine();
     JanetConsole.print("Row  3/13: "); String r3  = JanetConsole.readLine();
     JanetConsole.print("Row  4/13: "); String r4  = JanetConsole.readLine();
     JanetConsole.print("Row  5/13: "); String r5  = JanetConsole.readLine();
     JanetConsole.print("Row  6/13: "); String r6  = JanetConsole.readLine();
     JanetConsole.print("Row  7/13: "); String r7  = JanetConsole.readLine();
     JanetConsole.print("Row  8/13: "); String r8  = JanetConsole.readLine();
     JanetConsole.print("Row  9/13: "); String r9  = JanetConsole.readLine();
     JanetConsole.print("Row 10/13: "); String r10 = JanetConsole.readLine();
     JanetConsole.print("Row 11/13: "); String r11 = JanetConsole.readLine();
     JanetConsole.print("Row 12/13: "); String r12 = JanetConsole.readLine();
     JanetConsole.print("Row 13/13: "); String r13 = JanetConsole.readLine();
     int[,] parsedPuzzle = SudokuStore.loadBoardFromStrings(r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13);
     if (parsedPuzzle != null)
     {
         trackPuzzleUndo();
         puzzle = parsedPuzzle;
     }
     else
     {
         JanetConsole.println(">>> !!! Error - incorrect puzzle definition !!! <<<");
     }
 }
Esempio n. 3
0
        /**
         * One line keyboard input (81 characters)
         * 0 or '.' as empty cell.
         *
         * @see SudokuStore#loadBoardFromStringLine(String)
         */
        private void inputPuzzleFromKeyboard1Line()
        {
            JanetConsole.print("One line definition: ");
            String line = JanetConsole.readLine();

            int[,] parsedPuzzle = SudokuStore.loadBoardFromStringLine(line);
            if (parsedPuzzle != null)
            {
                trackPuzzleUndo();
                puzzle = parsedPuzzle;
            }
            else
            {
                JanetConsole.println(">>> !!! Error - incorrect puzzle definition !!! <<<");
            }
        }
Esempio n. 4
0
        /**
         * Load puzzle from provided puzzle examples.
         * @see SudokuPuzzles
         * @see SudokuStore#getPuzzleExample(int)
         */
        private void loadFromExample()
        {
            JanetConsole.println();
            JanetConsole.print("Please provide example number (between 0 and " + (SudokuPuzzles.NUMBER_OF_PUZZLE_EXAMPLES - 1) + "): ");
            int example = JanetConsole.readInt();

            if ((example >= 0) && (example < SudokuPuzzles.NUMBER_OF_PUZZLE_EXAMPLES))
            {
                JanetConsole.println("Loading example: " + example);
                trackPuzzleUndo();
                puzzle = SudokuStore.boardCopy(SudokuStore.getPuzzleExample(example));
            }
            else
            {
                JanetConsole.println(">>> !!! Incorrect example number !!! <<<");
            }
        }
Esempio n. 5
0
        /*
         * ========================================
         *              Save Menu
         * ========================================
         */
        /**
         * Saves current puzzle in the txt file.
         *
         * @see SudokuStore#saveBoard(int[,], String)
         */
        private void savePuzzle()
        {
            JanetConsole.print("File path: ");
            String        filePath = JanetConsole.readLine();
            FileInfo      file     = new FileInfo(filePath);
            DirectoryInfo dir      = new DirectoryInfo(filePath);

            if ((file.Exists == true) || (dir.Exists == true))
            {
                JanetConsole.println(">>> !!! Error - file already exists !!! <<<");
                return;
            }
            bool puzzleSaved = SudokuStore.saveBoard(puzzle, filePath);

            if (puzzleSaved == false)
            {
                JanetConsole.println(">>> !!! Error while saving !!! <<<");
            }
        }
Esempio n. 6
0
        /**
         * Ask user for menu item selection.
         * @return  Select item id {@link MenuData}.
         *
         * @see MenuData
         */
        internal int getItem()
        {
            int  selItem = 0;
            bool loop    = true;

            do
            {
                consolePrintMenue();
                JanetConsole.println();
                JanetConsole.print("Your selection: ");
                selItem = JanetConsole.readInt();
                if ((selItem >= 0) && (selItem <= itemsNum))
                {
                    loop = false;
                }
                else
                {
                    JanetConsole.println(">>> !!! Please select correct menu item. !!! <<<");
                }
            } while (loop == true);
            return(selItem);
        }
Esempio n. 7
0
 /**
  * Manually sets cell value.
  */
 private void setCell()
 {
     JanetConsole.print("   Row number (between 1 and 9): "); int row = JanetConsole.readInt();
     if ((row < 1) || (row > 9))
     {
         JanetConsole.println(">>> !!! Error - incorrect row number !!! <<<");
         return;
     }
     JanetConsole.print("Column number (between 1 and 9): "); int col = JanetConsole.readInt();
     if ((col < 1) || (col > 9))
     {
         JanetConsole.println(">>> !!! Error - incorrect column number !!! <<<");
         return;
     }
     JanetConsole.print("        Digit (between 0 and 9): "); int digit = JanetConsole.readInt();
     if ((digit < 0) || (digit > 9))
     {
         JanetConsole.println(">>> !!! Error - incorrect digit !!! <<<");
         return;
     }
     trackPuzzleUndo();
     puzzle[row - 1, col - 1] = digit;
 }
Esempio n. 8
0
 /**
  * 9 rows keyboard input - 0 or '.' as empty cell.
  * Any other character is being filtered out.
  *
  * @see SudokuStore#loadBoardFromStrings(String...)
  * @see SudokuStore#loadBoard(String[])
  */
 private void inputPuzzleFromKeyboard9rows()
 {
     JanetConsole.println("You will be asked for inputting 9 rows.");
     JanetConsole.print("Row 1/9: "); String r1 = JanetConsole.readLine();
     JanetConsole.print("Row 2/9: "); String r2 = JanetConsole.readLine();
     JanetConsole.print("Row 3/9: "); String r3 = JanetConsole.readLine();
     JanetConsole.print("Row 4/9: "); String r4 = JanetConsole.readLine();
     JanetConsole.print("Row 5/9: "); String r5 = JanetConsole.readLine();
     JanetConsole.print("Row 6/9: "); String r6 = JanetConsole.readLine();
     JanetConsole.print("Row 7/9: "); String r7 = JanetConsole.readLine();
     JanetConsole.print("Row 8/9: "); String r8 = JanetConsole.readLine();
     JanetConsole.print("Row 9/9: "); String r9 = JanetConsole.readLine();
     int[,] parsedPuzzle = SudokuStore.loadBoardFromStrings(r1, r2, r3, r4, r5, r6, r7, r8, r9);
     if (parsedPuzzle != null)
     {
         trackPuzzleUndo();
         puzzle = parsedPuzzle;
     }
     else
     {
         JanetConsole.println(">>> !!! Error - incorrect puzzle definition !!! <<<");
     }
 }
Esempio n. 9
0
 /**
  * Print current puzzle to the console
  */
 internal void consolePrintPuzzle()
 {
     JanetConsole.println();
     JanetConsole.print(">>> Random seed option - empty cells = " + rndSeedOnCells + ", free digits = " + rndSeedOnDigits);
     SudokuStore.consolePrintBoard(puzzle);
 }