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.GameType;
|
||||||
import tu_darmstadt.sudoku.game.ICellAction;
|
import tu_darmstadt.sudoku.game.ICellAction;
|
||||||
import tu_darmstadt.sudoku.game.solver.Solver;
|
import tu_darmstadt.sudoku.game.solver.Solver;
|
||||||
import tu_darmstadt.sudoku.game.solver.ISolver;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Chris on 06.11.2015.
|
* Created by Chris on 06.11.2015.
|
||||||
|
@ -26,6 +25,7 @@ public class GameController {
|
||||||
private int sectionWidth;
|
private int sectionWidth;
|
||||||
private GameBoard gameBoard;
|
private GameBoard gameBoard;
|
||||||
private Solver solver;
|
private Solver solver;
|
||||||
|
private LinkedList<GameBoard> solvedBoards = new LinkedList<>();
|
||||||
private GameType gameType;
|
private GameType gameType;
|
||||||
private int selectedRow;
|
private int selectedRow;
|
||||||
private int selectedCol;
|
private int selectedCol;
|
||||||
|
@ -141,20 +141,23 @@ public class GameController {
|
||||||
}
|
}
|
||||||
|
|
||||||
public LinkedList<GameBoard> solve() {
|
public LinkedList<GameBoard> solve() {
|
||||||
switch(gameType) {
|
if(solvedBoards.size() == 0) {
|
||||||
case Default_9x9:
|
switch (gameType) {
|
||||||
case Default_6x6:
|
case Default_9x9:
|
||||||
case Default_12x12:
|
case Default_6x6:
|
||||||
solver = new Solver(gameBoard);
|
case Default_12x12:
|
||||||
break;
|
solver = new Solver(gameBoard);
|
||||||
default:
|
break;
|
||||||
throw new UnsupportedOperationException("No Solver for this GameType defined.");
|
default:
|
||||||
}
|
throw new UnsupportedOperationException("No Solver for this GameType defined.");
|
||||||
|
}
|
||||||
|
|
||||||
if(solver.solve(solver.getGameBoard())) {
|
if (solver.solve(solver.getGameBoard())) {
|
||||||
return solver.getSolutions();
|
solvedBoards.addAll(solver.getSolutions());
|
||||||
|
return solvedBoards;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return solvedBoards;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*public boolean loadLevel(GameBoard level) {
|
/*public boolean loadLevel(GameBoard level) {
|
||||||
|
@ -362,19 +365,19 @@ public class GameController {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void selectValue(int value) {
|
public void selectValue(int value) {
|
||||||
if(isCellSelected()) setValue(selectedRow, selectedCol, value);
|
if(isValidCellSelected()) setValue(selectedRow, selectedCol, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteSelectedValue() {
|
public void deleteSelectedValue() {
|
||||||
if(isCellSelected()) deleteValue(selectedRow, selectedCol);
|
if(isValidCellSelected()) deleteValue(selectedRow, selectedCol);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void toggleSelectedNote(int value) {
|
public void toggleSelectedNote(int value) {
|
||||||
if(isCellSelected()) toggleNote(selectedRow, selectedCol, value);
|
if(isValidCellSelected()) toggleNote(selectedRow, selectedCol, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isCellSelected() {
|
public boolean isValidCellSelected() {
|
||||||
return selectedRow != -1 && selectedCol != -1;
|
return selectedRow != -1 && selectedCol != -1 && !getGameCell(selectedRow, selectedCol).isFixed();
|
||||||
}
|
}
|
||||||
|
|
||||||
// public void registerListener(IModelChangeListener l) {
|
// public void registerListener(IModelChangeListener l) {
|
||||||
|
|
|
@ -102,6 +102,8 @@ public class SudokuCellView extends View {
|
||||||
case Value_Highlighted:
|
case Value_Highlighted:
|
||||||
p.setColor(Color.YELLOW);
|
p.setColor(Color.YELLOW);
|
||||||
break;
|
break;
|
||||||
|
case Value_Highlighted_Selected:
|
||||||
|
p.setColor(Color.CYAN);
|
||||||
default:
|
default:
|
||||||
p.setColor(Color.WHITE);
|
p.setColor(Color.WHITE);
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,19 +70,20 @@ public class SudokuFieldLayout extends RelativeLayout {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Set connected Fields
|
// 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., "");
|
for (GameCell c : gameController.getConnectedCells(row, col, highlightConnectedRow, highlightConnectedColumn, highlightConnectedSection)) {
|
||||||
boolean highlightConnectedRow = settings.getBoolean("pref_highlight_rows", true);
|
gamecells[c.getRow()][c.getCol()].setHighlightType(CellHighlightTypes.Connected);
|
||||||
boolean highlightConnectedColumn = settings.getBoolean("pref_highlight_cols", true);
|
}
|
||||||
boolean highlightConnectedSection = settings.getBoolean("pref_highlight_secs", true);
|
// Select touched Cell
|
||||||
|
scv.setHighlightType(CellHighlightTypes.Selected);
|
||||||
for(GameCell c : gameController.getConnectedCells(row,col, highlightConnectedRow, highlightConnectedColumn, highlightConnectedSection)) {
|
} else {
|
||||||
gamecells[c.getRow()][c.getCol()].setHighlightType(CellHighlightTypes.Connected);
|
scv.setHighlightType(CellHighlightTypes.Value_Highlighted_Selected);
|
||||||
}
|
}
|
||||||
// Select touched Cell
|
|
||||||
scv.setHighlightType(CellHighlightTypes.Selected);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,8 +8,10 @@ import android.view.ViewGroup;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
|
||||||
import tu_darmstadt.sudoku.controller.GameController;
|
import tu_darmstadt.sudoku.controller.GameController;
|
||||||
|
import tu_darmstadt.sudoku.game.GameBoard;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by TMZ_LToP on 17.11.2015.
|
* Created by TMZ_LToP on 17.11.2015.
|
||||||
|
@ -28,6 +30,9 @@ public class SudokuSpecialButtonLayout extends LinearLayout {
|
||||||
if(v instanceof SudokuButton) {
|
if(v instanceof SudokuButton) {
|
||||||
SudokuButton btn = (SudokuButton)v;
|
SudokuButton btn = (SudokuButton)v;
|
||||||
|
|
||||||
|
int row = gameController.getSelectedRow();
|
||||||
|
int col = gameController.getSelectedCol();
|
||||||
|
|
||||||
switch(btn.getType()) {
|
switch(btn.getType()) {
|
||||||
case Delete:
|
case Delete:
|
||||||
gameController.deleteSelectedValue();
|
gameController.deleteSelectedValue();
|
||||||
|
@ -43,7 +48,16 @@ public class SudokuSpecialButtonLayout extends LinearLayout {
|
||||||
// TODO: not implemented
|
// TODO: not implemented
|
||||||
break;
|
break;
|
||||||
case Hint:
|
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;
|
break;
|
||||||
case NumberOrCellFirst:
|
case NumberOrCellFirst:
|
||||||
// TODO: not implemented
|
// TODO: not implemented
|
||||||
|
|
Loading…
Reference in a new issue