diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 3fa68c7..fc87649 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -18,16 +18,18 @@
+ android:parentActivityName="tu_darmstadt.sudoku.ui.MainActivity" >
+
+
diff --git a/app/src/main/java/tu_darmstadt/sudoku/controller/GameController.java b/app/src/main/java/tu_darmstadt/sudoku/controller/GameController.java
index 1e43342..acf756d 100644
--- a/app/src/main/java/tu_darmstadt/sudoku/controller/GameController.java
+++ b/app/src/main/java/tu_darmstadt/sudoku/controller/GameController.java
@@ -47,6 +47,53 @@ public class GameController {
setSettings(pref);
}
+ public void loadNewLevel(GameType type, int difficulty) {
+ switch(type) {
+ case Default_9x9:
+ loadLevel(GameType.Default_9x9,
+ new int[]{5, 0, 1, 9, 0, 0, 0, 0, 0,
+ 2, 0, 0, 0, 0, 4, 9, 5, 0,
+ 3, 9, 0, 7, 0, 0, 0, 2, 6,
+ 0, 3, 0, 0, 0, 1, 0, 7, 2,
+ 0, 0, 6, 0, 5, 7, 0, 0, 0,
+ 0, 7, 2, 0, 0, 9, 0, 4, 1,
+ 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}
+ , null, null);
+ break;
+ case Default_12x12:
+ loadLevel(GameType.Default_12x12,
+ new int[] {0, 2, 1, 0, 0, 6, 0, 0, 0, 8, 9, 0,
+ 10, 0,12, 0, 0, 2, 1,11, 0, 0, 0, 6,
+ 6, 0, 0, 4, 0,12, 0, 0, 0, 0, 2, 1,
+ 0, 0, 0, 5, 0, 0, 0, 4,11,10, 0, 0,
+ 0,10, 0, 1, 0, 0, 6, 0, 0, 0, 0, 0,
+ 0, 7, 0, 0,11, 0, 0, 0, 0,12, 8, 9,
+ 2, 1,11, 0, 0, 0, 0, 7, 0, 0, 6, 0,
+ 0, 0, 0, 0, 0, 5, 0, 0, 4, 0,10, 0,
+ 0, 0, 7, 3, 9, 0, 0, 0, 1, 0, 0, 0,
+ 1, 5, 0, 0, 0, 0, 4, 0,10, 0, 0,11,
+ 9, 0, 0, 0, 1,10, 2, 0, 0, 6, 0, 7,
+ 0, 6,10, 0, 0, 0, 8, 0, 0, 1,12, 0}
+ ,null, null);
+ break;
+ case Unspecified:
+ default:
+ loadLevel(GameType.Default_9x9,
+ new int[]{5, 0, 1, 9, 0, 0, 0, 0, 0,
+ 2, 0, 0, 0, 0, 4, 9, 5, 0,
+ 3, 9, 0, 7, 0, 0, 0, 2, 6,
+ 0, 3, 0, 0, 0, 1, 0, 7, 2,
+ 0, 0, 6, 0, 5, 7, 0, 0, 0,
+ 0, 7, 2, 0, 0, 9, 0, 4, 1,
+ 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}
+ , null, null);
+ }
+ }
+
public void loadLevel(GameType type, int[] fixedValues, int[] setValues, int[][] setNotes) {
setGameType(type);
this.gameBoard = new GameBoard(size, sectionHeight, sectionWidth);
@@ -67,7 +114,6 @@ public class GameController {
if(setNotes != null) {
// set notes.
}
-
}
public void setSettings(SharedPreferences pref) {
@@ -260,15 +306,19 @@ public class GameController {
}
public void setSelectedValue(int value) {
- if(selectedRow != -1 && selectedCol != -1) setValue(selectedRow, selectedCol, value);
+ if(isCellSelected()) setValue(selectedRow, selectedCol, value);
}
public void deleteSelectedValue() {
- if(selectedRow != -1 && selectedCol != -1) setValue(selectedRow, selectedCol, 0);
+ if(isCellSelected()) setValue(selectedRow, selectedCol, 0);
}
public void toggleSelectedNote(int value) {
- if(selectedRow != -1 && selectedCol != -1) toggleNote(selectedRow, selectedCol, value);
+ if(isCellSelected()) toggleNote(selectedRow, selectedCol, value);
+ }
+
+ public boolean isCellSelected() {
+ return selectedRow != -1 && selectedCol != -1;
}
// public void registerListener(IModelChangeListener l) {
diff --git a/app/src/main/java/tu_darmstadt/sudoku/ui/GameActivity.java b/app/src/main/java/tu_darmstadt/sudoku/ui/GameActivity.java
index e5d6c2f..d171cc1 100644
--- a/app/src/main/java/tu_darmstadt/sudoku/ui/GameActivity.java
+++ b/app/src/main/java/tu_darmstadt/sudoku/ui/GameActivity.java
@@ -33,6 +33,19 @@ public class GameActivity extends AppCompatActivity implements NavigationView.On
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+ GameType gameType = GameType.Unspecified;
+ int gameDifficulty = 0;
+
+ Bundle extras = getIntent().getExtras();
+ if (extras != null) {
+ Object o = extras.get("gameType");
+ if(o instanceof GameType) {
+ gameType = (GameType)extras.get("gameType");
+ }
+ gameDifficulty = extras.getInt("gameDifficulty");
+
+ }
+
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
setContentView(R.layout.activity_game_view);
@@ -42,31 +55,8 @@ public class GameActivity extends AppCompatActivity implements NavigationView.On
//Create new GameField
layout = (SudokuFieldLayout)findViewById(R.id.sudokuLayout);
gameController = new GameController(sharedPref);
- /*gameController.loadLevel(GameType.Default_9x9,
- new int[]{5, 0, 1, 9, 0, 0, 0, 0, 0,
- 2, 0, 0, 0, 0, 4, 9, 5, 0,
- 3, 9, 0, 7, 0, 0, 0, 2, 6,
- 0, 3, 0, 0, 0, 1, 0, 7, 2,
- 0, 0, 6, 0, 5, 7, 0, 0, 0,
- 0, 7, 2, 0, 0, 9, 0, 4, 1,
- 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}
- , null, null);*/
- gameController.loadLevel(GameType.Default_12x12,
- new int[]{0, 2, 1, 0, 0, 6, 0, 0, 0, 8, 9, 0,
- 10, 0, 12, 0, 0, 2, 1, 11, 0, 0, 0, 6,
- 6, 0, 0, 4, 0, 12, 0, 0, 0, 0, 2, 1,
- 0, 0, 0, 5, 0, 0, 0, 4, 11, 10, 0, 0,
- 0, 10, 0, 1, 0, 0, 6, 0, 0, 0, 0, 0,
- 0, 7, 0, 0, 11, 0, 0, 0, 0, 12, 8, 9,
- 2, 1, 11, 0, 0, 0, 0, 7, 0, 0, 6, 0,
- 0, 0, 0, 0, 0, 5, 0, 0, 4, 0, 10, 0,
- 0, 0, 7, 3, 9, 0, 0, 0, 1, 0, 0, 0,
- 1, 5, 0, 0, 0, 0, 4, 0, 10, 0, 0, 11,
- 9, 0, 0, 0, 1, 10, 2, 0, 0, 6, 0, 7,
- 0, 6, 10, 0, 0, 0, 8, 0, 0, 1, 12, 0}
- , null, null);
+
+ gameController.loadNewLevel(gameType, gameDifficulty);
layout.setGame(gameController);
layout.setSettings(sharedPref);
diff --git a/app/src/main/java/tu_darmstadt/sudoku/ui/MainActivity.java b/app/src/main/java/tu_darmstadt/sudoku/ui/MainActivity.java
index ecf1d93..9ec32c3 100644
--- a/app/src/main/java/tu_darmstadt/sudoku/ui/MainActivity.java
+++ b/app/src/main/java/tu_darmstadt/sudoku/ui/MainActivity.java
@@ -17,7 +17,7 @@ public class MainActivity extends AppCompatActivity {
}
public void onClicktext(View view) {
- Intent i = new Intent(this, GameActivity.class);
+ Intent i = new Intent(this, NewGameActivity.class);
startActivity(i);
}
diff --git a/app/src/main/java/tu_darmstadt/sudoku/ui/NewGameActivity.java b/app/src/main/java/tu_darmstadt/sudoku/ui/NewGameActivity.java
new file mode 100644
index 0000000..f7e98be
--- /dev/null
+++ b/app/src/main/java/tu_darmstadt/sudoku/ui/NewGameActivity.java
@@ -0,0 +1,36 @@
+package tu_darmstadt.sudoku.ui;
+
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.preference.PreferenceManager;
+import android.support.v7.app.AppCompatActivity;
+import android.os.Bundle;
+import android.view.View;
+
+import tu_darmstadt.sudoku.controller.GameController;
+import tu_darmstadt.sudoku.game.GameType;
+import tu_darmstadt.sudoku.ui.view.R;
+
+public class NewGameActivity extends AppCompatActivity {
+
+ GameType gameType = GameType.Default_9x9;
+ int gameDifficulty = 1;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_new_game);
+ }
+
+ public void onPlayClick(View view) {
+
+ // TODO get settings from GUI
+
+ Intent i = new Intent(this, GameActivity.class);
+
+ i.putExtra("gameType", gameType);
+ i.putExtra("gameDifficulty", gameDifficulty);
+
+ startActivity(i);
+ }
+}
diff --git a/app/src/main/java/tu_darmstadt/sudoku/ui/view/SudokuButtonType.java b/app/src/main/java/tu_darmstadt/sudoku/ui/view/SudokuButtonType.java
index ac58f83..4a2ee55 100644
--- a/app/src/main/java/tu_darmstadt/sudoku/ui/view/SudokuButtonType.java
+++ b/app/src/main/java/tu_darmstadt/sudoku/ui/view/SudokuButtonType.java
@@ -11,5 +11,6 @@ public enum SudokuButtonType {
Hint,
NoteToggle,
NumberOrCellFirst,
- Delete
+ Delete,
+ Reset
}
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index 9ec0ac3..1445a83 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -1,22 +1,60 @@
+ android:orientation="vertical"
+ tools:context="tu_darmstadt.sudoku.activity.MainActivity"
+ android:weightSum="10"
+ android:divider="#000">
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/activity_new_game.xml b/app/src/main/res/layout/activity_new_game.xml
new file mode 100644
index 0000000..2e69cd6
--- /dev/null
+++ b/app/src/main/res/layout/activity_new_game.xml
@@ -0,0 +1,36 @@
+
+
+
+
+
+
+
+
+