Bug fix.
This commit is contained in:
parent
f43803ad46
commit
8d2358b5aa
5 changed files with 59 additions and 14 deletions
|
@ -18,10 +18,7 @@
|
||||||
<activity
|
<activity
|
||||||
android:name="tu_darmstadt.sudoku.ui.SettingsActivity"
|
android:name="tu_darmstadt.sudoku.ui.SettingsActivity"
|
||||||
android:label="@string/title_activity_settings"
|
android:label="@string/title_activity_settings"
|
||||||
android:parentActivityName="tu_darmstadt.sudoku.ui.MainActivity" >
|
android:parentActivityName="tu_darmstadt.sudoku.ui.MainActivity">
|
||||||
<meta-data
|
|
||||||
android:name="android.support.PARENT_ACTIVITY"
|
|
||||||
android:value="tu_darmstadt.sudoku.ui.MainActivity" />
|
|
||||||
</activity>
|
</activity>
|
||||||
<activity
|
<activity
|
||||||
android:name="tu_darmstadt.sudoku.ui.GameActivity"
|
android:name="tu_darmstadt.sudoku.ui.GameActivity"
|
||||||
|
|
|
@ -63,14 +63,24 @@ public class GameController {
|
||||||
this.sectionHeight = sectionHeight;
|
this.sectionHeight = sectionHeight;
|
||||||
this.sectionWidth = sectionWidth;
|
this.sectionWidth = sectionWidth;
|
||||||
this.gameField = new GameField(size, sectionHeight, sectionWidth);
|
this.gameField = new GameField(size, sectionHeight, sectionWidth);
|
||||||
|
|
||||||
|
if(fixedValues == null) throw new IllegalArgumentException("fixedValues may not be null.");
|
||||||
|
|
||||||
gameField.initCells(fixedValues);
|
gameField.initCells(fixedValues);
|
||||||
|
|
||||||
// now set the values that are not fixed
|
// now set the values that are not fixed
|
||||||
for(int i = 0; i < size*size; i++) {
|
if (setValues != null) {
|
||||||
int row = (int)Math.floor(i/size);
|
for (int i = 0; i < size * size; i++) {
|
||||||
int col = i%size;
|
int row = (int) Math.floor(i / size);
|
||||||
setValue(row, col, setValues[i]);
|
int col = i % size;
|
||||||
|
setValue(row, col, setValues[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(setNotes != null) {
|
||||||
|
// set notes.
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSettings(SharedPreferences pref) {
|
public void setSettings(SharedPreferences pref) {
|
||||||
|
@ -129,7 +139,7 @@ public class GameController {
|
||||||
/** Use with care.
|
/** Use with care.
|
||||||
*/
|
*/
|
||||||
public GameCell getGameCell(int row, int col) {
|
public GameCell getGameCell(int row, int col) {
|
||||||
return gameField.getCell(row,col);
|
return gameField.getCell(row, col);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSolved() {
|
public boolean isSolved() {
|
||||||
|
@ -240,13 +250,36 @@ public class GameController {
|
||||||
return gameField.toString();
|
return gameField.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getSelectedRow() {
|
||||||
|
return selectedRow;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSelectedCol() {
|
||||||
|
return selectedCol;
|
||||||
|
}
|
||||||
|
|
||||||
public void selectCell(int row, int col) {
|
public void selectCell(int row, int col) {
|
||||||
this.selectedRow = row;
|
if(selectedRow == row && selectedCol == col) {
|
||||||
this.selectedCol = col;
|
// if we select the same field 2ce -> 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) {
|
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) {
|
// public void registerListener(IModelChangeListener l) {
|
||||||
|
|
|
@ -51,14 +51,16 @@ public class GameField implements Cloneable {
|
||||||
{ 7, 0, 0, 0, 1, 0, 3, 0, 5 }};
|
{ 7, 0, 0, 0, 1, 0, 3, 0, 5 }};
|
||||||
|
|
||||||
// Initit the game field
|
// Initit the game field
|
||||||
|
int[] oneDimension = new int[size*size];
|
||||||
for(int i = 0; i < size; i++) {
|
for(int i = 0; i < size; i++) {
|
||||||
for(int j = 0; j < size; j++) {
|
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) {
|
public void initCells(int[] level) {
|
||||||
|
int count = 0;
|
||||||
if(level.length != size*size) {
|
if(level.length != size*size) {
|
||||||
throw new IllegalArgumentException("Levelarray must have length of "+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++) {
|
for(int i = 0; i < size*size; i++) {
|
||||||
int row = (int)Math.floor(i/size);
|
int row = (int)Math.floor(i/size);
|
||||||
int col = i%size;
|
int col = i%size;
|
||||||
|
if(level[i] != 0) count++;
|
||||||
field[row][col] = new GameCell(row,col,size,level[i]);
|
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) {
|
public GameCell getCell(int row, int col) {
|
||||||
|
|
|
@ -53,12 +53,22 @@ public class SudokuFieldLayout extends RelativeLayout {
|
||||||
int row = scv.getRow();
|
int row = scv.getRow();
|
||||||
int col = scv.getCol();
|
int col = scv.getCol();
|
||||||
|
|
||||||
|
gameController.selectCell(row, col);
|
||||||
|
row = gameController.getSelectedRow();
|
||||||
|
col = gameController.getSelectedCol();
|
||||||
|
|
||||||
// Reset everything
|
// Reset everything
|
||||||
for(int i = 0; i < gameController.getSize(); i++) {
|
for(int i = 0; i < gameController.getSize(); i++) {
|
||||||
for(int j = 0; j < gameController.getSize(); j++) {
|
for(int j = 0; j < gameController.getSize(); j++) {
|
||||||
gamecells[i][j].setHighlightType(CellHighlightTypes.Default);
|
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
|
// Set connected Fields
|
||||||
|
|
||||||
//String syncConnPref = sharedPref.getString(SettingsActivity., "");
|
//String syncConnPref = sharedPref.getString(SettingsActivity., "");
|
||||||
|
@ -70,7 +80,6 @@ public class SudokuFieldLayout extends RelativeLayout {
|
||||||
gamecells[c.getRow()][c.getCol()].setHighlightType(CellHighlightTypes.Connected);
|
gamecells[c.getRow()][c.getCol()].setHighlightType(CellHighlightTypes.Connected);
|
||||||
}
|
}
|
||||||
// Select touched Cell
|
// Select touched Cell
|
||||||
gameController.selectCell(row, col);
|
|
||||||
scv.setHighlightType(CellHighlightTypes.Selected);
|
scv.setHighlightType(CellHighlightTypes.Selected);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,8 @@ public class SolverTest {
|
||||||
{ 0, 0, 0, 0, 7, 0, 4, 0, 9 },
|
{ 0, 0, 0, 0, 7, 0, 4, 0, 9 },
|
||||||
{ 6, 4, 0, 0, 0, 0, 0, 0, 0 },
|
{ 6, 4, 0, 0, 0, 0, 0, 0, 0 },
|
||||||
{ 7, 0, 0, 0, 1, 0, 3, 0, 5 }};
|
{ 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
|
//000041000060000200000000000320600000000050041700000000000200300048000000501000000
|
||||||
|
|
Loading…
Reference in a new issue