Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class SudokuDriver{
- public static void main(String[] args)
- {
- Scanner i=new Scanner(System.in);
- int row=-1,col=-1,val=-1,x=0;
- SudokuPuzzle puzzle1 = new SudokuPuzzle();
- SudokuPuzzle.initializeBoard(puzzle1);
- System.out.println("Welcome to Sudoku. Please choose");
- SudokuPuzzle.addInitial(puzzle1, 2, 3 , 8);
- SudokuPuzzle.addInitial(puzzle1, 3, 1 , 3);
- SudokuPuzzle.addInitial(puzzle1, 7, 7 , 6);
- SudokuPuzzle.addInitial(puzzle1, 4, 6 , 3);
- SudokuPuzzle.addInitial(puzzle1, 9, 2 , 9);
- System.out.println(SudokuPuzzle.toString(puzzle1));
- System.out.println();
- do
- {
- System.out.println("What would you like to do? \n1.Continue the puzzle \n2.See avaliable values in a square \n3.Reset everything \n4.Exit the program");
- x= Userinput;
- switch(UserInput)
- {
- case 1 :
- while (Input Validation While Loop: Column between 1-9)
- {
- Ask What row?;
- row=i.nextInt();
- if( Input Validation for Row)
- "Sorry, that is an invalid input, please try again.";
- }
- while (Input Validation While Loop: Row between 1-9)
- {
- Ask What Row;
- col=i.nextInt();
- if( Input Validation for Column)
- "Sorry, that is an invalid input, please try again.";
- }
- while (Input Validation While Loop: Value between 1-9)
- {
- Ask for value;
- val=i.nextInt();
- if( val < 0 && val >9)
- "Sorry, that is an invalid input, please try again.";
- }
- ;
- AddGuess method;
- row=-1;
- col=-1;
- val=-1;
- break;
- // end choice 1
- case 2 :
- while (row < 0 || row > 9)
- {
- System.out.println("What row?");
- row=i.nextInt();
- if( row < 0 && row > 9)
- System.out.println("Sorry, that is an invalid input, please try again.");
- }
- while (col < 0 || col > 9)
- {
- System.out.println("What column?");
- col=i.nextInt();
- if( col < 0 && col > 9)
- System.out.println("Sorry, that is an invalid input, please try again.");
- }
- String nums="";
- boolean[] games=SudokuPuzzle.getAllowedValues(puzzle1,row,col);
- for(int u=1;u<=9;u++)
- {
- if(!games[u-1])
- {
- nums=nums+u;
- }
- }
- System.out.println(nums);
- row=-1;
- col=-1;
- val=-1;
- break;
- // end choice 2
- case 3 :
- SudokuPuzzle.reset(puzzle1);
- System.out.println("Puzzle Reset");
- row=-1;
- col=-1;
- val=-1;
- break;
- //end choice 3
- case 4 :
- System.exit(0);
- row=-1;
- col=-1;
- val=-1;
- break;
- //end choice 4
- }
- }while(While Loop: Break if checkPuzzle method returns true);
- (WIN CONDITION) System.out.println("You have won yay!!!!");
- }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement