diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index fc87649..1e1b5b5 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -8,13 +8,6 @@ android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme" > - - - - - - - - + + + + + + diff --git a/app/src/main/java/tu_darmstadt/sudoku/controller/FileManager.java b/app/src/main/java/tu_darmstadt/sudoku/controller/FileManager.java new file mode 100644 index 0000000..409503e --- /dev/null +++ b/app/src/main/java/tu_darmstadt/sudoku/controller/FileManager.java @@ -0,0 +1,17 @@ +package tu_darmstadt.sudoku.controller; + +import java.io.File; +/** + * Created by Chris on 16.11.2015. + */ +public class FileManager { + + FileManager() {} + + void doSomething() { + //File f = new File("./level/sudoku.txt"); + + + + } +} 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 7169a2a..1c4a668 100644 --- a/app/src/main/java/tu_darmstadt/sudoku/controller/GameController.java +++ b/app/src/main/java/tu_darmstadt/sudoku/controller/GameController.java @@ -49,18 +49,14 @@ public class GameController { 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); + case Default_6x6: + loadLevel(GameType.Default_6x6, + new int[]{1,0,0,0,0,6, + 4,0,6,1,0,0, + 0,0,2,3,0,5, + 0,4,0,0,1,0, + 0,6,0,2,0,0, + 0,3,0,5,0,1}, null,null); break; case Default_12x12: loadLevel(GameType.Default_12x12, @@ -78,6 +74,7 @@ public class GameController { 0, 6,10, 0, 0, 0, 8, 0, 0, 1,12, 0} ,null, null); break; + case Default_9x9: case Unspecified: default: loadLevel(GameType.Default_9x9, @@ -94,7 +91,7 @@ public class GameController { } } - public void loadLevel(GameType type, int[] fixedValues, int[] setValues, int[][] setNotes) { + public void loadLevel(GameType type, int[] fixedValues, int[] setValues, boolean[][] setNotes) { setGameType(type); this.gameBoard = new GameBoard(size, sectionHeight, sectionWidth); @@ -111,8 +108,17 @@ public class GameController { } } + // set notes. if(setNotes != null) { - // set notes. + for(int i = 0; i < size * size; i++) { + int row = (int) Math.floor(i / size); + int col = i % size; + for(int k = 0 ; k < size; k++) { + if(setNotes[i][k]) { + setNote(row, col, k); + } + } + } } } diff --git a/app/src/main/java/tu_darmstadt/sudoku/game/GameBoard.java b/app/src/main/java/tu_darmstadt/sudoku/game/GameBoard.java index 6d7f796..0052979 100644 --- a/app/src/main/java/tu_darmstadt/sudoku/game/GameBoard.java +++ b/app/src/main/java/tu_darmstadt/sudoku/game/GameBoard.java @@ -56,7 +56,7 @@ public class GameBoard implements Cloneable { 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."); + //if(count < 17) throw new IllegalArgumentException("There must be at least 17 fixed values."); } public GameCell getCell(int row, int col) { diff --git a/app/src/main/java/tu_darmstadt/sudoku/game/GameType.java b/app/src/main/java/tu_darmstadt/sudoku/game/GameType.java index c7c1bfc..5080f53 100644 --- a/app/src/main/java/tu_darmstadt/sudoku/game/GameType.java +++ b/app/src/main/java/tu_darmstadt/sudoku/game/GameType.java @@ -1,5 +1,8 @@ package tu_darmstadt.sudoku.game; +import java.util.LinkedList; +import java.util.List; + /** * Created by Chris on 09.11.2015. */ @@ -7,7 +10,15 @@ public enum GameType { Unspecified, Default_9x9, Default_12x12, - Default_6x6 + Default_6x6; + + public static List getValidGameTypes() { + LinkedList result = new LinkedList<>(); + result.add(Default_6x6); + result.add(Default_9x9); + result.add(Default_12x12); + return result; + } } diff --git a/app/src/main/java/tu_darmstadt/sudoku/ui/AboutActivity.java b/app/src/main/java/tu_darmstadt/sudoku/ui/AboutActivity.java index 757637c..2d6320f 100644 --- a/app/src/main/java/tu_darmstadt/sudoku/ui/AboutActivity.java +++ b/app/src/main/java/tu_darmstadt/sudoku/ui/AboutActivity.java @@ -16,7 +16,7 @@ public class AboutActivity extends AppCompatActivity { setContentView(R.layout.activity_about); android.support.v7.app.ActionBar actionBar = getSupportActionBar(); - actionBar.setTitle(R.string.about); + actionBar.setTitle(R.string.menu_about); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#024265"))); } 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 401e969..abce70e 100644 --- a/app/src/main/java/tu_darmstadt/sudoku/ui/GameActivity.java +++ b/app/src/main/java/tu_darmstadt/sudoku/ui/GameActivity.java @@ -11,9 +11,7 @@ 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 android.widget.GridLayout; import tu_darmstadt.sudoku.controller.GameController; import tu_darmstadt.sudoku.game.GameType; @@ -46,11 +44,22 @@ public class GameActivity extends AppCompatActivity implements NavigationView.On } + // TODO: DEBUG START + /*if(gameDifficulty == 0) { + gameType = GameType.Default_6x6; + } else if(gameDifficulty == 5) { + gameType = GameType.Default_12x12; + } else { + gameType = GameType.Default_9x9; + }*/ + // TODO: DEBUG END + SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); setContentView(R.layout.activity_game_view); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); + //toolbar.addView(); //Create new GameField layout = (SudokuFieldLayout)findViewById(R.id.sudokuLayout); @@ -65,7 +74,7 @@ public class GameActivity extends AppCompatActivity implements NavigationView.On keyboard = (SudokuKeyboardLayout) findViewById(R.id.sudokuKeyboardLayout); keyboard.removeAllViews(); keyboard.setGameController(gameController); - keyboard.setColumnCount(Math.max(((gameController.getSize() / 2) + 1),keyboard.fixedButtonsCount)); + keyboard.setColumnCount(Math.max(((gameController.getSize() / 2) + 1), keyboard.fixedButtonsCount)); keyboard.setRowCount(3); Point p = new Point(); getWindowManager().getDefaultDisplay().getSize(p); @@ -98,12 +107,12 @@ public class GameActivity extends AppCompatActivity implements NavigationView.On } } - @Override + /*@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; - } + }*/ @SuppressWarnings("StatementWithEmptyBody") @Override @@ -115,14 +124,14 @@ public class GameActivity extends AppCompatActivity implements NavigationView.On if (id == R.id.nav_newgame) { //create new game - intent = new Intent(this, NewGameActivity.class); - startActivity(intent); - - } else if (id == R.id.nav_mainmenu) { - //go to main menu intent = new Intent(this, MainActivity.class); startActivity(intent); + /*} else if (id == R.id.nav_mainmenu) { + //go to main menu + intent = new Intent(this, MainActivity.class); + startActivity(intent);*/ + } else if (id == R.id.nav_settings) { //open settings intent = new Intent(this,SettingsActivity.class); 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 9ec32c3..99812db 100644 --- a/app/src/main/java/tu_darmstadt/sudoku/ui/MainActivity.java +++ b/app/src/main/java/tu_darmstadt/sudoku/ui/MainActivity.java @@ -2,23 +2,181 @@ package tu_darmstadt.sudoku.ui; import android.content.Intent; import android.support.v7.app.AppCompatActivity; -import android.os.Bundle; -import android.view.View; +import android.support.v7.widget.Toolbar; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentPagerAdapter; +import android.support.v4.view.ViewPager; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.MenuItem; +import android.view.View; +import android.view.ViewGroup; + +import android.widget.Button; +import android.widget.RatingBar; +import android.widget.TextView; + +import tu_darmstadt.sudoku.game.GameType; import tu_darmstadt.sudoku.ui.view.R; public class MainActivity extends AppCompatActivity { + GameType gameType = GameType.Default_9x9; + int gameDifficulty = 1; + + /** + * The {@link android.support.v4.view.PagerAdapter} that will provide + * fragments for each of the sections. We use a + * {@link FragmentPagerAdapter} derivative, which will keep every + * loaded fragment in memory. If this becomes too memory intensive, it + * may be best to switch to a + * {@link android.support.v4.app.FragmentStatePagerAdapter}. + */ + private SectionsPagerAdapter mSectionsPagerAdapter; + + /** + * The {@link ViewPager} that will host the section contents. + */ + private ViewPager mViewPager; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); + setContentView(R.layout.activity_main_menu); + Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); + setSupportActionBar(toolbar); + // Create the adapter that will return a fragment for each of the three + // primary sections of the activity. + + mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); + + // Set up the ViewPager with the sections adapter. + mViewPager = (ViewPager) findViewById(R.id.scroller); + mViewPager.setAdapter(mSectionsPagerAdapter); + + mViewPager.setCurrentItem(1); + + Button continueButton = (Button)findViewById(R.id.continueButton); + continueButton.setEnabled(false); } - public void onClicktext(View view) { - Intent i = new Intent(this, NewGameActivity.class); + + public void onClick(View view) { + + Intent i = null; + + if(view instanceof Button) { + Button b = (Button)view; + switch(b.getId()) { + case R.id.aboutButton: + i = new Intent(this, AboutActivity.class); + break; + case R.id.continueButton: + // TODO continue from file. + i = new Intent(this, GameActivity.class); + int levelNr = 0; + i.putExtra("loadLevel", levelNr); + break; + case R.id.highscoreButton: + // TODO: create highscore screen + break; + case R.id.settingsButton: + i = new Intent(this, SettingsActivity.class); + break; + case R.id.helpButton: + // TODO: create help page.. what is supposed to be in there?! + break; + case R.id.playButton: + gameType = GameType.getValidGameTypes().get(mViewPager.getCurrentItem()); + RatingBar difficultyBar = (RatingBar)findViewById(R.id.difficultyBar); + gameDifficulty = difficultyBar.getProgress(); + + // send everything to game activity + i = new Intent(this, GameActivity.class); + i.putExtra("gameType", gameType); + i.putExtra("gameDifficulty", gameDifficulty); + break; + default: + i = getIntent(); + } + } + if(i == null) { + i = getIntent(); + } startActivity(i); } + @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(); + + return super.onOptionsItemSelected(item); + } + + + /** + * A {@link FragmentPagerAdapter} that returns a fragment corresponding to + * one of the sections/tabs/pages. + */ + public class SectionsPagerAdapter extends FragmentPagerAdapter { + + public SectionsPagerAdapter(FragmentManager fm) { + super(fm); + } + + @Override + public Fragment getItem(int position) { + // getItem is called to instantiate the fragment for the given page. + // Return a GameTypeFragment (defined as a static inner class below). + return GameTypeFragment.newInstance(position); + } + + @Override + public int getCount() { + // Show 3 total pages. + return GameType.getValidGameTypes().size(); + } + } + + /** + * A placeholder fragment containing a simple view. + */ + public static class GameTypeFragment extends Fragment { + /** + * The fragment argument representing the section number for this + * fragment. + */ + private static final String ARG_SECTION_NUMBER = "section_number"; + + /** + * Returns a new instance of this fragment for the given section + * number. + */ + public static GameTypeFragment newInstance(int sectionNumber) { + GameTypeFragment fragment = new GameTypeFragment(); + Bundle args = new Bundle(); + args.putInt(ARG_SECTION_NUMBER, sectionNumber); + fragment.setArguments(args); + return fragment; + } + + public GameTypeFragment() { + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View rootView = inflater.inflate(R.layout.fragment_main_menu, container, false); + + TextView textView = (TextView) rootView.findViewById(R.id.section_label); + textView.setText(GameType.getValidGameTypes().get(getArguments().getInt(ARG_SECTION_NUMBER)).name()); + return rootView; + } + } } diff --git a/app/src/main/java/tu_darmstadt/sudoku/ui/NewGameActivity.java b/app/src/main/java/tu_darmstadt/sudoku/ui/NewGameActivity.java deleted file mode 100644 index f7e98be..0000000 --- a/app/src/main/java/tu_darmstadt/sudoku/ui/NewGameActivity.java +++ /dev/null @@ -1,36 +0,0 @@ -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/SudokuButton.java b/app/src/main/java/tu_darmstadt/sudoku/ui/view/SudokuButton.java index ce6135a..9cb8c9e 100644 --- a/app/src/main/java/tu_darmstadt/sudoku/ui/view/SudokuButton.java +++ b/app/src/main/java/tu_darmstadt/sudoku/ui/view/SudokuButton.java @@ -3,6 +3,7 @@ package tu_darmstadt.sudoku.ui.view; import android.content.Context; import android.util.AttributeSet; import android.widget.Button; +import android.widget.ToggleButton; /** * Created by TMZ_LToP on 12.11.2015. diff --git a/app/src/main/java/tu_darmstadt/sudoku/ui/view/SudokuKeyboardLayout.java b/app/src/main/java/tu_darmstadt/sudoku/ui/view/SudokuKeyboardLayout.java index fbc57df..2c2b2eb 100644 --- a/app/src/main/java/tu_darmstadt/sudoku/ui/view/SudokuKeyboardLayout.java +++ b/app/src/main/java/tu_darmstadt/sudoku/ui/view/SudokuKeyboardLayout.java @@ -45,7 +45,7 @@ public class SudokuKeyboardLayout extends GridLayout { break; case NoteToggle: notesEnabled = !notesEnabled; - btn.setText(String.valueOf(notesEnabled)); + btn.setText(notesEnabled ? "ON" : "OFF"); break; case Do: // TODO: not implemented diff --git a/app/src/main/res/drawable-hdpi/privacyfriendlyappslogo.png b/app/src/main/res/drawable-hdpi/privacyfriendlyappslogo.png deleted file mode 100644 index 69f63a8..0000000 Binary files a/app/src/main/res/drawable-hdpi/privacyfriendlyappslogo.png and /dev/null differ diff --git a/app/src/main/res/drawable/privacyfriendlyappslogo.png b/app/src/main/res/drawable/privacyfriendlyappslogo.png new file mode 100644 index 0000000..14f2748 Binary files /dev/null and b/app/src/main/res/drawable/privacyfriendlyappslogo.png differ diff --git a/app/src/main/res/drawable/sudoku9x9.png b/app/src/main/res/drawable/sudoku9x9.png new file mode 100644 index 0000000..b884c54 Binary files /dev/null and b/app/src/main/res/drawable/sudoku9x9.png differ diff --git a/app/src/main/res/layout/activity_about.xml b/app/src/main/res/layout/activity_about.xml index bc3f9be..150d1ef 100644 --- a/app/src/main/res/layout/activity_about.xml +++ b/app/src/main/res/layout/activity_about.xml @@ -12,19 +12,12 @@ tools:context=".AboutActivity" android:weightSum="1"> - - - - - + + + + app:menu="@menu/menu_drawer" /> diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml deleted file mode 100644 index 1fbe2b6..0000000 --- a/app/src/main/res/layout/activity_main.xml +++ /dev/null @@ -1,58 +0,0 @@ - - - - - - - - - - - - - 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..de70967 --- /dev/null +++ b/app/src/main/res/layout/activity_main_menu.xml @@ -0,0 +1,171 @@ + + + + + + + + + + + + + + + + + + + + +