stats reworked fixed a bug
This commit is contained in:
parent
3d110b57c5
commit
4724612c1e
7 changed files with 34 additions and 28 deletions
|
@ -173,8 +173,8 @@ public class GameController implements IModelChangedListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
int[] solved = solve();
|
int[] solved = solve();
|
||||||
//
|
// TODO test every placed value so far
|
||||||
// reveal the selected value.
|
// and reveal the selected value.
|
||||||
selectValue(solved[selectedRow * getSize() + selectedCol]);
|
selectValue(solved[selectedRow * getSize() + selectedCol]);
|
||||||
usedHints++;
|
usedHints++;
|
||||||
|
|
||||||
|
|
|
@ -13,11 +13,13 @@ import java.util.List;
|
||||||
import org.secuso.privacyfriendlysudoku.controller.helper.HighscoreInfoContainer;
|
import org.secuso.privacyfriendlysudoku.controller.helper.HighscoreInfoContainer;
|
||||||
import org.secuso.privacyfriendlysudoku.game.GameDifficulty;
|
import org.secuso.privacyfriendlysudoku.game.GameDifficulty;
|
||||||
import org.secuso.privacyfriendlysudoku.game.GameType;
|
import org.secuso.privacyfriendlysudoku.game.GameType;
|
||||||
|
import org.secuso.privacyfriendlysudoku.game.listener.IHintListener;
|
||||||
|
import org.secuso.privacyfriendlysudoku.game.listener.ITimerListener;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by TMZ_LToP on 19.11.2015.
|
* Created by TMZ_LToP on 19.11.2015.
|
||||||
*/
|
*/
|
||||||
public class SaveLoadStatistics implements ITimerListener {
|
public class SaveLoadStatistics implements ITimerListener, IHintListener {
|
||||||
|
|
||||||
|
|
||||||
private static String FILE_EXTENSION = ".txt";
|
private static String FILE_EXTENSION = ".txt";
|
||||||
|
@ -114,15 +116,14 @@ public class SaveLoadStatistics implements ITimerListener {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveTime(GameDifficulty gd, GameType gameType) {
|
public void incTime(GameDifficulty gd, GameType gameType) {
|
||||||
//TODO: Increse time every second
|
|
||||||
HighscoreInfoContainer infos = loadStats(gameType, gd);
|
HighscoreInfoContainer infos = loadStats(gameType, gd);
|
||||||
infos.incTime();
|
infos.incTime();
|
||||||
saveContainer(infos,gd,gameType);
|
saveContainer(infos,gd,gameType);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
public void saveHints(GameDifficulty gd, GameType gameType){
|
public void incHints(GameDifficulty gd, GameType gameType){
|
||||||
HighscoreInfoContainer infos = loadStats(gameType,gd);
|
HighscoreInfoContainer infos = loadStats(gameType,gd);
|
||||||
infos.incHints();
|
infos.incHints();
|
||||||
saveContainer(infos,gd,gameType);
|
saveContainer(infos,gd,gameType);
|
||||||
|
@ -202,7 +203,12 @@ public class SaveLoadStatistics implements ITimerListener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTick(int time) {
|
public void onTick(int time) {
|
||||||
saveTime(gc.getDifficulty(),gc.getGameType());
|
incTime(gc.getDifficulty(), gc.getGameType());
|
||||||
//gc.getUsedHints();
|
//gc.getUsedHints();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onHintUsed() {
|
||||||
|
incHints(gc.getDifficulty(),gc.getGameType());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,9 @@ import android.support.v4.widget.DrawerLayout;
|
||||||
import android.support.v7.app.ActionBarDrawerToggle;
|
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.Gravity;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
import android.view.WindowManager;
|
||||||
import android.widget.RatingBar;
|
import android.widget.RatingBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
@ -252,15 +254,18 @@ public class GameActivity extends AppCompatActivity implements NavigationView.On
|
||||||
gameController.pauseTimer();
|
gameController.pauseTimer();
|
||||||
gameController.deleteGame(this);
|
gameController.deleteGame(this);
|
||||||
|
|
||||||
Toast t = Toast.makeText(this, R.string.win_text, Toast.LENGTH_SHORT);
|
//Show time hints new plus old best time
|
||||||
t.show();
|
|
||||||
|
|
||||||
statistics.saveGameStats();
|
statistics.saveGameStats();
|
||||||
|
|
||||||
FragmentManager fr = getSupportFragmentManager();
|
Dialog dialog = new Dialog(this);
|
||||||
DialogWinScreen win = new DialogWinScreen();
|
//dialog.setContentView(getLayoutInflater().inflate(R.layout.win_screen_layout,null));
|
||||||
win.setProps(gameController, this);
|
dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
|
||||||
win.show(fr, "win_screen_layout");
|
//dialog.setContentView(R.layout.win_screen_layout);
|
||||||
|
dialog.getWindow().setGravity(Gravity.CENTER_HORIZONTAL);
|
||||||
|
dialog.getWindow().setContentView(R.layout.win_screen_layout);
|
||||||
|
dialog.getWindow().setBackgroundDrawableResource(R.color.transparent);
|
||||||
|
dialog.show();
|
||||||
|
|
||||||
keyboard.setButtonsEnabled(false);
|
keyboard.setButtonsEnabled(false);
|
||||||
specialButtonLayout.setButtonsEnabled(false);
|
specialButtonLayout.setButtonsEnabled(false);
|
||||||
|
|
|
@ -144,14 +144,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
||||||
DialogWinScreen winScreen = new DialogWinScreen();
|
DialogWinScreen winScreen = new DialogWinScreen();
|
||||||
|
|
||||||
winScreen.show(fm,"win_screen_layout");*/
|
winScreen.show(fm,"win_screen_layout");*/
|
||||||
Dialog dialog = new Dialog(this);
|
|
||||||
//dialog.setContentView(getLayoutInflater().inflate(R.layout.win_screen_layout,null));
|
|
||||||
dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
|
|
||||||
//dialog.setContentView(R.layout.win_screen_layout);
|
|
||||||
dialog.getWindow().setGravity(Gravity.CENTER_HORIZONTAL);
|
|
||||||
dialog.getWindow().setContentView(R.layout.win_screen_layout);
|
|
||||||
dialog.getWindow().setBackgroundDrawableResource(R.color.transparent);
|
|
||||||
dialog.show();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
|
|
|
@ -181,7 +181,7 @@ public class StatsActivity extends AppCompatActivity {
|
||||||
List<HighscoreInfoContainer> stats = s.loadStats(GameType.getValidGameTypes().get(getArguments().getInt(ARG_SECTION_NUMBER)));
|
List<HighscoreInfoContainer> stats = s.loadStats(GameType.getValidGameTypes().get(getArguments().getInt(ARG_SECTION_NUMBER)));
|
||||||
int j =0;
|
int j =0;
|
||||||
for (HighscoreInfoContainer i : stats){
|
for (HighscoreInfoContainer i : stats){
|
||||||
updateGeneralIfo(i.getTime(), i.getNumberOfGames(), i.getNumberOfHintsUsed());
|
updateGeneralInfo(i.getTime(), i.getNumberOfGames(), i.getNumberOfHintsUsed());
|
||||||
setStats(i,j++);
|
setStats(i,j++);
|
||||||
}
|
}
|
||||||
setGeneralInfo();
|
setGeneralInfo();
|
||||||
|
@ -209,7 +209,7 @@ public class StatsActivity extends AppCompatActivity {
|
||||||
return (h + ":" + m + ":" + s);
|
return (h + ":" + m + ":" + s);
|
||||||
|
|
||||||
}
|
}
|
||||||
private void updateGeneralIfo(int time, int games, int hints){
|
private void updateGeneralInfo(int time, int games, int hints){
|
||||||
totalHints +=hints;
|
totalHints +=hints;
|
||||||
totalGames +=games;
|
totalGames +=games;
|
||||||
totalTime +=time;
|
totalTime +=time;
|
||||||
|
@ -264,6 +264,7 @@ public class StatsActivity extends AppCompatActivity {
|
||||||
|
|
||||||
View rootView = inflater.inflate(R.layout.fragment_stats, container, false);
|
View rootView = inflater.inflate(R.layout.fragment_stats, container, false);
|
||||||
this.rootView = rootView;
|
this.rootView = rootView;
|
||||||
|
resetGeneral();
|
||||||
TextView textView = (TextView) rootView.findViewById(R.id.section_label);
|
TextView textView = (TextView) rootView.findViewById(R.id.section_label);
|
||||||
|
|
||||||
SaveLoadStatistics s = new SaveLoadStatistics(this.getContext());
|
SaveLoadStatistics s = new SaveLoadStatistics(this.getContext());
|
||||||
|
@ -272,7 +273,7 @@ public class StatsActivity extends AppCompatActivity {
|
||||||
|
|
||||||
int j =0;
|
int j =0;
|
||||||
for (HighscoreInfoContainer i : stats){
|
for (HighscoreInfoContainer i : stats){
|
||||||
updateGeneralIfo(i.getTime(), i.getNumberOfGames(), i.getNumberOfHintsUsed());
|
updateGeneralInfo(i.getTime(), i.getNumberOfGames(), i.getNumberOfHintsUsed());
|
||||||
setStats(i,j++);
|
setStats(i,j++);
|
||||||
}
|
}
|
||||||
setGeneralInfo();
|
setGeneralInfo();
|
||||||
|
|
|
@ -115,6 +115,7 @@
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="@color/colorPrimaryDark"
|
android:background="@color/colorPrimaryDark"
|
||||||
|
android:textColor="@color/white"
|
||||||
android:text="@string/win_button_text"/>
|
android:text="@string/win_button_text"/>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
|
@ -98,11 +98,11 @@
|
||||||
|
|
||||||
<!-- ### Stats ###-->
|
<!-- ### Stats ###-->
|
||||||
<string name="stats_name">Statistics</string>
|
<string name="stats_name">Statistics</string>
|
||||||
<string name="number_of_hints">Number of hints used:</string>
|
<string name="number_of_hints"># used hints:</string>
|
||||||
<string name="number_of_games">Number of games played:</string>
|
<string name="number_of_games"># completed games:</string>
|
||||||
<string name="total_of_time">Total time played:</string>
|
<string name="total_of_time">Total time played:</string>
|
||||||
<string name="average_time">Average time:</string>
|
<string name="average_time">average time:</string>
|
||||||
<string name="min_time">Minimum time:</string>
|
<string name="min_time">best time:</string>
|
||||||
<string name="reset_stats">Reset All</string>
|
<string name="reset_stats">Reset All</string>
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue