Redesigned a bit of the model.
Added JUnit Tests for GameController. Added a GameView, that doesn't show the game yet though.
This commit is contained in:
parent
351bb3bc2d
commit
b5dc145bb7
22 changed files with 797 additions and 84 deletions
40
app/app.iml
40
app/app.iml
|
@ -9,14 +9,15 @@
|
||||||
<facet type="android" name="Android">
|
<facet type="android" name="Android">
|
||||||
<configuration>
|
<configuration>
|
||||||
<option name="SELECTED_BUILD_VARIANT" value="debug" />
|
<option name="SELECTED_BUILD_VARIANT" value="debug" />
|
||||||
<option name="SELECTED_TEST_ARTIFACT" value="_android_test_" />
|
<option name="SELECTED_TEST_ARTIFACT" value="_unit_test_" />
|
||||||
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
|
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
|
||||||
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
|
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
|
||||||
<option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugAndroidTest" />
|
<option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugUnitTest" />
|
||||||
<option name="COMPILE_JAVA_TEST_TASK_NAME" value="compileDebugAndroidTestSources" />
|
<option name="COMPILE_JAVA_TEST_TASK_NAME" value="compileDebugUnitTestSources" />
|
||||||
<afterSyncTasks>
|
<afterSyncTasks>
|
||||||
<task>generateDebugAndroidTestSources</task>
|
|
||||||
<task>generateDebugSources</task>
|
<task>generateDebugSources</task>
|
||||||
|
<task>mockableAndroidJar</task>
|
||||||
|
<task>prepareDebugUnitTestDependencies</task>
|
||||||
</afterSyncTasks>
|
</afterSyncTasks>
|
||||||
<option name="ALLOW_USER_CONFIGURATION" value="false" />
|
<option name="ALLOW_USER_CONFIGURATION" value="false" />
|
||||||
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
|
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
|
||||||
|
@ -28,7 +29,7 @@
|
||||||
</component>
|
</component>
|
||||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="false">
|
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="false">
|
||||||
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
|
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
|
||||||
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/androidTest/debug" />
|
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/test/debug" />
|
||||||
<exclude-output />
|
<exclude-output />
|
||||||
<content url="file://$MODULE_DIR$">
|
<content url="file://$MODULE_DIR$">
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
|
||||||
|
@ -37,12 +38,6 @@
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/debug" type="java-resource" />
|
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/debug" type="java-resource" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/androidTest/debug" isTestSource="true" generated="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/androidTest/debug" isTestSource="true" generated="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/debug" isTestSource="true" generated="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/androidTest/debug" isTestSource="true" generated="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/debug" type="java-test-resource" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/androidTest/debug" type="java-test-resource" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
|
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
|
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
|
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
|
||||||
|
@ -50,6 +45,13 @@
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/res" type="java-test-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/resources" type="java-test-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/assets" type="java-test-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/aidl" isTestSource="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/java" isTestSource="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/jni" isTestSource="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/rs" isTestSource="true" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
|
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
|
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
|
||||||
|
@ -57,13 +59,13 @@
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
|
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
|
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
|
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
|
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
|
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
|
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
|
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
|
||||||
|
@ -93,6 +95,8 @@
|
||||||
<orderEntry type="jdk" jdkName="Android API 23 Platform" jdkType="Android SDK" />
|
<orderEntry type="jdk" jdkName="Android API 23 Platform" jdkType="Android SDK" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
<orderEntry type="library" exported="" name="recyclerview-v7-23.1.0" level="project" />
|
<orderEntry type="library" exported="" name="recyclerview-v7-23.1.0" level="project" />
|
||||||
|
<orderEntry type="library" exported="" scope="TEST" name="hamcrest-core-1.3" level="project" />
|
||||||
|
<orderEntry type="library" exported="" scope="TEST" name="junit-4.12" level="project" />
|
||||||
<orderEntry type="library" exported="" name="support-v4-23.1.0" level="project" />
|
<orderEntry type="library" exported="" name="support-v4-23.1.0" level="project" />
|
||||||
<orderEntry type="library" exported="" name="design-23.1.0" level="project" />
|
<orderEntry type="library" exported="" name="design-23.1.0" level="project" />
|
||||||
<orderEntry type="library" exported="" name="appcompat-v7-23.1.0" level="project" />
|
<orderEntry type="library" exported="" name="appcompat-v7-23.1.0" level="project" />
|
||||||
|
|
|
@ -8,13 +8,21 @@
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/AppTheme" >
|
android:theme="@style/AppTheme" >
|
||||||
<activity
|
<!--<activity
|
||||||
android:name=".view.MainMenu"
|
android:name=".MainMenu"
|
||||||
|
android:label="@string/app_name"
|
||||||
|
android:theme="@style/AppTheme.NoActionBar" >
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
|
</intent-filter>
|
||||||
|
</activity>-->
|
||||||
|
<activity
|
||||||
|
android:name=".GameView"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:theme="@style/AppTheme.NoActionBar" >
|
android:theme="@style/AppTheme.NoActionBar" >
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package tu_darmstadt.sudoku.controller;
|
package tu_darmstadt.sudoku.controller;
|
||||||
|
|
||||||
import tu_darmstadt.sudoku.game.*;
|
import tu_darmstadt.sudoku.game.*;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
@ -11,22 +13,47 @@ public class GameController {
|
||||||
|
|
||||||
private int size;
|
private int size;
|
||||||
private GameField gameField;
|
private GameField gameField;
|
||||||
private List<CheckError> errorList = new ArrayList<CheckError>();
|
private ArrayList<CheckError> errorList = new ArrayList<CheckError>();
|
||||||
|
private GameSettings settings = new GameSettings();
|
||||||
|
|
||||||
// private SudokuSolver solver;
|
// private SudokuSolver solver;
|
||||||
// private SudokuGenerator generator;
|
// private SudokuGenerator generator;
|
||||||
|
|
||||||
|
public GameController() {
|
||||||
public GameController(int size) {
|
this(GameType.Default_9x9);
|
||||||
this.size = size;
|
|
||||||
gameField = new GameField(size);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setValue(int row, int col, int val) {
|
public GameController(GameType type) {
|
||||||
|
gameField = new GameField(type);
|
||||||
|
size = gameField.getSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*public boolean loadLevel(GameField level) {
|
||||||
|
if(GameField.isValid(level)) {
|
||||||
|
gameField = level;
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
|
public void setValue(int row, int col, int value) {
|
||||||
GameCell cell = gameField.getCell(row, col);
|
GameCell cell = gameField.getCell(row, col);
|
||||||
if (!cell.isFixed() && isValidNumber(val)) {
|
if (!cell.isFixed() && isValidNumber(value)) {
|
||||||
cell.clearNotes();
|
cell.deleteNotes();
|
||||||
cell.setValue(val);
|
cell.setValue(value);
|
||||||
|
|
||||||
|
if(settings.getEnableAutomaticNoteDeletion()) {
|
||||||
|
LinkedList<GameCell> updateList = new LinkedList<GameCell>();
|
||||||
|
updateList.addAll(gameField.getRow(cell.getRow()));
|
||||||
|
updateList.addAll(gameField.getColumn(cell.getCol()));
|
||||||
|
updateList.addAll(gameField.getSection(cell.getRow(), cell.getCol()));
|
||||||
|
deleteNote(updateList, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteNote(List<GameCell> updateList, int value) {
|
||||||
|
for(GameCell c : updateList) {
|
||||||
|
c.deleteNote(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,42 +78,84 @@ public class GameController {
|
||||||
|
|
||||||
public boolean isSolved() {
|
public boolean isSolved() {
|
||||||
boolean solved = true;
|
boolean solved = true;
|
||||||
/*
|
|
||||||
|
// this will automatically build the CheckError list. so we reset it before we call the checks
|
||||||
|
errorList = new ArrayList<CheckError>();
|
||||||
|
|
||||||
for(int i = 0; i < size; i++) {
|
for(int i = 0; i < size; i++) {
|
||||||
|
if(!checkList(gameField.getRow(i))) solved = false;
|
||||||
List<Integer> set = new ArrayList<Integer>();
|
|
||||||
for(int j = 0; j < size; j++) {
|
|
||||||
if(set.contains(gameField.getField()[i][j].getValue())) {
|
|
||||||
errorList.add(new CheckError(i,j,));
|
|
||||||
} else {
|
|
||||||
set.add(gameField.getField()[i][j].getValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!checkList() solved = false;
|
|
||||||
if(!checkList(gameField.getColumn(i))) solved = false;
|
if(!checkList(gameField.getColumn(i))) solved = false;
|
||||||
if(!checkList(gameField.getSection(i))) solved = false;
|
if(!checkList(gameField.getSection(i))) solved = false;
|
||||||
}*/
|
}
|
||||||
return solved;
|
return solved;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks the given list if every number occurs only once.
|
* Checks the given list if every number occurs only once.
|
||||||
|
* This method will automatically build the errorList.
|
||||||
* @param list the list of {@link GameCell}s that is supposed to be tested.
|
* @param list the list of {@link GameCell}s that is supposed to be tested.
|
||||||
* @return true if every cell has a value and every value occurs only once
|
* @return true if every cell has a value and every value occurs only once
|
||||||
*/
|
*/
|
||||||
private boolean checkList(GameCell[] list) {
|
private boolean checkList(List<GameCell> list) {
|
||||||
/*List<Integer> set = new ArrayList<Integer>();
|
boolean isNothingEmpty = true;
|
||||||
for(GameCell c : list) {
|
CheckError lastFound = null;
|
||||||
if(set.contains(c.getValue())) {
|
|
||||||
|
|
||||||
errorList.add(new CheckError());
|
for(int i = 0; i < list.size(); i++) {
|
||||||
|
for(int j = i + 1; j < list.size(); j++) {
|
||||||
|
GameCell c1 = list.get(i);
|
||||||
|
GameCell c2 = list.get(j);
|
||||||
|
|
||||||
|
if(c1.getValue() == 0 || c2.getValue() == 0) {
|
||||||
|
isNothingEmpty = false;
|
||||||
}
|
}
|
||||||
}*/
|
|
||||||
return false;
|
// Same value in one set should not exist
|
||||||
|
if(c1.getValue() != 0 && c1.getValue() == c2.getValue()) {
|
||||||
|
// we found an error..
|
||||||
|
|
||||||
|
LinkedList<CheckError> removeList = new LinkedList<CheckError>();
|
||||||
|
|
||||||
|
// check if one of the cells is already in conflict with something else
|
||||||
|
if(errorList.size() == 0) {
|
||||||
|
lastFound = new CheckError(c1, c2);
|
||||||
|
errorList.add(lastFound);
|
||||||
|
}
|
||||||
|
for(CheckError ce : errorList) {
|
||||||
|
if(ce.contains(c1) || ce.contains(c2)) {
|
||||||
|
ce.add(c1);
|
||||||
|
ce.add(c2);
|
||||||
|
|
||||||
|
if(lastFound != null && !lastFound.equals(ce)) {
|
||||||
|
lastFound.merge(ce);
|
||||||
|
removeList.add(ce);
|
||||||
|
} else {
|
||||||
|
lastFound = ce;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
lastFound = new CheckError(c1, c2);
|
||||||
|
errorList.add(lastFound);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove the empty errors, that have been merged.
|
||||||
|
for(CheckError ce : removeList) {
|
||||||
|
errorList.remove(ce);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return isNothingEmpty ? (errorList.size() == 0) : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<CheckError> getErrorList() {
|
public List<CheckError> getErrorList() {
|
||||||
return errorList;
|
return errorList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Debug only method
|
||||||
|
*
|
||||||
|
* @return the Field represented as a String
|
||||||
|
*/
|
||||||
|
public String getFieldAsString() {
|
||||||
|
return gameField.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,78 @@
|
||||||
package tu_darmstadt.sudoku.game;
|
package tu_darmstadt.sudoku.game;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Chris on 08.11.2015.
|
* Created by Chris on 08.11.2015.
|
||||||
*/
|
*/
|
||||||
public class CheckError {
|
public class CheckError {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* An Error is created for every cell.
|
||||||
|
*/
|
||||||
|
|
||||||
|
private int value = 0;
|
||||||
|
private LinkedList<GameCell> list = new LinkedList<GameCell>();
|
||||||
|
|
||||||
CheckError(GameCell first, GameCell... list) {
|
public CheckError(GameCell first, GameCell second) {
|
||||||
|
add(first);
|
||||||
|
add(second);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(GameCell cell) {
|
||||||
|
if(value == 0 && cell.getValue() != 0) {
|
||||||
|
value = cell.getValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!list.contains(cell)) {
|
||||||
|
list.add(cell);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean contains(GameCell c) {
|
||||||
|
return list.contains(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void merge(CheckError other) {
|
||||||
|
// merge the same object? ... why would you do that. This would simply clear the CheckError.
|
||||||
|
if(equals(other)) return;
|
||||||
|
|
||||||
|
for(GameCell c : other.list) {
|
||||||
|
if(!contains(c)) {
|
||||||
|
add(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Empty the other list.... because they are merged now.
|
||||||
|
other.list = new LinkedList<GameCell>();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object other) {
|
||||||
|
if(!(other instanceof CheckError)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(list.size() != ((CheckError) other).list.size()) return false;
|
||||||
|
|
||||||
|
for(int i = 0; i < list.size(); i++) {
|
||||||
|
if(!list.get(i).equals(((CheckError) other).list.get(i))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append("[CheckError: "); sb.append(value);
|
||||||
|
for(GameCell c : list) {
|
||||||
|
sb.append(" (");
|
||||||
|
sb.append(c.getRow());
|
||||||
|
sb.append("|");
|
||||||
|
sb.append(c.getCol());
|
||||||
|
sb.append(")");
|
||||||
|
}
|
||||||
|
sb.append("]");
|
||||||
|
return sb.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,8 @@ package tu_darmstadt.sudoku.game;
|
||||||
*/
|
*/
|
||||||
public class GameCell {
|
public class GameCell {
|
||||||
|
|
||||||
private int row = -1;
|
private int row = 0;
|
||||||
private int col = -1;
|
private int col = 0;
|
||||||
private int value = 0;
|
private int value = 0;
|
||||||
private boolean fixed = false;
|
private boolean fixed = false;
|
||||||
private boolean notes[];
|
private boolean notes[];
|
||||||
|
@ -24,14 +24,12 @@ public class GameCell {
|
||||||
this.row = row;
|
this.row = row;
|
||||||
this.col = col;
|
this.col = col;
|
||||||
this.size = size;
|
this.size = size;
|
||||||
clearNotes();
|
|
||||||
if(0 < val && val <= size) {
|
if(0 < val && val <= size) {
|
||||||
setValue(val);
|
setValue(val);
|
||||||
setFixed(true);
|
setFixed(true);
|
||||||
} else {
|
} else {
|
||||||
setValue(0);
|
setValue(0);
|
||||||
setFixed(false);
|
setFixed(false);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +38,7 @@ public class GameCell {
|
||||||
* @param val the value to be assigned to the cell.
|
* @param val the value to be assigned to the cell.
|
||||||
*/
|
*/
|
||||||
public void setValue(int val) {
|
public void setValue(int val) {
|
||||||
clearNotes();
|
deleteNotes();
|
||||||
value = val;
|
value = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,12 +58,21 @@ public class GameCell {
|
||||||
* Toggle notes in this cell, if cell isn't fixed.
|
* Toggle notes in this cell, if cell isn't fixed.
|
||||||
* @param val the value to be toggled.
|
* @param val the value to be toggled.
|
||||||
*/
|
*/
|
||||||
public void setNotes(int val) {
|
public void toggleNote(int val) {
|
||||||
// only possible to set notes if cell isn't fixed.
|
if(!isFixed())
|
||||||
// TODO .. put logic here?
|
|
||||||
notes[val - 1] = !notes[val - 1];
|
notes[val - 1] = !notes[val - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setNote(int val) {
|
||||||
|
if(!isFixed())
|
||||||
|
notes[val - 1] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteNote(int val) {
|
||||||
|
if(!isFixed())
|
||||||
|
notes[val - 1] = false;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean[] getNotes() {
|
public boolean[] getNotes() {
|
||||||
return notes;
|
return notes;
|
||||||
}
|
}
|
||||||
|
@ -73,7 +80,7 @@ public class GameCell {
|
||||||
/**
|
/**
|
||||||
* Clear the notes array (set everything to false).
|
* Clear the notes array (set everything to false).
|
||||||
*/
|
*/
|
||||||
public void clearNotes() {
|
public void deleteNotes() {
|
||||||
notes = new boolean[size];
|
notes = new boolean[size];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,7 +88,47 @@ public class GameCell {
|
||||||
return fixed;
|
return fixed;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFixed(boolean b) {
|
private void setFixed(boolean b) {
|
||||||
fixed = b;
|
fixed = b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object other) {
|
||||||
|
if(!(other instanceof GameCell)) return false;
|
||||||
|
if(((GameCell) other).getCol() != this.getCol()) return false;
|
||||||
|
if(((GameCell) other).getRow() != this.getRow()) return false;
|
||||||
|
if(((GameCell) other).isFixed() != this.isFixed()) return false;
|
||||||
|
if(((GameCell) other).getValue() != this.getValue()) return false;
|
||||||
|
if(((GameCell) other).getNotes().length != this.getNotes().length) return false;
|
||||||
|
for(int i = 0; i < notes.length; i++) {
|
||||||
|
if(((GameCell) other).getNotes()[i] != this.getNotes()[i]) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append("{("); sb.append(row); sb.append("|"); sb.append(col); sb.append(")");
|
||||||
|
sb.append(" ");
|
||||||
|
if(value == 0) {
|
||||||
|
sb.append("[");
|
||||||
|
boolean addedNotes = false;
|
||||||
|
for(int i = 0; i < size; i++) {
|
||||||
|
if(notes[i]) {
|
||||||
|
if(addedNotes) {
|
||||||
|
sb.append(" ,");
|
||||||
|
}
|
||||||
|
sb.append(i+1);
|
||||||
|
addedNotes = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sb.append("]");
|
||||||
|
} else {
|
||||||
|
sb.append(value);
|
||||||
|
}
|
||||||
|
sb.append("}");
|
||||||
|
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +1,27 @@
|
||||||
package tu_darmstadt.sudoku.game;
|
package tu_darmstadt.sudoku.game;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Chris on 06.11.2015.
|
* Created by Christopher Beckmann on 06.11.2015.
|
||||||
*/
|
*/
|
||||||
public class GameField {
|
public class GameField {
|
||||||
|
|
||||||
|
//private int id;
|
||||||
|
private int sectionHeight;
|
||||||
|
private int sectionWidth;
|
||||||
|
//private List additionalSections
|
||||||
private int size;
|
private int size;
|
||||||
private GameCell[][] field;
|
private GameCell[][] field;
|
||||||
|
|
||||||
public GameField() {
|
public GameField() {
|
||||||
this(9);
|
this(GameType.Default_9x9);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GameField(int size) {
|
public GameField(GameType type) {
|
||||||
this.size = size;
|
setGameType(type);
|
||||||
field = new GameCell[size][size];
|
|
||||||
|
|
||||||
|
field = new GameCell[size][size];
|
||||||
|
|
||||||
|
|
||||||
// TODO: this is a placeholder, because we don't have real levels yet.
|
// TODO: this is a placeholder, because we don't have real levels yet.
|
||||||
|
@ -34,6 +40,19 @@ public class GameField {
|
||||||
initCells(level);
|
initCells(level);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setGameType(GameType type) {
|
||||||
|
switch(type) {
|
||||||
|
case Default_9x9:
|
||||||
|
this.size = 9;
|
||||||
|
this.sectionHeight = 3;
|
||||||
|
this.sectionWidth = 3;
|
||||||
|
break;
|
||||||
|
case Unspecified:
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException("GameType can not be unspecified.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void initCells(int[][] level) {
|
public void initCells(int[][] level) {
|
||||||
// Initit the game field
|
// Initit the game field
|
||||||
for(int i = 0; i < size; i++) {
|
for(int i = 0; i < size; i++) {
|
||||||
|
@ -51,31 +70,34 @@ public class GameField {
|
||||||
return field;
|
return field;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GameCell[] getRow(int row) {
|
public LinkedList<GameCell> getRow(int row) {
|
||||||
return field[row];
|
LinkedList<GameCell> result = new LinkedList<GameCell>();
|
||||||
|
for(GameCell c : field[row]) {
|
||||||
|
result.add(c);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GameCell[] getColumn(int col) {
|
public LinkedList<GameCell> getColumn(int col) {
|
||||||
GameCell[] result = new GameCell[size];
|
LinkedList<GameCell> result = new LinkedList<GameCell>();
|
||||||
for(int i = 0; i < size ; i++) { // row
|
for(int i = 0; i < size ; i++) { // row
|
||||||
for(int j = 0 ; j < size ; j++) { // col
|
for(int j = 0 ; j < size ; j++) { // col
|
||||||
if(j == col) {
|
if(j == col) {
|
||||||
result[i] = field[i][j];
|
result.add(field[i][j]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GameCell[] getSection(int sec) {
|
public LinkedList<GameCell> getSection(int sec) {
|
||||||
GameCell[] result = new GameCell[size];
|
LinkedList<GameCell> result = new LinkedList<GameCell>();
|
||||||
int c = 0;
|
|
||||||
for(int i = 0; i < size ; i++) { // row
|
for(int i = 0; i < size ; i++) { // row
|
||||||
for(int j = 0 ; j < size ; j++) { // col
|
for(int j = 0 ; j < size ; j++) { // col
|
||||||
if(Math.floor(i/3)*3 + Math.floor(j/3) == sec) {
|
if((int)(Math.floor(i/sectionHeight)*sectionHeight + Math.floor(j/sectionWidth)) == sec) {
|
||||||
result[c++] = field[i][j];
|
result.add(field[i][j]);
|
||||||
}
|
}
|
||||||
if(c > size) {
|
if(result.size() >= sectionHeight*sectionWidth) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,10 +105,34 @@ public class GameField {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public LinkedList<GameCell> getSection(int row, int col) {
|
||||||
|
int sec = (int) (Math.floor(row / sectionHeight) * sectionHeight + Math.floor(col / sectionWidth));
|
||||||
|
return getSection(sec);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSize() {
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
|
sb.append("GameField: "); sb.append("\n");
|
||||||
|
|
||||||
|
for(int i = 0; i < size; i++) {
|
||||||
|
|
||||||
|
for(int j = 0; j < size; j++) {
|
||||||
|
if(j % sectionWidth == 0) {
|
||||||
|
sb.append("\t");
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.append(getField()[i][j]);
|
||||||
|
sb.append(" ");
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.append("\n");
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
12
app/src/main/java/tu_darmstadt/sudoku/game/GameSettings.java
Normal file
12
app/src/main/java/tu_darmstadt/sudoku/game/GameSettings.java
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
package tu_darmstadt.sudoku.game;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Chris on 09.11.2015.
|
||||||
|
*/
|
||||||
|
public class GameSettings {
|
||||||
|
private boolean enableAutomaticNoteDeletion = true;
|
||||||
|
|
||||||
|
public boolean getEnableAutomaticNoteDeletion() {
|
||||||
|
return enableAutomaticNoteDeletion;
|
||||||
|
}
|
||||||
|
}
|
11
app/src/main/java/tu_darmstadt/sudoku/game/GameStatus.java
Normal file
11
app/src/main/java/tu_darmstadt/sudoku/game/GameStatus.java
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
package tu_darmstadt.sudoku.game;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Chris on 10.11.2015.
|
||||||
|
*/
|
||||||
|
public enum GameStatus {
|
||||||
|
Unspecified,
|
||||||
|
Running,
|
||||||
|
Paused,
|
||||||
|
|
||||||
|
}
|
10
app/src/main/java/tu_darmstadt/sudoku/game/GameType.java
Normal file
10
app/src/main/java/tu_darmstadt/sudoku/game/GameType.java
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
package tu_darmstadt.sudoku.game;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Chris on 09.11.2015.
|
||||||
|
*/
|
||||||
|
public enum GameType {
|
||||||
|
Unspecified,
|
||||||
|
Default_9x9
|
||||||
|
|
||||||
|
}
|
108
app/src/main/java/tu_darmstadt/sudoku/view/GameView.java
Normal file
108
app/src/main/java/tu_darmstadt/sudoku/view/GameView.java
Normal file
|
@ -0,0 +1,108 @@
|
||||||
|
package tu_darmstadt.sudoku.view;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.design.widget.FloatingActionButton;
|
||||||
|
import android.support.design.widget.Snackbar;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.View;
|
||||||
|
import android.support.design.widget.NavigationView;
|
||||||
|
import android.support.v4.view.GravityCompat;
|
||||||
|
import android.support.v4.widget.DrawerLayout;
|
||||||
|
import android.support.v7.app.ActionBarDrawerToggle;
|
||||||
|
import android.support.v7.app.AppCompatActivity;
|
||||||
|
import android.support.v7.widget.Toolbar;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.MenuItem;
|
||||||
|
import tu_darmstadt.sudoku.controller.GameController;
|
||||||
|
import tu_darmstadt.sudoku.game.*;
|
||||||
|
|
||||||
|
public class GameView extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
|
||||||
|
|
||||||
|
GameController gameController = new GameController(GameType.Default_9x9);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_game_view);
|
||||||
|
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||||
|
setSupportActionBar(toolbar);
|
||||||
|
|
||||||
|
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
|
||||||
|
fab.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
/* DEBUG */
|
||||||
|
String debug = gameController.getFieldAsString();
|
||||||
|
Log.d("Sudoku", debug);
|
||||||
|
|
||||||
|
Snackbar.make(view, "Printed example Sudoku board in console.", Snackbar.LENGTH_LONG).setAction("Action", null).show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
|
||||||
|
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
|
||||||
|
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
|
||||||
|
drawer.setDrawerListener(toggle);
|
||||||
|
toggle.syncState();
|
||||||
|
|
||||||
|
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
|
||||||
|
navigationView.setNavigationItemSelectedListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBackPressed() {
|
||||||
|
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
|
||||||
|
if (drawer.isDrawerOpen(GravityCompat.START)) {
|
||||||
|
drawer.closeDrawer(GravityCompat.START);
|
||||||
|
} else {
|
||||||
|
super.onBackPressed();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
|
// Inflate the menu; this adds items to the action bar if it is present.
|
||||||
|
getMenuInflater().inflate(R.menu.game_view, menu);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
|
// Handle action bar item clicks here. The action bar will
|
||||||
|
// automatically handle clicks on the Home/Up button, so long
|
||||||
|
// as you specify a parent activity in AndroidManifest.xml.
|
||||||
|
int id = item.getItemId();
|
||||||
|
|
||||||
|
//noinspection SimplifiableIfStatement
|
||||||
|
if (id == R.id.action_settings) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("StatementWithEmptyBody")
|
||||||
|
@Override
|
||||||
|
public boolean onNavigationItemSelected(MenuItem item) {
|
||||||
|
// Handle navigation view item clicks here.
|
||||||
|
int id = item.getItemId();
|
||||||
|
|
||||||
|
if (id == R.id.nav_camara) {
|
||||||
|
// Handle the camera action
|
||||||
|
} else if (id == R.id.nav_gallery) {
|
||||||
|
|
||||||
|
} else if (id == R.id.nav_slideshow) {
|
||||||
|
|
||||||
|
} else if (id == R.id.nav_manage) {
|
||||||
|
|
||||||
|
} else if (id == R.id.nav_share) {
|
||||||
|
|
||||||
|
} else if (id == R.id.nav_send) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
|
||||||
|
drawer.closeDrawer(GravityCompat.START);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
|
@ -15,8 +15,8 @@ public class MainMenu extends AppCompatActivity {
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_main_menu);
|
setContentView(R.layout.activity_main_menu);
|
||||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
//Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||||
setSupportActionBar(toolbar);
|
//setSupportActionBar(toolbar);
|
||||||
|
|
||||||
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
|
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
|
||||||
fab.setOnClickListener(new View.OnClickListener() {
|
fab.setOnClickListener(new View.OnClickListener() {
|
||||||
|
|
9
app/src/main/res/drawable/side_nav_bar.xml
Normal file
9
app/src/main/res/drawable/side_nav_bar.xml
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:shape="rectangle" >
|
||||||
|
<gradient
|
||||||
|
android:startColor="#81C784"
|
||||||
|
android:centerColor="#4CAF50"
|
||||||
|
android:endColor="#2E7D32"
|
||||||
|
android:type="linear"
|
||||||
|
android:angle="135"/>
|
||||||
|
</shape>
|
17
app/src/main/res/layout/activity_game_view.xml
Normal file
17
app/src/main/res/layout/activity_game_view.xml
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools" android:id="@+id/drawer_layout"
|
||||||
|
android:layout_width="match_parent" android:layout_height="match_parent"
|
||||||
|
android:fitsSystemWindows="true" tools:openDrawer="start">
|
||||||
|
|
||||||
|
<include layout="@layout/app_bar_game_view" android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent" />
|
||||||
|
|
||||||
|
<android.support.design.widget.NavigationView android:id="@+id/nav_view"
|
||||||
|
android:layout_width="wrap_content" android:layout_height="match_parent"
|
||||||
|
android:layout_gravity="start" android:fitsSystemWindows="true"
|
||||||
|
app:headerLayout="@layout/nav_header_game_view"
|
||||||
|
app:menu="@menu/activity_game_view_drawer" />
|
||||||
|
|
||||||
|
</android.support.v4.widget.DrawerLayout>
|
|
@ -8,10 +8,6 @@
|
||||||
<android.support.design.widget.AppBarLayout android:layout_height="wrap_content"
|
<android.support.design.widget.AppBarLayout android:layout_height="wrap_content"
|
||||||
android:layout_width="match_parent" android:theme="@style/AppTheme.AppBarOverlay">
|
android:layout_width="match_parent" android:theme="@style/AppTheme.AppBarOverlay">
|
||||||
|
|
||||||
<android.support.v7.widget.Toolbar android:id="@+id/toolbar"
|
|
||||||
android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"
|
|
||||||
android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay" />
|
|
||||||
|
|
||||||
</android.support.design.widget.AppBarLayout>
|
</android.support.design.widget.AppBarLayout>
|
||||||
|
|
||||||
<include layout="@layout/content_main_menu" />
|
<include layout="@layout/content_main_menu" />
|
||||||
|
|
25
app/src/main/res/layout/app_bar_game_view.xml
Normal file
25
app/src/main/res/layout/app_bar_game_view.xml
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<android.support.design.widget.CoordinatorLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent" android:fitsSystemWindows="true"
|
||||||
|
tools:context="tu_darmstadt.sudoku.view.GameView">
|
||||||
|
|
||||||
|
<android.support.design.widget.AppBarLayout android:layout_height="wrap_content"
|
||||||
|
android:layout_width="match_parent" android:theme="@style/AppTheme.AppBarOverlay">
|
||||||
|
|
||||||
|
<android.support.v7.widget.Toolbar android:id="@+id/toolbar"
|
||||||
|
android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"
|
||||||
|
android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay" />
|
||||||
|
|
||||||
|
</android.support.design.widget.AppBarLayout>
|
||||||
|
|
||||||
|
<include layout="@layout/content_game_view" />
|
||||||
|
|
||||||
|
<android.support.design.widget.FloatingActionButton android:id="@+id/fab"
|
||||||
|
android:layout_width="wrap_content" android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="bottom|end" android:layout_margin="@dimen/fab_margin"
|
||||||
|
android:src="@android:drawable/ic_dialog_email" />
|
||||||
|
|
||||||
|
</android.support.design.widget.CoordinatorLayout>
|
12
app/src/main/res/layout/content_game_view.xml
Normal file
12
app/src/main/res/layout/content_game_view.xml
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||||
|
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||||
|
android:paddingTop="@dimen/activity_vertical_margin"
|
||||||
|
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||||
|
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
||||||
|
tools:showIn="@layout/app_bar_game_view" tools:context="tu_darmstadt.sudoku.view.GameView">
|
||||||
|
|
||||||
|
</RelativeLayout>
|
23
app/src/main/res/layout/nav_header_game_view.xml
Normal file
23
app/src/main/res/layout/nav_header_game_view.xml
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent" android:layout_height="@dimen/nav_header_height"
|
||||||
|
android:background="@drawable/side_nav_bar"
|
||||||
|
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||||
|
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||||
|
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||||
|
android:paddingTop="@dimen/activity_vertical_margin"
|
||||||
|
android:theme="@style/ThemeOverlay.AppCompat.Dark" android:orientation="vertical"
|
||||||
|
android:gravity="bottom">
|
||||||
|
|
||||||
|
<ImageView android:layout_width="wrap_content" android:layout_height="wrap_content"
|
||||||
|
android:paddingTop="@dimen/nav_header_vertical_spacing"
|
||||||
|
android:src="@android:drawable/sym_def_app_icon" android:id="@+id/imageView" />
|
||||||
|
|
||||||
|
<TextView android:layout_width="match_parent" android:layout_height="wrap_content"
|
||||||
|
android:paddingTop="@dimen/nav_header_vertical_spacing" android:text="Android Studio"
|
||||||
|
android:textAppearance="@style/TextAppearance.AppCompat.Body1" />
|
||||||
|
|
||||||
|
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
|
||||||
|
android:text="android.studio@android.com" android:id="@+id/textView" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
24
app/src/main/res/menu/activity_game_view_drawer.xml
Normal file
24
app/src/main/res/menu/activity_game_view_drawer.xml
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
|
<group android:checkableBehavior="single">
|
||||||
|
<item android:id="@+id/nav_camara" android:icon="@android:drawable/ic_menu_camera"
|
||||||
|
android:title="Import" />
|
||||||
|
<item android:id="@+id/nav_gallery" android:icon="@android:drawable/ic_menu_gallery"
|
||||||
|
android:title="Gallery" />
|
||||||
|
<item android:id="@+id/nav_slideshow" android:icon="@android:drawable/ic_menu_slideshow"
|
||||||
|
android:title="Slideshow" />
|
||||||
|
<item android:id="@+id/nav_manage" android:icon="@android:drawable/ic_menu_manage"
|
||||||
|
android:title="Tools" />
|
||||||
|
</group>
|
||||||
|
|
||||||
|
<item android:title="Communicate">
|
||||||
|
<menu>
|
||||||
|
<item android:id="@+id/nav_share" android:icon="@android:drawable/ic_menu_share"
|
||||||
|
android:title="Share" />
|
||||||
|
<item android:id="@+id/nav_send" android:icon="@android:drawable/ic_menu_send"
|
||||||
|
android:title="Send" />
|
||||||
|
</menu>
|
||||||
|
</item>
|
||||||
|
|
||||||
|
</menu>
|
6
app/src/main/res/menu/game_view.xml
Normal file
6
app/src/main/res/menu/game_view.xml
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
<item android:id="@+id/action_settings" android:title="@string/action_settings"
|
||||||
|
android:orderInCategory="100" app:showAsAction="never" />
|
||||||
|
</menu>
|
|
@ -3,4 +3,7 @@
|
||||||
<dimen name="activity_horizontal_margin">16dp</dimen>
|
<dimen name="activity_horizontal_margin">16dp</dimen>
|
||||||
<dimen name="activity_vertical_margin">16dp</dimen>
|
<dimen name="activity_vertical_margin">16dp</dimen>
|
||||||
<dimen name="fab_margin">16dp</dimen>
|
<dimen name="fab_margin">16dp</dimen>
|
||||||
|
<!-- Default screen margins, per the Android Design guidelines. -->
|
||||||
|
<dimen name="nav_header_vertical_spacing">16dp</dimen>
|
||||||
|
<dimen name="nav_header_height">160dp</dimen>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">Sudoku</string>
|
<string name="app_name">Sudoku</string>
|
||||||
<string name="action_settings">Settings</string>
|
<string name="action_settings">Settings</string>
|
||||||
|
<string name="title_activity_game_view">GameView</string>
|
||||||
|
|
||||||
|
<string name="navigation_drawer_open">Open navigation drawer</string>
|
||||||
|
<string name="navigation_drawer_close">Close navigation drawer</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -0,0 +1,214 @@
|
||||||
|
package tu_darmstadt.sudoku.controller;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import tu_darmstadt.sudoku.game.GameType;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Chris on 10.11.2015.
|
||||||
|
*/
|
||||||
|
public class GameControllerTest {
|
||||||
|
|
||||||
|
GameController controller;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void init() {
|
||||||
|
controller = new GameController();
|
||||||
|
int[][] level = {{ 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 }};
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void setValueOfFixedCellTest() {
|
||||||
|
assertEquals(5, controller.getValue(0, 0));
|
||||||
|
controller.setValue(0, 0, 6);
|
||||||
|
assertEquals(5, controller.getValue(0, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void setValueOfFreeCellTest() {
|
||||||
|
assertEquals(0, controller.getValue(0, 1));
|
||||||
|
controller.setValue(0, 1, 6);
|
||||||
|
assertEquals(6, controller.getValue(0, 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void solveTest1() {
|
||||||
|
controller.setValue(0, 1, 8);
|
||||||
|
controller.setValue(0, 4, 2);
|
||||||
|
controller.setValue(0, 5, 6);
|
||||||
|
controller.setValue(0, 6, 7);
|
||||||
|
controller.setValue(0, 7, 3);
|
||||||
|
controller.setValue(0, 8, 4);
|
||||||
|
controller.setValue(1, 1, 6);
|
||||||
|
controller.setValue(1, 2, 7);
|
||||||
|
controller.setValue(1, 3, 1);
|
||||||
|
controller.setValue(1, 4, 3);
|
||||||
|
controller.setValue(1, 8, 8);
|
||||||
|
controller.setValue(2, 2, 4);
|
||||||
|
controller.setValue(2, 4, 8);
|
||||||
|
controller.setValue(2, 5, 5);
|
||||||
|
controller.setValue(2, 6, 1);
|
||||||
|
controller.setValue(3, 0, 9);
|
||||||
|
controller.setValue(3, 2, 5);
|
||||||
|
controller.setValue(3, 3, 8);
|
||||||
|
controller.setValue(3, 4, 4);
|
||||||
|
controller.setValue(3, 6, 6);
|
||||||
|
controller.setValue(4, 0, 4);
|
||||||
|
controller.setValue(4, 1, 1);
|
||||||
|
controller.setValue(4, 3, 2);
|
||||||
|
controller.setValue(4, 6, 8);
|
||||||
|
controller.setValue(4, 7, 9);
|
||||||
|
controller.setValue(4, 8, 3);
|
||||||
|
controller.setValue(5, 0, 8);
|
||||||
|
controller.setValue(5, 3, 3);
|
||||||
|
controller.setValue(5, 4, 6);
|
||||||
|
controller.setValue(5, 6, 5);
|
||||||
|
controller.setValue(6, 0, 1);
|
||||||
|
controller.setValue(6, 1, 5);
|
||||||
|
controller.setValue(6, 2, 3);
|
||||||
|
controller.setValue(6, 3, 6);
|
||||||
|
controller.setValue(6, 5, 2);
|
||||||
|
controller.setValue(6, 7, 8);
|
||||||
|
controller.setValue(7, 2, 8);
|
||||||
|
controller.setValue(7, 3, 5);
|
||||||
|
controller.setValue(7, 4, 9);
|
||||||
|
controller.setValue(7, 5, 3);
|
||||||
|
controller.setValue(7, 6, 2);
|
||||||
|
controller.setValue(7, 7, 1);
|
||||||
|
controller.setValue(7, 8, 7);
|
||||||
|
controller.setValue(8, 1, 2);
|
||||||
|
controller.setValue(8, 2, 9);
|
||||||
|
controller.setValue(8, 3, 4);
|
||||||
|
controller.setValue(8, 5, 8);
|
||||||
|
controller.setValue(8, 7, 6);
|
||||||
|
|
||||||
|
assertTrue(controller.isSolved());
|
||||||
|
assertEquals(0, controller.getErrorList().size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void solveTest2() {
|
||||||
|
|
||||||
|
controller.setValue(0, 1, 8);
|
||||||
|
controller.setValue(0, 4, 2);
|
||||||
|
controller.setValue(0, 5, 6);
|
||||||
|
controller.setValue(0, 6, 7);
|
||||||
|
controller.setValue(0, 7, 3);
|
||||||
|
controller.setValue(0, 8, 4);
|
||||||
|
controller.setValue(1, 1, 6);
|
||||||
|
controller.setValue(1, 2, 7);
|
||||||
|
controller.setValue(1, 3, 1);
|
||||||
|
controller.setValue(1, 4, 3);
|
||||||
|
controller.setValue(1, 8, 8);
|
||||||
|
controller.setValue(2, 2, 4);
|
||||||
|
controller.setValue(2, 4, 8);
|
||||||
|
controller.setValue(2, 5, 5);
|
||||||
|
controller.setValue(2, 6, 1);
|
||||||
|
controller.setValue(3, 0, 9);
|
||||||
|
controller.setValue(3, 2, 5);
|
||||||
|
controller.setValue(3, 3, 8);
|
||||||
|
controller.setValue(3, 4, 4);
|
||||||
|
controller.setValue(3, 6, 6);
|
||||||
|
controller.setValue(4, 0, 4);
|
||||||
|
controller.setValue(4, 1, 1);
|
||||||
|
controller.setValue(4, 3, 2);
|
||||||
|
controller.setValue(4, 6, 8);
|
||||||
|
controller.setValue(4, 7, 9);
|
||||||
|
controller.setValue(4, 8, 3);
|
||||||
|
controller.setValue(5, 0, 8);
|
||||||
|
controller.setValue(5, 3, 3);
|
||||||
|
controller.setValue(5, 4, 6);
|
||||||
|
controller.setValue(5, 6, 5);
|
||||||
|
controller.setValue(6, 0, 1);
|
||||||
|
controller.setValue(6, 1, 5);
|
||||||
|
controller.setValue(6, 2, 3);
|
||||||
|
controller.setValue(6, 3, 1);
|
||||||
|
controller.setValue(6, 5, 2);
|
||||||
|
controller.setValue(6, 7, 8);
|
||||||
|
controller.setValue(7, 2, 8);
|
||||||
|
controller.setValue(7, 3, 5);
|
||||||
|
controller.setValue(7, 4, 9);
|
||||||
|
controller.setValue(7, 5, 3);
|
||||||
|
controller.setValue(7, 6, 2);
|
||||||
|
controller.setValue(7, 7, 1);
|
||||||
|
controller.setValue(7, 8, 7);
|
||||||
|
controller.setValue(8, 1, 2);
|
||||||
|
controller.setValue(8, 2, 9);
|
||||||
|
controller.setValue(8, 3, 4);
|
||||||
|
controller.setValue(8, 5, 8);
|
||||||
|
controller.setValue(8, 7, 6);
|
||||||
|
|
||||||
|
assertFalse(controller.isSolved());
|
||||||
|
assertEquals(1, controller.getErrorList().size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void solveTest3() {
|
||||||
|
controller.setValue(0, 4, 2);
|
||||||
|
controller.setValue(0, 5, 6);
|
||||||
|
controller.setValue(0, 6, 7);
|
||||||
|
controller.setValue(0, 7, 3);
|
||||||
|
controller.setValue(0, 8, 4);
|
||||||
|
controller.setValue(1, 1, 6);
|
||||||
|
controller.setValue(1, 2, 7);
|
||||||
|
controller.setValue(1, 3, 1);
|
||||||
|
controller.setValue(1, 4, 3);
|
||||||
|
controller.setValue(1, 8, 8);
|
||||||
|
controller.setValue(2, 2, 4);
|
||||||
|
controller.setValue(2, 4, 8);
|
||||||
|
controller.setValue(2, 5, 5);
|
||||||
|
controller.setValue(2, 6, 1);
|
||||||
|
controller.setValue(3, 0, 9);
|
||||||
|
controller.setValue(3, 2, 5);
|
||||||
|
controller.setValue(3, 3, 8);
|
||||||
|
controller.setValue(3, 4, 4);
|
||||||
|
controller.setValue(3, 6, 6);
|
||||||
|
controller.setValue(4, 0, 4);
|
||||||
|
controller.setValue(4, 1, 1);
|
||||||
|
controller.setValue(4, 3, 2);
|
||||||
|
controller.setValue(4, 6, 8);
|
||||||
|
controller.setValue(4, 7, 9);
|
||||||
|
controller.setValue(4, 8, 3);
|
||||||
|
controller.setValue(5, 0, 8);
|
||||||
|
controller.setValue(5, 3, 3);
|
||||||
|
controller.setValue(5, 4, 6);
|
||||||
|
controller.setValue(5, 6, 5);
|
||||||
|
controller.setValue(6, 0, 1);
|
||||||
|
controller.setValue(6, 1, 5);
|
||||||
|
controller.setValue(6, 2, 3);
|
||||||
|
controller.setValue(6, 5, 2);
|
||||||
|
controller.setValue(6, 7, 8);
|
||||||
|
controller.setValue(7, 2, 8);
|
||||||
|
controller.setValue(7, 3, 5);
|
||||||
|
controller.setValue(7, 4, 9);
|
||||||
|
controller.setValue(7, 5, 3);
|
||||||
|
controller.setValue(7, 6, 2);
|
||||||
|
controller.setValue(7, 7, 1);
|
||||||
|
controller.setValue(7, 8, 7);
|
||||||
|
controller.setValue(8, 1, 2);
|
||||||
|
controller.setValue(8, 2, 9);
|
||||||
|
controller.setValue(8, 3, 4);
|
||||||
|
controller.setValue(8, 5, 8);
|
||||||
|
controller.setValue(8, 7, 6);
|
||||||
|
|
||||||
|
assertFalse(controller.isSolved());
|
||||||
|
assertEquals(0, controller.getErrorList().size());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue