Added the NewGame screen. No real settings available yet.

This commit is contained in:
Christopher Beckmann 2015-11-15 12:18:22 +01:00
parent 54b9de3e22
commit 94f183f95b
8 changed files with 189 additions and 36 deletions

View file

@ -18,16 +18,18 @@
<activity <activity
android:name="tu_darmstadt.sudoku.ui.SettingsActivity" android:name="tu_darmstadt.sudoku.ui.SettingsActivity"
android:label="@string/title_activity_settings" android:label="@string/title_activity_settings"
android:parentActivityName="tu_darmstadt.sudoku.ui.MainActivity"> android:parentActivityName="tu_darmstadt.sudoku.ui.MainActivity" >
</activity> </activity>
<activity <activity
android:screenOrientation="portrait"
android:name="tu_darmstadt.sudoku.ui.GameActivity" android:name="tu_darmstadt.sudoku.ui.GameActivity"
android:label="@string/title_activity_game_view" android:label="@string/title_activity_game_view"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar" > android:theme="@style/AppTheme.NoActionBar" >
</activity> </activity>
<activity android:name="tu_darmstadt.sudoku.ui.AboutActivity" > <activity android:name="tu_darmstadt.sudoku.ui.AboutActivity" >
</activity> </activity>
<activity android:name="tu_darmstadt.sudoku.ui.NewGameActivity" >
</activity>
</application> </application>
</manifest> </manifest>

View file

@ -47,6 +47,53 @@ public class GameController {
setSettings(pref); 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) { public void loadLevel(GameType type, int[] fixedValues, int[] setValues, int[][] setNotes) {
setGameType(type); setGameType(type);
this.gameBoard = new GameBoard(size, sectionHeight, sectionWidth); this.gameBoard = new GameBoard(size, sectionHeight, sectionWidth);
@ -67,7 +114,6 @@ public class GameController {
if(setNotes != null) { if(setNotes != null) {
// set notes. // set notes.
} }
} }
public void setSettings(SharedPreferences pref) { public void setSettings(SharedPreferences pref) {
@ -260,15 +306,19 @@ public class GameController {
} }
public void setSelectedValue(int value) { public void setSelectedValue(int value) {
if(selectedRow != -1 && selectedCol != -1) setValue(selectedRow, selectedCol, value); if(isCellSelected()) setValue(selectedRow, selectedCol, value);
} }
public void deleteSelectedValue() { public void deleteSelectedValue() {
if(selectedRow != -1 && selectedCol != -1) setValue(selectedRow, selectedCol, 0); if(isCellSelected()) setValue(selectedRow, selectedCol, 0);
} }
public void toggleSelectedNote(int value) { 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) { // public void registerListener(IModelChangeListener l) {

View file

@ -33,6 +33,19 @@ public class GameActivity extends AppCompatActivity implements NavigationView.On
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(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); SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
setContentView(R.layout.activity_game_view); setContentView(R.layout.activity_game_view);
@ -42,31 +55,8 @@ public class GameActivity extends AppCompatActivity implements NavigationView.On
//Create new GameField //Create new GameField
layout = (SudokuFieldLayout)findViewById(R.id.sudokuLayout); layout = (SudokuFieldLayout)findViewById(R.id.sudokuLayout);
gameController = new GameController(sharedPref); gameController = new GameController(sharedPref);
/*gameController.loadLevel(GameType.Default_9x9,
new int[]{5, 0, 1, 9, 0, 0, 0, 0, 0, gameController.loadNewLevel(gameType, gameDifficulty);
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);
layout.setGame(gameController); layout.setGame(gameController);
layout.setSettings(sharedPref); layout.setSettings(sharedPref);

View file

@ -17,7 +17,7 @@ public class MainActivity extends AppCompatActivity {
} }
public void onClicktext(View view) { public void onClicktext(View view) {
Intent i = new Intent(this, GameActivity.class); Intent i = new Intent(this, NewGameActivity.class);
startActivity(i); startActivity(i);
} }

View file

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

View file

@ -11,5 +11,6 @@ public enum SudokuButtonType {
Hint, Hint,
NoteToggle, NoteToggle,
NumberOrCellFirst, NumberOrCellFirst,
Delete Delete,
Reset
} }

View file

@ -1,22 +1,60 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin" android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin"
android:layout_centerHorizontal="true" android:layout_centerHorizontal="true"
tools:context="tu_darmstadt.sudoku.activity.MainActivity"> android:orientation="vertical"
tools:context="tu_darmstadt.sudoku.activity.MainActivity"
android:weightSum="10"
android:divider="#000">
<!-- TODO .. add menu --> <!-- TODO .. add menu -->
<!--<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" >
<menu xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<group android:checkableBehavior="single">
<item android:id="@+id/nav_newgame" android:icon="@android:drawable/ic_menu_today"
android:title="@string/new_game" />
<item android:id="@+id/nav_mainmenu" android:icon="@android:drawable/ic_menu_gallery"
android:title="@string/mainmenu" />
<item android:id="@+id/nav_highscore" android:icon="@android:drawable/ic_menu_myplaces"
android:title="@string/highscore" />
</group>
<group android:menuCategory="container" android:title="">
<menu>
<item android:id="@+id/nav_settings" android:icon="@android:drawable/ic_menu_manage"
android:title="@string/settings" />
<item android:id="@+id/nav_help" android:icon="@android:drawable/ic_menu_help"
android:title="@string/help" />
<item android:id="@+id/nav_about" android:icon="@android:drawable/ic_menu_info_details"
android:title="@string/about" />
</menu>
</group>
</menu>
</android.support.design.widget.NavigationView>-->
<TextView android:id="@+id/testString" <TextView android:id="@+id/testString"
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:editable="true" android:editable="true"
android:clickable="true" android:clickable="true"
android:onClick="onClicktext" android:onClick="onClicktext"
android:text="@string/app_name"/> android:text="@string/app_name"/>
</LinearLayout> </LinearLayout>

View file

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" 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"
tools:context="tu_darmstadt.sudoku.ui.NewGameActivity"
android:layout_centerHorizontal="true"
android:orientation="vertical"
android:weightSum="10"
android:divider="#000"
android:baselineAligned="false"
android:gravity="center_vertical|center_horizontal">
<RatingBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ratingBar"
android:layout_gravity="center_horizontal"
android:clickable="true"
android:numStars="5"
android:rating="1"
android:stepSize="1" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/button"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:onClick="onPlayClick"/>
</LinearLayout>