diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 938bcea..e993d63 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -18,10 +18,7 @@
-
+ android:parentActivityName="tu_darmstadt.sudoku.ui.MainActivity">
deselect it
+ selectedRow = -1;
+ selectedCol = -1;
+ } else {
+ // else we set it to the new selected field
+ selectedRow = row;
+ selectedCol = col;
+ }
}
public void setSelectedValue(int value) {
- setValue(selectedRow, selectedCol, value);
+ if(selectedRow != -1 && selectedCol != -1) setValue(selectedRow, selectedCol, value);
+ }
+
+ public void deleteSelectedValue() {
+ if(selectedRow != -1 && selectedCol != -1) setValue(selectedRow, selectedCol, 0);
+ }
+
+ public void toggleSelectedNote(int value) {
+ if(selectedRow != -1 && selectedCol != -1) toggleNote(selectedRow, selectedCol, value);
}
// public void registerListener(IModelChangeListener l) {
diff --git a/app/src/main/java/tu_darmstadt/sudoku/game/GameField.java b/app/src/main/java/tu_darmstadt/sudoku/game/GameField.java
index 7b1ddeb..a7a12d7 100644
--- a/app/src/main/java/tu_darmstadt/sudoku/game/GameField.java
+++ b/app/src/main/java/tu_darmstadt/sudoku/game/GameField.java
@@ -51,14 +51,16 @@ public class GameField implements Cloneable {
{ 7, 0, 0, 0, 1, 0, 3, 0, 5 }};
// Initit the game field
+ int[] oneDimension = new int[size*size];
for(int i = 0; i < size; i++) {
for(int j = 0; j < size; j++) {
- field[i][j] = new GameCell(i,j,size,placeholder[i][j]);
+ oneDimension[i*size+j] = placeholder[i][j];
}
}
}
public void initCells(int[] level) {
+ int count = 0;
if(level.length != size*size) {
throw new IllegalArgumentException("Levelarray must have length of "+size*size+".");
}
@@ -66,8 +68,10 @@ public class GameField implements Cloneable {
for(int i = 0; i < size*size; i++) {
int row = (int)Math.floor(i/size);
int col = i%size;
+ if(level[i] != 0) count++;
field[row][col] = new GameCell(row,col,size,level[i]);
}
+ if(count < 17) throw new IllegalArgumentException("There must be at least 17 fixed values.");
}
public GameCell getCell(int row, int col) {
diff --git a/app/src/main/java/tu_darmstadt/sudoku/ui/view/SudokuFieldLayout.java b/app/src/main/java/tu_darmstadt/sudoku/ui/view/SudokuFieldLayout.java
index cefd49d..9807264 100644
--- a/app/src/main/java/tu_darmstadt/sudoku/ui/view/SudokuFieldLayout.java
+++ b/app/src/main/java/tu_darmstadt/sudoku/ui/view/SudokuFieldLayout.java
@@ -53,12 +53,22 @@ public class SudokuFieldLayout extends RelativeLayout {
int row = scv.getRow();
int col = scv.getCol();
+ gameController.selectCell(row, col);
+ row = gameController.getSelectedRow();
+ col = gameController.getSelectedCol();
+
// Reset everything
for(int i = 0; i < gameController.getSize(); i++) {
for(int j = 0; j < gameController.getSize(); j++) {
gamecells[i][j].setHighlightType(CellHighlightTypes.Default);
}
}
+
+ if(row == -1 || col == -1) {
+ // we clicked on the same cell 2 times.
+ // means it got deselected and we dont highlight any cells.
+ return false;
+ }
// Set connected Fields
//String syncConnPref = sharedPref.getString(SettingsActivity., "");
@@ -70,7 +80,6 @@ public class SudokuFieldLayout extends RelativeLayout {
gamecells[c.getRow()][c.getCol()].setHighlightType(CellHighlightTypes.Connected);
}
// Select touched Cell
- gameController.selectCell(row, col);
scv.setHighlightType(CellHighlightTypes.Selected);
diff --git a/app/src/test/java/tu_darmstadt/sudoku/game/solver/SolverTest.java b/app/src/test/java/tu_darmstadt/sudoku/game/solver/SolverTest.java
index 9745627..1217f11 100644
--- a/app/src/test/java/tu_darmstadt/sudoku/game/solver/SolverTest.java
+++ b/app/src/test/java/tu_darmstadt/sudoku/game/solver/SolverTest.java
@@ -26,6 +26,8 @@ public class SolverTest {
{ 0, 0, 0, 0, 7, 0, 4, 0, 9 },
{ 6, 4, 0, 0, 0, 0, 0, 0, 0 },
{ 7, 0, 0, 0, 1, 0, 3, 0, 5 }};
+
+ controller.loadLevel(9,3,3,new int[]{0,0,0,0,4,1,0,0,0,0,6,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,3,2,0,6,0,0,0,0,0,0,0,0,0,5,0,0,4,1,7,0,0,0,0,0,0,0,0,0,0,0,2,0,0,3,0,0,0,4,8,0,0,0,0,0,0,5,0,1,0,0,0,0,0,0},null,null);
}
//000041000060000200000000000320600000000050041700000000000200300048000000501000000