Changed GameType Enum to hold al the relevant information for that GameType. Added Timer to the GameView.
This commit is contained in:
parent
c7e7f1d88c
commit
8089adf862
8 changed files with 162 additions and 85 deletions
|
@ -171,9 +171,9 @@ public class GameController implements IModelChangedListener {
|
||||||
|
|
||||||
private void setGameType(GameType type) {
|
private void setGameType(GameType type) {
|
||||||
this.gameType = type;
|
this.gameType = type;
|
||||||
this.size = GameType.getSize(type);
|
this.size = type.getSize();
|
||||||
this.sectionHeight = GameType.getSectionHeight(type);
|
this.sectionHeight = type.getSectionHeight();
|
||||||
this.sectionWidth = GameType.getSectionWidth(type);
|
this.sectionWidth = type.getSectionWidth();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Use with care.
|
/** Use with care.
|
||||||
|
@ -224,7 +224,7 @@ public class GameController implements IModelChangedListener {
|
||||||
|
|
||||||
public int getValue(int row, int col) {
|
public int getValue(int row, int col) {
|
||||||
GameCell cell = gameBoard.getCell(row, col);
|
GameCell cell = gameBoard.getCell(row, col);
|
||||||
return cell.getValue();
|
return cell.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public GameType getGameType() {
|
public GameType getGameType() {
|
||||||
|
|
|
@ -50,7 +50,7 @@ public class GameInfoContainer {
|
||||||
|
|
||||||
public void parseFixedValues(String s){
|
public void parseFixedValues(String s){
|
||||||
if(gameType != GameType.Unspecified && gameType != null) {
|
if(gameType != GameType.Unspecified && gameType != null) {
|
||||||
int size = GameType.getSize(gameType);
|
int size = gameType.getSize();
|
||||||
int sq = size*size;
|
int sq = size*size;
|
||||||
|
|
||||||
if(s.length() != sq) {
|
if(s.length() != sq) {
|
||||||
|
@ -65,7 +65,7 @@ public class GameInfoContainer {
|
||||||
|
|
||||||
public void parseSetValues(String s) {
|
public void parseSetValues(String s) {
|
||||||
if(gameType != GameType.Unspecified && gameType != null) {
|
if(gameType != GameType.Unspecified && gameType != null) {
|
||||||
int size = GameType.getSize(gameType);
|
int size = gameType.getSize();
|
||||||
int sq = size*size;
|
int sq = size*size;
|
||||||
|
|
||||||
if(s.length() != sq) {
|
if(s.length() != sq) {
|
||||||
|
@ -81,7 +81,7 @@ public class GameInfoContainer {
|
||||||
public void parseNotes(String s) {
|
public void parseNotes(String s) {
|
||||||
String[] strings = s.split("-");
|
String[] strings = s.split("-");
|
||||||
|
|
||||||
int size = GameType.getSize(gameType);
|
int size = gameType.getSize();
|
||||||
int sq = size*size;
|
int sq = size*size;
|
||||||
|
|
||||||
if(gameType != GameType.Unspecified && gameType != null) {
|
if(gameType != GameType.Unspecified && gameType != null) {
|
||||||
|
|
|
@ -3,16 +3,32 @@ package tu_darmstadt.sudoku.game;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import tu_darmstadt.sudoku.ui.view.R;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Chris on 09.11.2015.
|
* Created by Chris on 09.11.2015.
|
||||||
*/
|
*/
|
||||||
public enum GameType {
|
public enum GameType {
|
||||||
Unspecified,
|
Unspecified(1,1,1,R.string.gametype_unspecified,R.drawable.icon_default_6x6),
|
||||||
Default_9x9,
|
Default_9x9(9,3,3,R.string.gametype_default_9x9,R.drawable.icon_default_9x9),
|
||||||
Default_12x12,
|
Default_12x12(12,3,4,R.string.gametype_default_12x12,R.drawable.icon_default_12x12),
|
||||||
Default_6x6,
|
Default_6x6(6,2,3,R.string.gametype_default_6x6,R.drawable.icon_default_6x6),
|
||||||
X_9x9,
|
X_9x9(9,3,3,R.string.gametype_x_9x9,R.drawable.icon_default_9x9),
|
||||||
Hyper_9x9;
|
Hyper_9x9(9,3,3,R.string.gametype_hyper_9x9,R.drawable.icon_default_9x9);
|
||||||
|
//TODO: change pictures for unsepc x9x9 and hyper 9x9 as soon as available
|
||||||
|
int resIDString;
|
||||||
|
int sectionWidth;
|
||||||
|
int sectionHeight;
|
||||||
|
int size;
|
||||||
|
int resIDImage;
|
||||||
|
|
||||||
|
GameType(int size, int sectionHeight, int sectionWidth, int resIDString, int resIDImage) {
|
||||||
|
this.resIDImage = resIDImage;
|
||||||
|
this.size = size;
|
||||||
|
this.sectionHeight = sectionHeight;
|
||||||
|
this.sectionWidth = sectionWidth;
|
||||||
|
this.resIDString = this.resIDString;
|
||||||
|
}
|
||||||
|
|
||||||
public static List<GameType> getValidGameTypes() {
|
public static List<GameType> getValidGameTypes() {
|
||||||
LinkedList<GameType> result = new LinkedList<>();
|
LinkedList<GameType> result = new LinkedList<>();
|
||||||
|
@ -22,51 +38,20 @@ public enum GameType {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getSize(GameType type) {
|
public int getResIDImage(){return resIDImage; }
|
||||||
switch(type) {
|
public int getSectionHeight() {
|
||||||
case X_9x9:
|
return sectionHeight;
|
||||||
case Hyper_9x9:
|
}
|
||||||
case Default_9x9:
|
public int getSize() {
|
||||||
return 9;
|
return size;
|
||||||
case Default_12x12:
|
|
||||||
return 12;
|
|
||||||
case Default_6x6:
|
|
||||||
return 6;
|
|
||||||
case Unspecified:
|
|
||||||
default:
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getSectionHeight(GameType type) {
|
public int getSectionWidth() {
|
||||||
switch(type) {
|
return sectionWidth;
|
||||||
case X_9x9:
|
|
||||||
case Hyper_9x9:
|
|
||||||
case Default_9x9:
|
|
||||||
return 3;
|
|
||||||
case Default_12x12:
|
|
||||||
return 3;
|
|
||||||
case Default_6x6:
|
|
||||||
return 2;
|
|
||||||
case Unspecified:
|
|
||||||
default:
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getSectionWidth(GameType type) {
|
public int getStringResID() {
|
||||||
switch(type) {
|
return resIDString;
|
||||||
case X_9x9:
|
|
||||||
case Hyper_9x9:
|
|
||||||
case Default_9x9:
|
|
||||||
return 3;
|
|
||||||
case Default_12x12:
|
|
||||||
return 4;
|
|
||||||
case Default_6x6:
|
|
||||||
return 3;
|
|
||||||
case Unspecified:
|
|
||||||
default:
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,8 +12,11 @@ import android.support.v7.app.ActionBarDrawerToggle;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Timer;
|
||||||
|
import java.util.TimerTask;
|
||||||
|
|
||||||
import tu_darmstadt.sudoku.controller.SaveLoadController;
|
import tu_darmstadt.sudoku.controller.SaveLoadController;
|
||||||
import tu_darmstadt.sudoku.controller.GameController;
|
import tu_darmstadt.sudoku.controller.GameController;
|
||||||
|
@ -23,6 +26,7 @@ import tu_darmstadt.sudoku.ui.view.R;
|
||||||
import tu_darmstadt.sudoku.ui.view.SudokuFieldLayout;
|
import tu_darmstadt.sudoku.ui.view.SudokuFieldLayout;
|
||||||
import tu_darmstadt.sudoku.ui.view.SudokuKeyboardLayout;
|
import tu_darmstadt.sudoku.ui.view.SudokuKeyboardLayout;
|
||||||
import tu_darmstadt.sudoku.ui.view.SudokuSpecialButtonLayout;
|
import tu_darmstadt.sudoku.ui.view.SudokuSpecialButtonLayout;
|
||||||
|
import tu_darmstadt.sudoku.ui.view.SudokuTimer;
|
||||||
|
|
||||||
public class GameActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
|
public class GameActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
|
||||||
|
|
||||||
|
@ -30,6 +34,10 @@ public class GameActivity extends AppCompatActivity implements NavigationView.On
|
||||||
SudokuFieldLayout layout;
|
SudokuFieldLayout layout;
|
||||||
SudokuKeyboardLayout keyboard;
|
SudokuKeyboardLayout keyboard;
|
||||||
SudokuSpecialButtonLayout specialButtonLayout;
|
SudokuSpecialButtonLayout specialButtonLayout;
|
||||||
|
Timer t = new Timer();
|
||||||
|
SudokuTimer timerView;
|
||||||
|
boolean isActive = true;
|
||||||
|
TextView viewName ;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
@ -92,11 +100,28 @@ public class GameActivity extends AppCompatActivity implements NavigationView.On
|
||||||
//set Special keys
|
//set Special keys
|
||||||
specialButtonLayout = (SudokuSpecialButtonLayout) findViewById(R.id.sudokuSpecialLayout);
|
specialButtonLayout = (SudokuSpecialButtonLayout) findViewById(R.id.sudokuSpecialLayout);
|
||||||
specialButtonLayout.setButtons(p.x, gameController, keyboard);
|
specialButtonLayout.setButtons(p.x, gameController, keyboard);
|
||||||
/*
|
|
||||||
// DEBUG
|
//set TimerView
|
||||||
String debug = gameController.getFieldAsString();
|
timerView = (SudokuTimer)findViewById(R.id.timerView);
|
||||||
Log.d("Sudoku", debug);
|
|
||||||
*/
|
t.scheduleAtFixedRate(new TimerTask() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
// run every second / ever 1000 milsecs
|
||||||
|
runOnUiThread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (isActive) timerView.increase();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, 0, 1000);
|
||||||
|
|
||||||
|
//set GameName
|
||||||
|
viewName = (TextView) findViewById(R.id.gameModeText);
|
||||||
|
viewName.setText(getString(gameController.getGameType().getStringResID()));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
|
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
|
||||||
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
|
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
|
||||||
|
@ -108,6 +133,17 @@ public class GameActivity extends AppCompatActivity implements NavigationView.On
|
||||||
navigationView.setNavigationItemSelectedListener(this);
|
navigationView.setNavigationItemSelectedListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPause(){
|
||||||
|
super.onPause();
|
||||||
|
isActive = false;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void onResume(){
|
||||||
|
super.onResume();
|
||||||
|
isActive = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBackPressed() {
|
public void onBackPressed() {
|
||||||
|
|
|
@ -23,6 +23,8 @@ import android.widget.TextView;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Timer;
|
||||||
|
import java.util.TimerTask;
|
||||||
|
|
||||||
import tu_darmstadt.sudoku.controller.SaveLoadController;
|
import tu_darmstadt.sudoku.controller.SaveLoadController;
|
||||||
import tu_darmstadt.sudoku.controller.helper.GameInfoContainer;
|
import tu_darmstadt.sudoku.controller.helper.GameInfoContainer;
|
||||||
|
@ -35,6 +37,7 @@ public class MainActivity extends AppCompatActivity {
|
||||||
RatingBar difficultyBar;
|
RatingBar difficultyBar;
|
||||||
TextView difficultyText;
|
TextView difficultyText;
|
||||||
SharedPreferences settings;
|
SharedPreferences settings;
|
||||||
|
Timer t = new Timer();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The {@link android.support.v4.view.PagerAdapter} that will provide
|
* The {@link android.support.v4.view.PagerAdapter} that will provide
|
||||||
|
@ -235,20 +238,11 @@ public class MainActivity extends AppCompatActivity {
|
||||||
|
|
||||||
ImageView imageView = (ImageView) rootView.findViewById(R.id.gameTypeImage);
|
ImageView imageView = (ImageView) rootView.findViewById(R.id.gameTypeImage);
|
||||||
|
|
||||||
switch(gameType) {
|
imageView.setImageResource(gameType.getResIDImage());
|
||||||
case Default_6x6:
|
|
||||||
imageView.setImageResource(R.drawable.icon_default_6x6);
|
|
||||||
break;
|
|
||||||
case Default_12x12:
|
|
||||||
imageView.setImageResource(R.drawable.icon_default_12x12);
|
|
||||||
break;
|
|
||||||
case Default_9x9:
|
|
||||||
default:
|
|
||||||
imageView.setImageResource(R.drawable.icon_default_9x9);
|
|
||||||
}
|
|
||||||
|
|
||||||
TextView textView = (TextView) rootView.findViewById(R.id.section_label);
|
TextView textView = (TextView) rootView.findViewById(R.id.section_label);
|
||||||
textView.setText(gameType.name());
|
textView.setText(getString(gameType.getStringResID()));
|
||||||
return rootView;
|
return rootView;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
package tu_darmstadt.sudoku.ui.view;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by TMZ_LToP on 19.11.2015.
|
||||||
|
*/
|
||||||
|
public class SudokuTimer extends TextView {
|
||||||
|
|
||||||
|
int seconds=0;
|
||||||
|
int mins=0;
|
||||||
|
long hours=0;
|
||||||
|
|
||||||
|
public SudokuTimer(Context context, AttributeSet attrs) {
|
||||||
|
super(context, attrs);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSeconds(){
|
||||||
|
return seconds;
|
||||||
|
}
|
||||||
|
public int getMins(){
|
||||||
|
return mins;
|
||||||
|
}
|
||||||
|
public long getHours(){
|
||||||
|
return hours;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void increase () {
|
||||||
|
seconds ++;
|
||||||
|
if(seconds+1 == 60){
|
||||||
|
seconds=0;
|
||||||
|
mins++;
|
||||||
|
}if (mins == 60) {
|
||||||
|
mins=0;
|
||||||
|
hours++;
|
||||||
|
}
|
||||||
|
String h,m,s;
|
||||||
|
s = (seconds<10)? "0"+String.valueOf(seconds) : String.valueOf(seconds);
|
||||||
|
m = (mins<10)? "0"+String.valueOf(mins) : String.valueOf(mins);
|
||||||
|
h = (hours<10)? "0"+String.valueOf(hours) : String.valueOf(hours);
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
setText(h+":"+m+":"+s);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -18,20 +18,26 @@
|
||||||
android:layout_height="?attr/actionBarSize"
|
android:layout_height="?attr/actionBarSize"
|
||||||
android:background="?attr/colorPrimary"
|
android:background="?attr/colorPrimary"
|
||||||
app:popupTheme="@style/AppTheme.PopupOverlay" >
|
app:popupTheme="@style/AppTheme.PopupOverlay" >
|
||||||
<TextView
|
<RelativeLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content">
|
||||||
android:text="test"
|
<TextView
|
||||||
android:id="@+id/time"
|
android:layout_width="wrap_content"
|
||||||
android:gravity="right"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginRight="@dimen/activity_horizontal_margin"/>
|
android:text="testMode"
|
||||||
<TextView
|
android:id="@+id/gameModeText"
|
||||||
android:layout_width="match_parent"
|
android:gravity="center"
|
||||||
android:layout_height="wrap_content"
|
android:layout_centerHorizontal="true"/>
|
||||||
android:text="testMode"
|
|
||||||
android:id="@+id/gameModeText"
|
|
||||||
android:gravity="center" />
|
|
||||||
|
|
||||||
|
<tu_darmstadt.sudoku.ui.view.SudokuTimer
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="test"
|
||||||
|
android:id="@+id/timerView"
|
||||||
|
android:gravity="right"
|
||||||
|
android:layout_alignParentRight="true"
|
||||||
|
android:layout_marginRight="@dimen/activity_horizontal_margin"/>
|
||||||
|
</RelativeLayout>
|
||||||
</android.support.v7.widget.Toolbar>
|
</android.support.v7.widget.Toolbar>
|
||||||
|
|
||||||
</android.support.design.widget.AppBarLayout>
|
</android.support.design.widget.AppBarLayout>
|
||||||
|
|
|
@ -51,4 +51,13 @@
|
||||||
<string name="difficulty_moderate">Moderate</string>
|
<string name="difficulty_moderate">Moderate</string>
|
||||||
<string name="difficulty_hard">Hard</string>
|
<string name="difficulty_hard">Hard</string>
|
||||||
|
|
||||||
|
<!--###GameActivity -->
|
||||||
|
<string name="Sudoku"></string>
|
||||||
|
<string name="gametype_default_9x9">Standart Sudoku 9x9</string>
|
||||||
|
<string name="gametype_default_6x6">Standart Sudoku 6x6</string>
|
||||||
|
<string name="gametype_unspecified">Unspec</string>
|
||||||
|
<string name="gametype_default_12x12">Standart Sudoku 12x12</string>
|
||||||
|
<string name="gametype_x_9x9">X Sudoku 9x9</string>
|
||||||
|
<string name="gametype_hyper_9x9">Hyper Sudoku 9x9</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in a new issue