This commit is contained in:
Christopher Beckmann 2015-11-13 14:40:58 +01:00
parent f43803ad46
commit 8d2358b5aa
5 changed files with 59 additions and 14 deletions

View file

@ -19,9 +19,6 @@
android:name="tu_darmstadt.sudoku.ui.SettingsActivity"
android:label="@string/title_activity_settings"
android:parentActivityName="tu_darmstadt.sudoku.ui.MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="tu_darmstadt.sudoku.ui.MainActivity" />
</activity>
<activity
android:name="tu_darmstadt.sudoku.ui.GameActivity"

View file

@ -63,9 +63,13 @@ public class GameController {
this.sectionHeight = sectionHeight;
this.sectionWidth = sectionWidth;
this.gameField = new GameField(size, sectionHeight, sectionWidth);
if(fixedValues == null) throw new IllegalArgumentException("fixedValues may not be null.");
gameField.initCells(fixedValues);
// now set the values that are not fixed
if (setValues != null) {
for (int i = 0; i < size * size; i++) {
int row = (int) Math.floor(i / size);
int col = i % size;
@ -73,6 +77,12 @@ public class GameController {
}
}
if(setNotes != null) {
// set notes.
}
}
public void setSettings(SharedPreferences pref) {
settings = pref;
}
@ -240,13 +250,36 @@ public class GameController {
return gameField.toString();
}
public int getSelectedRow() {
return selectedRow;
}
public int getSelectedCol() {
return selectedCol;
}
public void selectCell(int row, int col) {
this.selectedRow = row;
this.selectedCol = col;
if(selectedRow == row && 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) {
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) {

View file

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

View file

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

View file

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