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 6ce286c..76d6ecf 100644 --- a/app/src/main/java/tu_darmstadt/sudoku/controller/GameController.java +++ b/app/src/main/java/tu_darmstadt/sudoku/controller/GameController.java @@ -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() { diff --git a/app/src/main/java/tu_darmstadt/sudoku/controller/helper/GameInfoContainer.java b/app/src/main/java/tu_darmstadt/sudoku/controller/helper/GameInfoContainer.java index c84d5f7..dd92cf0 100644 --- a/app/src/main/java/tu_darmstadt/sudoku/controller/helper/GameInfoContainer.java +++ b/app/src/main/java/tu_darmstadt/sudoku/controller/helper/GameInfoContainer.java @@ -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) { 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 a06b4bf..06f49a4 100644 --- a/app/src/main/java/tu_darmstadt/sudoku/game/GameType.java +++ b/app/src/main/java/tu_darmstadt/sudoku/game/GameType.java @@ -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 getValidGameTypes() { LinkedList 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; } + } 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 2a4a449..35dbc7a 100644 --- a/app/src/main/java/tu_darmstadt/sudoku/ui/GameActivity.java +++ b/app/src/main/java/tu_darmstadt/sudoku/ui/GameActivity.java @@ -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() { 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 8f25101..449b604 100644 --- a/app/src/main/java/tu_darmstadt/sudoku/ui/MainActivity.java +++ b/app/src/main/java/tu_darmstadt/sudoku/ui/MainActivity.java @@ -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; } } diff --git a/app/src/main/java/tu_darmstadt/sudoku/ui/view/SudokuTimer.java b/app/src/main/java/tu_darmstadt/sudoku/ui/view/SudokuTimer.java new file mode 100644 index 0000000..4ec8dcc --- /dev/null +++ b/app/src/main/java/tu_darmstadt/sudoku/ui/view/SudokuTimer.java @@ -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); + } + +} diff --git a/app/src/main/res/layout/app_bar_game_view.xml b/app/src/main/res/layout/app_bar_game_view.xml index 1b75db0..32c1294 100644 --- a/app/src/main/res/layout/app_bar_game_view.xml +++ b/app/src/main/res/layout/app_bar_game_view.xml @@ -18,20 +18,26 @@ android:layout_height="?attr/actionBarSize" android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay" > - - + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2f07cde..be8546c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -51,4 +51,13 @@ Moderate Hard + + + Standart Sudoku 9x9 + Standart Sudoku 6x6 + Unspec + Standart Sudoku 12x12 + X Sudoku 9x9 + Hyper Sudoku 9x9 +