Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class SudokuDriver{
  3. public static void main(String[] args)
  4. {
  5. Scanner i=new Scanner(System.in);
  6. int row=-1,col=-1,val=-1,x=0;
  7. SudokuPuzzle puzzle1 = new SudokuPuzzle();
  8.  
  9. SudokuPuzzle.initializeBoard(puzzle1);
  10.  
  11.  
  12.  
  13. System.out.println("Welcome to Sudoku. Please choose");
  14. SudokuPuzzle.addInitial(puzzle1, 2, 3 , 8);
  15. SudokuPuzzle.addInitial(puzzle1, 3, 1 , 3);
  16. SudokuPuzzle.addInitial(puzzle1, 7, 7 , 6);
  17. SudokuPuzzle.addInitial(puzzle1, 4, 6 , 3);
  18. SudokuPuzzle.addInitial(puzzle1, 9, 2 , 9);
  19. System.out.println(SudokuPuzzle.toString(puzzle1));
  20. System.out.println();
  21. do
  22. {
  23. 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");
  24. x= Userinput;
  25. switch(UserInput)
  26. {
  27. case 1 :
  28. while (Input Validation While Loop: Column between 1-9)
  29. {
  30. Ask What row?;
  31. row=i.nextInt();
  32. if( Input Validation for Row)
  33. "Sorry, that is an invalid input, please try again.";
  34. }
  35.  
  36. while (Input Validation While Loop: Row between 1-9)
  37. {
  38. Ask What Row;
  39. col=i.nextInt();
  40. if( Input Validation for Column)
  41. "Sorry, that is an invalid input, please try again.";
  42. }
  43.  
  44. while (Input Validation While Loop: Value between 1-9)
  45. {
  46. Ask for value;
  47. val=i.nextInt();
  48. if( val < 0 && val >9)
  49. "Sorry, that is an invalid input, please try again.";
  50. }
  51. ;
  52. AddGuess method;
  53. row=-1;
  54. col=-1;
  55. val=-1;
  56. break;
  57. // end choice 1
  58. case 2 :
  59. while (row < 0 || row > 9)
  60. {
  61. System.out.println("What row?");
  62. row=i.nextInt();
  63. if( row < 0 && row > 9)
  64. System.out.println("Sorry, that is an invalid input, please try again.");
  65. }
  66.  
  67.  
  68. while (col < 0 || col > 9)
  69. {
  70. System.out.println("What column?");
  71. col=i.nextInt();
  72. if( col < 0 && col > 9)
  73. System.out.println("Sorry, that is an invalid input, please try again.");
  74. }
  75.  
  76. String nums="";
  77. boolean[] games=SudokuPuzzle.getAllowedValues(puzzle1,row,col);
  78. for(int u=1;u<=9;u++)
  79. {
  80. if(!games[u-1])
  81. {
  82. nums=nums+u;
  83. }
  84. }
  85. System.out.println(nums);
  86. row=-1;
  87. col=-1;
  88. val=-1;
  89. break;
  90. // end choice 2
  91. case 3 :
  92. SudokuPuzzle.reset(puzzle1);
  93. System.out.println("Puzzle Reset");
  94. row=-1;
  95. col=-1;
  96. val=-1;
  97. break;
  98. //end choice 3
  99. case 4 :
  100. System.exit(0);
  101. row=-1;
  102. col=-1;
  103. val=-1;
  104. break;
  105. //end choice 4
  106.  
  107. }
  108.  
  109.  
  110. }while(While Loop: Break if checkPuzzle method returns true);
  111. (WIN CONDITION) System.out.println("You have won yay!!!!");
  112. }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement