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:
Christopher Beckmann 2015-11-18 04:22:35 +01:00
parent 1bb1d96171
commit 40aab36624
4 changed files with 50 additions and 30 deletions

View file

@ -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,20 +141,23 @@ public class GameController {
}
public LinkedList<GameBoard> solve() {
switch(gameType) {
case Default_9x9:
case Default_6x6:
case Default_12x12:
solver = new Solver(gameBoard);
break;
default:
throw new UnsupportedOperationException("No Solver for this GameType defined.");
}
if(solvedBoards.size() == 0) {
switch (gameType) {
case Default_9x9:
case Default_6x6:
case Default_12x12:
solver = new Solver(gameBoard);
break;
default:
throw new UnsupportedOperationException("No Solver for this GameType defined.");
}
if(solver.solve(solver.getGameBoard())) {
return solver.getSolutions();
if (solver.solve(solver.getGameBoard())) {
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) {

View file

@ -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);
}

View file

@ -70,19 +70,20 @@ 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);
boolean highlightConnectedSection = settings.getBoolean("pref_highlight_secs", true);
//String syncConnPref = sharedPref.getString(SettingsActivity., "");
boolean highlightConnectedRow = settings.getBoolean("pref_highlight_rows", true);
boolean highlightConnectedColumn = settings.getBoolean("pref_highlight_cols", true);
boolean highlightConnectedSection = settings.getBoolean("pref_highlight_secs", true);
for(GameCell c : gameController.getConnectedCells(row,col, highlightConnectedRow, highlightConnectedColumn, highlightConnectedSection)) {
gamecells[c.getRow()][c.getCol()].setHighlightType(CellHighlightTypes.Connected);
for (GameCell c : gameController.getConnectedCells(row, col, highlightConnectedRow, highlightConnectedColumn, highlightConnectedSection)) {
gamecells[c.getRow()][c.getCol()].setHighlightType(CellHighlightTypes.Connected);
}
// Select touched Cell
scv.setHighlightType(CellHighlightTypes.Selected);
} else {
scv.setHighlightType(CellHighlightTypes.Value_Highlighted_Selected);
}
// Select touched Cell
scv.setHighlightType(CellHighlightTypes.Selected);
}
return false;
}

View file

@ -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