Modify hint button to fill in all notes
This commit is contained in:
parent
9a716004d0
commit
bced5e0988
2 changed files with 43 additions and 14 deletions
|
@ -40,8 +40,10 @@ import org.secuso.privacyfriendlysudoku.game.listener.IModelChangedListener;
|
|||
import org.secuso.privacyfriendlysudoku.game.listener.ITimerListener;
|
||||
import org.secuso.privacyfriendlysudoku.ui.GameActivity;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Timer;
|
||||
|
@ -218,6 +220,7 @@ public class GameController implements IModelChangedListener, Parcelable {
|
|||
}*/
|
||||
|
||||
public void hint(){
|
||||
/*
|
||||
if(!isValidCellSelected()) {
|
||||
return;
|
||||
}
|
||||
|
@ -233,7 +236,46 @@ public class GameController implements IModelChangedListener, Parcelable {
|
|||
usedHints++;
|
||||
|
||||
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();
|
||||
|
||||
}
|
||||
|
||||
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) {
|
||||
|
|
|
@ -88,20 +88,7 @@ public class SudokuSpecialButtonLayout extends LinearLayout implements IHighligh
|
|||
gameController.UnDo();
|
||||
break;
|
||||
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();
|
||||
}
|
||||
} 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;
|
||||
default:
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue