Fix mistake which caused impossible imported sudokus to be saved to database.
This commit is contained in:
parent
064fcd9971
commit
25e92172f0
1 changed files with 24 additions and 14 deletions
|
@ -69,6 +69,7 @@ public class GameActivity extends BaseActivity implements NavigationView.OnNavig
|
||||||
TextView viewName ;
|
TextView viewName ;
|
||||||
RatingBar ratingBar;
|
RatingBar ratingBar;
|
||||||
private boolean gameSolved = false;
|
private boolean gameSolved = false;
|
||||||
|
private boolean startGame = true;
|
||||||
SaveLoadStatistics statistics = new SaveLoadStatistics(this);
|
SaveLoadStatistics statistics = new SaveLoadStatistics(this);
|
||||||
WinDialog dialog = null;
|
WinDialog dialog = null;
|
||||||
|
|
||||||
|
@ -119,22 +120,29 @@ public class GameActivity extends BaseActivity implements NavigationView.OnNavig
|
||||||
|
|
||||||
int sectionSize = (int)Math.sqrt(input.length());
|
int sectionSize = (int)Math.sqrt(input.length());
|
||||||
int boardSize = sectionSize * sectionSize;
|
int boardSize = sectionSize * sectionSize;
|
||||||
|
QQWing difficultyCheck;
|
||||||
|
GameInfoContainer container = new GameInfoContainer(0, GameDifficulty.Unspecified,
|
||||||
|
GameType.Unspecified, new int [boardSize], new int [boardSize], new boolean [boardSize][sectionSize]);
|
||||||
|
|
||||||
GameInfoContainer container = new GameInfoContainer(0, null, null, null, new int [boardSize], new boolean [boardSize][sectionSize]);
|
try {
|
||||||
container.parseFixedValues(input);
|
container.parseFixedValues(input);
|
||||||
container.parseGameType("Default_" + sectionSize + "x" + sectionSize);
|
container.parseGameType("Default_" + sectionSize + "x" + sectionSize);
|
||||||
|
|
||||||
QQWing difficultyCheck = new QQWing(container.getGameType(), GameDifficulty.Unspecified);
|
difficultyCheck = new QQWing(container.getGameType(), GameDifficulty.Unspecified);
|
||||||
difficultyCheck.setRecordHistory(true);
|
difficultyCheck.setRecordHistory(true);
|
||||||
difficultyCheck.setPuzzle(container.getFixedValues());
|
difficultyCheck.setPuzzle(container.getFixedValues());
|
||||||
boolean possibleToSolve = difficultyCheck.solve();
|
startGame = difficultyCheck.solve();
|
||||||
|
container.parseDifficulty(difficultyCheck.getDifficulty().toString());
|
||||||
|
|
||||||
String difficulty = difficultyCheck.getDifficulty().toString();
|
} catch (IllegalArgumentException e) {
|
||||||
container.parseDifficulty(difficulty);
|
startGame = false;
|
||||||
gameController.loadLevel(container);
|
sectionSize = GameType.Default_9x9.getSize();
|
||||||
|
boardSize = sectionSize * sectionSize;
|
||||||
if (!possibleToSolve) {
|
container = new GameInfoContainer(0, GameDifficulty.Unspecified,
|
||||||
|
GameType.Default_9x9, new int [boardSize], new int [boardSize], new boolean [boardSize][sectionSize]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!startGame) {
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(GameActivity.this);
|
AlertDialog.Builder builder = new AlertDialog.Builder(GameActivity.this);
|
||||||
builder.setMessage(R.string.impossible_import_notice)
|
builder.setMessage(R.string.impossible_import_notice)
|
||||||
.setCancelable(false)
|
.setCancelable(false)
|
||||||
|
@ -147,6 +155,8 @@ public class GameActivity extends BaseActivity implements NavigationView.OnNavig
|
||||||
alert.show();
|
alert.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gameController.loadLevel(container);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (extras != null) {
|
if (extras != null) {
|
||||||
gameType = GameType.valueOf(extras.getString("gameType", GameType.Default_9x9.name()));
|
gameType = GameType.valueOf(extras.getString("gameType", GameType.Default_9x9.name()));
|
||||||
|
@ -268,7 +278,7 @@ public class GameActivity extends BaseActivity implements NavigationView.OnNavig
|
||||||
@Override
|
@Override
|
||||||
public void onPause(){
|
public void onPause(){
|
||||||
super.onPause();
|
super.onPause();
|
||||||
if(!gameSolved) {
|
if(!gameSolved && startGame) {
|
||||||
gameController.saveGame(this);
|
gameController.saveGame(this);
|
||||||
}
|
}
|
||||||
gameController.deleteTimer();
|
gameController.deleteTimer();
|
||||||
|
@ -493,7 +503,7 @@ public class GameActivity extends BaseActivity implements NavigationView.OnNavig
|
||||||
// display the time
|
// display the time
|
||||||
timerView.setText(timeToString(time));
|
timerView.setText(timeToString(time));
|
||||||
|
|
||||||
if(gameSolved) return;
|
if(gameSolved || !startGame) return;
|
||||||
// save time
|
// save time
|
||||||
gameController.saveGame(this);
|
gameController.saveGame(this);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue