commit b4a651a3321b04c37d8271950574db1d778d78c8 Author: Christopher Beckmann Date: Mon Nov 9 12:41:46 2015 +0100 First Commit. Adding some Source code. diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9c4de58 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +.gradle +/local.properties +/.idea/workspace.xml +/.idea/libraries +.DS_Store +/build +/captures diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..bb144c1 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +Sudoku \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..96cc43e --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000..e7bedf3 --- /dev/null +++ b/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..97626ba --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..5f8ec24 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,19 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..5d19981 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..7bcd847 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..7f68460 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..6564d52 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Sudoku.iml b/Sudoku.iml new file mode 100644 index 0000000..95bbf83 --- /dev/null +++ b/Sudoku.iml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/app/app.iml b/app/app.iml new file mode 100644 index 0000000..75b2ddb --- /dev/null +++ b/app/app.iml @@ -0,0 +1,112 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..ff4a23d --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,27 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 23 + buildToolsVersion "23.0.2" + + defaultConfig { + applicationId "tu_darmstadt.sudoku" + minSdkVersion 14 + targetSdkVersion 23 + versionCode 1 + versionName "1.0" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + testCompile 'junit:junit:4.12' + compile 'com.android.support:appcompat-v7:23.1.0' + compile 'com.android.support:design:23.1.0' +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..aae9255 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in C:\Users\Chris\AppData\Local\Android\sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/app/src/androidTest/java/tu_darmstadt/sudoku/view/ApplicationTest.java b/app/src/androidTest/java/tu_darmstadt/sudoku/view/ApplicationTest.java new file mode 100644 index 0000000..03dfa6e --- /dev/null +++ b/app/src/androidTest/java/tu_darmstadt/sudoku/view/ApplicationTest.java @@ -0,0 +1,13 @@ +package tu_darmstadt.sudoku.view; + +import android.app.Application; +import android.test.ApplicationTestCase; + +/** + * Testing Fundamentals + */ +public class ApplicationTest extends ApplicationTestCase { + public ApplicationTest() { + super(Application.class); + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..4a98da3 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + diff --git a/app/src/main/java/tu_darmstadt/sudoku/controller/GameController.java b/app/src/main/java/tu_darmstadt/sudoku/controller/GameController.java new file mode 100644 index 0000000..8aea071 --- /dev/null +++ b/app/src/main/java/tu_darmstadt/sudoku/controller/GameController.java @@ -0,0 +1,92 @@ +package tu_darmstadt.sudoku.controller; + +import tu_darmstadt.sudoku.game.*; +import java.util.List; +import java.util.ArrayList; + +/** + * Created by Chris on 06.11.2015. + */ +public class GameController { + + private int size; + private GameField gameField; + private List errorList = new ArrayList(); + +// private SudokuSolver solver; +// private SudokuGenerator generator; + + + public GameController(int size) { + this.size = size; + gameField = new GameField(size); + } + + public void setValue(int row, int col, int val) { + GameCell cell = gameField.getCell(row, col); + if (!cell.isFixed() && isValidNumber(val)) { + cell.clearNotes(); + cell.setValue(val); + } + } + + public int getValue(int row, int col) { + GameCell cell = gameField.getCell(row, col); + return cell.getValue(); + } + + public int getSize() { + return size; + } + + /** + * Test if the given parameter is a number from 1 to {code size}. + * @param val the value to be checked. + * @return true, if {@code val} is a number from 1 to {code size}. + * @see GameController#getSize() + */ + public boolean isValidNumber(int val) { + return 0 < val && val <= size; + } + + public boolean isSolved() { + boolean solved = true; + + for(int i = 0; i < size; i++) { + + List set = new ArrayList(); + 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.getSection(i))) solved = false; + } + return solved; + } + + /** + * Checks the given list if every number occurs only once. + * @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 + */ + private boolean checkList(GameCell[] list) { + List set = new ArrayList(); + for(GameCell c : list) { + if(set.contains(c.getValue())) { + + errorList.add(new CheckError()); + } + } + return false; + } + + public List getErrorList() { + return errorList; + } +} diff --git a/app/src/main/java/tu_darmstadt/sudoku/game/CheckError.java b/app/src/main/java/tu_darmstadt/sudoku/game/CheckError.java new file mode 100644 index 0000000..61c18e7 --- /dev/null +++ b/app/src/main/java/tu_darmstadt/sudoku/game/CheckError.java @@ -0,0 +1,13 @@ +package tu_darmstadt.sudoku.game; + +/** + * Created by Chris on 08.11.2015. + */ +public class CheckError { + + + + CheckError(GameCell first, GameCell... list) { + + } +} diff --git a/app/src/main/java/tu_darmstadt/sudoku/game/CheckType.java b/app/src/main/java/tu_darmstadt/sudoku/game/CheckType.java new file mode 100644 index 0000000..3a9d196 --- /dev/null +++ b/app/src/main/java/tu_darmstadt/sudoku/game/CheckType.java @@ -0,0 +1,12 @@ +package tu_darmstadt.sudoku.game; + +/** + * Created by Chris on 08.11.2015. + */ +public enum CheckType { + UNSPECIFIED, + ROW, + COLUMN, + SECTION + +} diff --git a/app/src/main/java/tu_darmstadt/sudoku/game/GameCell.java b/app/src/main/java/tu_darmstadt/sudoku/game/GameCell.java new file mode 100644 index 0000000..48dd8f6 --- /dev/null +++ b/app/src/main/java/tu_darmstadt/sudoku/game/GameCell.java @@ -0,0 +1,87 @@ +package tu_darmstadt.sudoku.game; + +/** + * Created by Chris on 06.11.2015. + */ +public class GameCell { + + private int row = -1; + private int col = -1; + private int value = 0; + private boolean fixed = false; + private boolean notes[]; + private int size = 0; + + public GameCell(int row, int col, int size) { + this(row,col,size,0); + } + + /** + * Constructor with init parameter. The cell will have that value and be uneditable. + * @param val the start value to be saved in the cell + */ + public GameCell(int row, int col, int size, int val) { + this.row = row; + this.col = col; + this.size = size; + clearNotes(); + if(0 < val && val <= size) { + setValue(val); + setFixed(true); + } else { + setValue(0); + setFixed(false); + + } + } + + /** + * Set the value of the cell, only if cell isn't fixed. + * @param val the value to be assigned to the cell. + */ + public void setValue(int val) { + clearNotes(); + value = val; + } + + public int getValue() { + return value; + } + + public int getRow() { + return row; + } + + public int getCol() { + return col; + } + + /** + * Toggle notes in this cell, if cell isn't fixed. + * @param val the value to be toggled. + */ + public void setNotes(int val) { + // only possible to set notes if cell isn't fixed. + // TODO .. put logic here? + notes[val - 1] = !notes[val - 1]; + } + + public boolean[] getNotes() { + return notes; + } + + /** + * Clear the notes array (set everything to false). + */ + public void clearNotes() { + notes = new boolean[size]; + } + + public boolean isFixed() { + return fixed; + } + + public void setFixed(boolean b) { + fixed = b; + } +} diff --git a/app/src/main/java/tu_darmstadt/sudoku/game/GameField.java b/app/src/main/java/tu_darmstadt/sudoku/game/GameField.java new file mode 100644 index 0000000..196f396 --- /dev/null +++ b/app/src/main/java/tu_darmstadt/sudoku/game/GameField.java @@ -0,0 +1,92 @@ +package tu_darmstadt.sudoku.game; + +/** + * Created by Chris on 06.11.2015. + */ +public class GameField { + + private int size; + private GameCell[][] field; + + public GameField() { + this(9); + } + + public GameField(int size) { + this.size = size; + field = new GameCell[size][size]; + + + + // TODO: this is a placeholder, because we don't have real levels yet. + 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 }}; + + initCells(level); + } + + public void initCells(int[][] level) { + // Initit the game field + for(int i = 0; i < size; i++) { + for(int j = 0; j < size; j++) { + field[i][j] = new GameCell(i,j,size,level[i][j]); + } + } + } + + public GameCell getCell(int row, int col) { + return field[row][col]; + } + + public GameCell[][] getField() { + return field; + } + + public GameCell[] getRow(int row) { + return field[row]; + } + + public GameCell[] getColumn(int col) { + GameCell[] result = new GameCell[size]; + for(int i = 0; i < size ; i++) { // row + for(int j = 0 ; j < size ; j++) { // col + if(j == col) { + result[i] = field[i][j]; + } + } + } + return result; + } + + public GameCell[] getSection(int sec) { + GameCell[] result = new GameCell[size]; + int c = 0; + for(int i = 0; i < size ; i++) { // row + for(int j = 0 ; j < size ; j++) { // col + if(Math.floor(i/3)*3 + Math.floor(j/3) == sec) { + result[c++] = field[i][j]; + } + if(c > size) { + break; + } + } + } + return result; + } + + + + + + + +} diff --git a/app/src/main/java/tu_darmstadt/sudoku/view/MainMenu.java b/app/src/main/java/tu_darmstadt/sudoku/view/MainMenu.java new file mode 100644 index 0000000..3ffa23b --- /dev/null +++ b/app/src/main/java/tu_darmstadt/sudoku/view/MainMenu.java @@ -0,0 +1,52 @@ +package tu_darmstadt.sudoku.view; + +import android.os.Bundle; +import android.support.design.widget.FloatingActionButton; +import android.support.design.widget.Snackbar; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.Toolbar; +import android.view.View; +import android.view.Menu; +import android.view.MenuItem; + +public class MainMenu extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main_menu); + 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) { + Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) + .setAction("Action", null).show(); + } + }); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + // Inflate the menu; this adds items to the action bar if it is present. + getMenuInflater().inflate(R.menu.menu_main_menu, 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); + } +} diff --git a/app/src/main/res/layout/activity_main_menu.xml b/app/src/main/res/layout/activity_main_menu.xml new file mode 100644 index 0000000..08f76be --- /dev/null +++ b/app/src/main/res/layout/activity_main_menu.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/content_main_menu.xml b/app/src/main/res/layout/content_main_menu.xml new file mode 100644 index 0000000..7f0cbd7 --- /dev/null +++ b/app/src/main/res/layout/content_main_menu.xml @@ -0,0 +1,14 @@ + + + + + diff --git a/app/src/main/res/menu/menu_main_menu.xml b/app/src/main/res/menu/menu_main_menu.xml new file mode 100644 index 0000000..2b4455a --- /dev/null +++ b/app/src/main/res/menu/menu_main_menu.xml @@ -0,0 +1,6 @@ + + + diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher.png b/app/src/main/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 0000000..cde69bc Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher.png b/app/src/main/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 0000000..c133a0c Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/app/src/main/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 0000000..bfa42f0 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 0000000..324e72c Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png new file mode 100644 index 0000000..aee44e1 Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/app/src/main/res/values-v21/styles.xml b/app/src/main/res/values-v21/styles.xml new file mode 100644 index 0000000..65d0c39 --- /dev/null +++ b/app/src/main/res/values-v21/styles.xml @@ -0,0 +1,8 @@ +> + + diff --git a/app/src/main/res/values-w820dp/dimens.xml b/app/src/main/res/values-w820dp/dimens.xml new file mode 100644 index 0000000..63fc816 --- /dev/null +++ b/app/src/main/res/values-w820dp/dimens.xml @@ -0,0 +1,6 @@ + + + 64dp + diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml new file mode 100644 index 0000000..3ab3e9c --- /dev/null +++ b/app/src/main/res/values/colors.xml @@ -0,0 +1,6 @@ + + + #3F51B5 + #303F9F + #FF4081 + diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml new file mode 100644 index 0000000..812cb7b --- /dev/null +++ b/app/src/main/res/values/dimens.xml @@ -0,0 +1,6 @@ + + + 16dp + 16dp + 16dp + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml new file mode 100644 index 0000000..39f0926 --- /dev/null +++ b/app/src/main/res/values/strings.xml @@ -0,0 +1,4 @@ + + Sudoku + Settings + diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml new file mode 100644 index 0000000..44f664f --- /dev/null +++ b/app/src/main/res/values/styles.xml @@ -0,0 +1,17 @@ + + + + + +