Slightly less ugly fix for invalid input
This commit is contained in:
		
							parent
							
								
									2209dd7786
								
							
						
					
					
						commit
						7e5253fb4b
					
				
					 1 changed files with 6 additions and 9 deletions
				
			
		|  | @ -103,20 +103,17 @@ public class SudokuController { | |||
|                 try { | ||||
|                     value = Integer.parseInt(cellValue); | ||||
|                 } catch (NumberFormatException ex) { | ||||
|                     model.set(row, col, 0); | ||||
|                     view.updateView(model.getBoard()); | ||||
|                     view.showErrorMessage("Invalid input. Try again."); | ||||
|                     return; // Bail out if the input is invalid | ||||
|                     value = 0; | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|             // Check if the input is legal and update the model and view | ||||
|             if (model.isLegal(row, col, value)) { | ||||
|                 model.set(row, col, value); | ||||
|                 view.updateView(model.getBoard()); | ||||
|             } else { | ||||
|             // If the input is invalid | ||||
|             if (!model.isLegal(row, col, value)) { | ||||
|                 value = 0; | ||||
|                 view.showErrorMessage("Invalid input. Try again."); | ||||
|             } | ||||
|             model.set(row, col, value); | ||||
|             view.updateView(model.getBoard()); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Imbus
						Imbus