Modify hint button to fill in all notes

This commit is contained in:
Joel Therrien 2022-11-10 21:12:51 -08:00
parent 9a716004d0
commit bced5e0988
2 changed files with 43 additions and 14 deletions

View file

@ -40,8 +40,10 @@ import org.secuso.privacyfriendlysudoku.game.listener.IModelChangedListener;
import org.secuso.privacyfriendlysudoku.game.listener.ITimerListener; import org.secuso.privacyfriendlysudoku.game.listener.ITimerListener;
import org.secuso.privacyfriendlysudoku.ui.GameActivity; import org.secuso.privacyfriendlysudoku.ui.GameActivity;
import java.util.Arrays;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.HashSet;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Timer; import java.util.Timer;
@ -218,6 +220,7 @@ public class GameController implements IModelChangedListener, Parcelable {
}*/ }*/
public void hint(){ public void hint(){
/*
if(!isValidCellSelected()) { if(!isValidCellSelected()) {
return; return;
} }
@ -233,7 +236,46 @@ public class GameController implements IModelChangedListener, Parcelable {
usedHints++; usedHints++;
notifyHintListener(); notifyHintListener();
notifyHighlightChangedListeners();*/
final GameCell[][] field = gameBoard.getField();
for(int row_id=0; row_id < field.length; row_id++) {
final GameCell[] row_field = field[row_id];
for(int column_id=0; column_id < row_field.length; column_id++) {
final GameCell cell = row_field[column_id];
if(cell.hasValue()){
continue;
}
final boolean[] notes = new boolean[gameBoard.getSize()];
Arrays.fill(notes, true);
removeFixedValues(notes, gameBoard.getRow(row_id));
removeFixedValues(notes, gameBoard.getColumn(column_id));
removeFixedValues(notes, gameBoard.getSection(row_id, column_id));
cell.deleteNotes();
for(int i=0; i<notes.length; i++){
if(notes[i]) {
cell.setNote(i+1);
}
}
}
}
undoRedoManager.addState(gameBoard);
notifyHighlightChangedListeners(); notifyHighlightChangedListeners();
}
private static void removeFixedValues(boolean[] notes, LinkedList<GameCell> section) {
for(GameCell neighbour_cell : section) {
if(neighbour_cell.isFixed()){
notes[neighbour_cell.getValue() - 1] = false;
}
}
} }
private void setGameType(GameType type) { private void setGameType(GameType type) {

View file

@ -88,20 +88,7 @@ public class SudokuSpecialButtonLayout extends LinearLayout implements IHighligh
gameController.UnDo(); gameController.UnDo();
break; break;
case Hint: case Hint:
if(gameController.isValidCellSelected()) {
if(gameController.getUsedHints() == 0 && !gameController.gameIsCustom()) {
// are you sure you want to use a hint?
HintConfirmationDialog hintDialog = new HintConfirmationDialog();
hintDialog.show(fragmentManager, "HintDialogFragment");
} else {
gameController.hint(); gameController.hint();
}
} else {
// Display a Toast that explains how to use the Hint function.
Toast t = Toast.makeText(getContext(), R.string.hint_usage, Toast.LENGTH_SHORT);
t.show();
}
break; break;
default: default:
break; break;