Hint Button is now working and will reveal the selected cell for you.
Not sure if I should check the board for errors as well.
This commit is contained in:
parent
1bb1d96171
commit
40aab36624
4 changed files with 50 additions and 30 deletions
|
@ -14,7 +14,6 @@ import tu_darmstadt.sudoku.controller.helper.GameInfoContainer;
|
|||
import tu_darmstadt.sudoku.game.GameType;
|
||||
import tu_darmstadt.sudoku.game.ICellAction;
|
||||
import tu_darmstadt.sudoku.game.solver.Solver;
|
||||
import tu_darmstadt.sudoku.game.solver.ISolver;
|
||||
|
||||
/**
|
||||
* Created by Chris on 06.11.2015.
|
||||
|
@ -26,6 +25,7 @@ public class GameController {
|
|||
private int sectionWidth;
|
||||
private GameBoard gameBoard;
|
||||
private Solver solver;
|
||||
private LinkedList<GameBoard> solvedBoards = new LinkedList<>();
|
||||
private GameType gameType;
|
||||
private int selectedRow;
|
||||
private int selectedCol;
|
||||
|
@ -141,6 +141,7 @@ public class GameController {
|
|||
}
|
||||
|
||||
public LinkedList<GameBoard> solve() {
|
||||
if(solvedBoards.size() == 0) {
|
||||
switch (gameType) {
|
||||
case Default_9x9:
|
||||
case Default_6x6:
|
||||
|
@ -152,9 +153,11 @@ public class GameController {
|
|||
}
|
||||
|
||||
if (solver.solve(solver.getGameBoard())) {
|
||||
return solver.getSolutions();
|
||||
solvedBoards.addAll(solver.getSolutions());
|
||||
return solvedBoards;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return solvedBoards;
|
||||
}
|
||||
|
||||
/*public boolean loadLevel(GameBoard level) {
|
||||
|
@ -362,19 +365,19 @@ public class GameController {
|
|||
}
|
||||
|
||||
public void selectValue(int value) {
|
||||
if(isCellSelected()) setValue(selectedRow, selectedCol, value);
|
||||
if(isValidCellSelected()) setValue(selectedRow, selectedCol, value);
|
||||
}
|
||||
|
||||
public void deleteSelectedValue() {
|
||||
if(isCellSelected()) deleteValue(selectedRow, selectedCol);
|
||||
if(isValidCellSelected()) deleteValue(selectedRow, selectedCol);
|
||||
}
|
||||
|
||||
public void toggleSelectedNote(int value) {
|
||||
if(isCellSelected()) toggleNote(selectedRow, selectedCol, value);
|
||||
if(isValidCellSelected()) toggleNote(selectedRow, selectedCol, value);
|
||||
}
|
||||
|
||||
public boolean isCellSelected() {
|
||||
return selectedRow != -1 && selectedCol != -1;
|
||||
public boolean isValidCellSelected() {
|
||||
return selectedRow != -1 && selectedCol != -1 && !getGameCell(selectedRow, selectedCol).isFixed();
|
||||
}
|
||||
|
||||
// public void registerListener(IModelChangeListener l) {
|
||||
|
|
|
@ -102,6 +102,8 @@ public class SudokuCellView extends View {
|
|||
case Value_Highlighted:
|
||||
p.setColor(Color.YELLOW);
|
||||
break;
|
||||
case Value_Highlighted_Selected:
|
||||
p.setColor(Color.CYAN);
|
||||
default:
|
||||
p.setColor(Color.WHITE);
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ public class SudokuFieldLayout extends RelativeLayout {
|
|||
return false;
|
||||
}
|
||||
// Set connected Fields
|
||||
|
||||
if(gameController.isValidCellSelected()) {
|
||||
//String syncConnPref = sharedPref.getString(SettingsActivity., "");
|
||||
boolean highlightConnectedRow = settings.getBoolean("pref_highlight_rows", true);
|
||||
boolean highlightConnectedColumn = settings.getBoolean("pref_highlight_cols", true);
|
||||
|
@ -81,8 +81,9 @@ public class SudokuFieldLayout extends RelativeLayout {
|
|||
}
|
||||
// Select touched Cell
|
||||
scv.setHighlightType(CellHighlightTypes.Selected);
|
||||
|
||||
|
||||
} else {
|
||||
scv.setHighlightType(CellHighlightTypes.Value_Highlighted_Selected);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -8,8 +8,10 @@ import android.view.ViewGroup;
|
|||
import android.widget.LinearLayout;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import tu_darmstadt.sudoku.controller.GameController;
|
||||
import tu_darmstadt.sudoku.game.GameBoard;
|
||||
|
||||
/**
|
||||
* Created by TMZ_LToP on 17.11.2015.
|
||||
|
@ -28,6 +30,9 @@ public class SudokuSpecialButtonLayout extends LinearLayout {
|
|||
if(v instanceof SudokuButton) {
|
||||
SudokuButton btn = (SudokuButton)v;
|
||||
|
||||
int row = gameController.getSelectedRow();
|
||||
int col = gameController.getSelectedCol();
|
||||
|
||||
switch(btn.getType()) {
|
||||
case Delete:
|
||||
gameController.deleteSelectedValue();
|
||||
|
@ -43,7 +48,16 @@ public class SudokuSpecialButtonLayout extends LinearLayout {
|
|||
// TODO: not implemented
|
||||
break;
|
||||
case Hint:
|
||||
// TODO: not implemented
|
||||
if(gameController.isValidCellSelected()) {
|
||||
LinkedList<GameBoard> solved = gameController.solve();
|
||||
if(solved.size() >= 1) {
|
||||
GameBoard solvedBoard = solved.get(0);
|
||||
// test every placed value so far
|
||||
|
||||
// and reveal the selected value.
|
||||
gameController.selectValue(solvedBoard.getCell(row, col).getValue());
|
||||
}
|
||||
}
|
||||
break;
|
||||
case NumberOrCellFirst:
|
||||
// TODO: not implemented
|
||||
|
|
Loading…
Reference in a new issue