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) {
|
||||
this.gameType = type;
|
||||
this.size = GameType.getSize(type);
|
||||
this.sectionHeight = GameType.getSectionHeight(type);
|
||||
this.sectionWidth = GameType.getSectionWidth(type);
|
||||
this.size = type.getSize();
|
||||
this.sectionHeight = type.getSectionHeight();
|
||||
this.sectionWidth = type.getSectionWidth();
|
||||
}
|
||||
|
||||
/** Use with care.
|
||||
|
@ -224,7 +224,7 @@ public class GameController implements IModelChangedListener {
|
|||
|
||||
public int getValue(int row, int col) {
|
||||
GameCell cell = gameBoard.getCell(row, col);
|
||||
return cell.getValue();
|
||||
return cell.getValue();
|
||||
}
|
||||
|
||||
public GameType getGameType() {
|
||||
|
|
|
@ -50,7 +50,7 @@ public class GameInfoContainer {
|
|||
|
||||
public void parseFixedValues(String s){
|
||||
if(gameType != GameType.Unspecified && gameType != null) {
|
||||
int size = GameType.getSize(gameType);
|
||||
int size = gameType.getSize();
|
||||
int sq = size*size;
|
||||
|
||||
if(s.length() != sq) {
|
||||
|
@ -65,7 +65,7 @@ public class GameInfoContainer {
|
|||
|
||||
public void parseSetValues(String s) {
|
||||
if(gameType != GameType.Unspecified && gameType != null) {
|
||||
int size = GameType.getSize(gameType);
|
||||
int size = gameType.getSize();
|
||||
int sq = size*size;
|
||||
|
||||
if(s.length() != sq) {
|
||||
|
@ -81,7 +81,7 @@ public class GameInfoContainer {
|
|||
public void parseNotes(String s) {
|
||||
String[] strings = s.split("-");
|
||||
|
||||
int size = GameType.getSize(gameType);
|
||||
int size = gameType.getSize();
|
||||
int sq = size*size;
|
||||
|
||||
if(gameType != GameType.Unspecified && gameType != null) {
|
||||
|
|
|
@ -3,16 +3,32 @@ package tu_darmstadt.sudoku.game;
|
|||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import tu_darmstadt.sudoku.ui.view.R;
|
||||
|
||||
/**
|
||||
* Created by Chris on 09.11.2015.
|
||||
*/
|
||||
public enum GameType {
|
||||
Unspecified,
|
||||
Default_9x9,
|
||||
Default_12x12,
|
||||
Default_6x6,
|
||||
X_9x9,
|
||||
Hyper_9x9;
|
||||
Unspecified(1,1,1,R.string.gametype_unspecified,R.drawable.icon_default_6x6),
|
||||
Default_9x9(9,3,3,R.string.gametype_default_9x9,R.drawable.icon_default_9x9),
|
||||
Default_12x12(12,3,4,R.string.gametype_default_12x12,R.drawable.icon_default_12x12),
|
||||
Default_6x6(6,2,3,R.string.gametype_default_6x6,R.drawable.icon_default_6x6),
|
||||
X_9x9(9,3,3,R.string.gametype_x_9x9,R.drawable.icon_default_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() {
|
||||
LinkedList<GameType> result = new LinkedList<>();
|
||||
|
@ -22,51 +38,20 @@ public enum GameType {
|
|||
return result;
|
||||
}
|
||||
|
||||
public static int getSize(GameType type) {
|
||||
switch(type) {
|
||||
case X_9x9:
|
||||
case Hyper_9x9:
|
||||
case Default_9x9:
|
||||
return 9;
|
||||
case Default_12x12:
|
||||
return 12;
|
||||
case Default_6x6:
|
||||
return 6;
|
||||
case Unspecified:
|
||||
default:
|
||||
return 1;
|
||||
}
|
||||
public int getResIDImage(){return resIDImage; }
|
||||
public int getSectionHeight() {
|
||||
return sectionHeight;
|
||||
}
|
||||
public int getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public static int getSectionHeight(GameType type) {
|
||||
switch(type) {
|
||||
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 int getSectionWidth() {
|
||||
return sectionWidth;
|
||||
}
|
||||
|
||||
public static int getSectionWidth(GameType type) {
|
||||
switch(type) {
|
||||
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;
|
||||
}
|
||||
public int getStringResID() {
|
||||
return resIDString;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,8 +12,11 @@ import android.support.v7.app.ActionBarDrawerToggle;
|
|||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.MenuItem;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
import tu_darmstadt.sudoku.controller.SaveLoadController;
|
||||
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.SudokuKeyboardLayout;
|
||||
import tu_darmstadt.sudoku.ui.view.SudokuSpecialButtonLayout;
|
||||
import tu_darmstadt.sudoku.ui.view.SudokuTimer;
|
||||
|
||||
public class GameActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
|
||||
|
||||
|
@ -30,6 +34,10 @@ public class GameActivity extends AppCompatActivity implements NavigationView.On
|
|||
SudokuFieldLayout layout;
|
||||
SudokuKeyboardLayout keyboard;
|
||||
SudokuSpecialButtonLayout specialButtonLayout;
|
||||
Timer t = new Timer();
|
||||
SudokuTimer timerView;
|
||||
boolean isActive = true;
|
||||
TextView viewName ;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -92,11 +100,28 @@ public class GameActivity extends AppCompatActivity implements NavigationView.On
|
|||
//set Special keys
|
||||
specialButtonLayout = (SudokuSpecialButtonLayout) findViewById(R.id.sudokuSpecialLayout);
|
||||
specialButtonLayout.setButtons(p.x, gameController, keyboard);
|
||||
/*
|
||||
// DEBUG
|
||||
String debug = gameController.getFieldAsString();
|
||||
Log.d("Sudoku", debug);
|
||||
*/
|
||||
|
||||
//set TimerView
|
||||
timerView = (SudokuTimer)findViewById(R.id.timerView);
|
||||
|
||||
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);
|
||||
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
|
||||
|
@ -108,6 +133,17 @@ public class GameActivity extends AppCompatActivity implements NavigationView.On
|
|||
navigationView.setNavigationItemSelectedListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause(){
|
||||
super.onPause();
|
||||
isActive = false;
|
||||
}
|
||||
@Override
|
||||
public void onResume(){
|
||||
super.onResume();
|
||||
isActive = true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
|
|
|
@ -23,6 +23,8 @@ import android.widget.TextView;
|
|||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
import tu_darmstadt.sudoku.controller.SaveLoadController;
|
||||
import tu_darmstadt.sudoku.controller.helper.GameInfoContainer;
|
||||
|
@ -35,6 +37,7 @@ public class MainActivity extends AppCompatActivity {
|
|||
RatingBar difficultyBar;
|
||||
TextView difficultyText;
|
||||
SharedPreferences settings;
|
||||
Timer t = new Timer();
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
switch(gameType) {
|
||||
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);
|
||||
}
|
||||
imageView.setImageResource(gameType.getResIDImage());
|
||||
|
||||
|
||||
TextView textView = (TextView) rootView.findViewById(R.id.section_label);
|
||||
textView.setText(gameType.name());
|
||||
textView.setText(getString(gameType.getStringResID()));
|
||||
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:background="?attr/colorPrimary"
|
||||
app:popupTheme="@style/AppTheme.PopupOverlay" >
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="test"
|
||||
android:id="@+id/time"
|
||||
android:gravity="right"
|
||||
android:layout_marginRight="@dimen/activity_horizontal_margin"/>
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="testMode"
|
||||
android:id="@+id/gameModeText"
|
||||
android:gravity="center" />
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="testMode"
|
||||
android:id="@+id/gameModeText"
|
||||
android:gravity="center"
|
||||
android:layout_centerHorizontal="true"/>
|
||||
|
||||
<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.design.widget.AppBarLayout>
|
||||
|
|
|
@ -51,4 +51,13 @@
|
|||
<string name="difficulty_moderate">Moderate</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>
|
||||
|
|
Loading…
Reference in a new issue