From 25e92172f01289db2a68965dfe4daa94b75add1a Mon Sep 17 00:00:00 2001 From: uykek Date: Tue, 19 May 2020 18:23:41 +0200 Subject: [PATCH] Fix mistake which caused impossible imported sudokus to be saved to database. --- .../ui/GameActivity.java | 38 ++++++++++++------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/GameActivity.java b/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/GameActivity.java index da45e48..8b2bd2d 100644 --- a/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/GameActivity.java +++ b/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/GameActivity.java @@ -69,6 +69,7 @@ public class GameActivity extends BaseActivity implements NavigationView.OnNavig TextView viewName ; RatingBar ratingBar; private boolean gameSolved = false; + private boolean startGame = true; SaveLoadStatistics statistics = new SaveLoadStatistics(this); WinDialog dialog = null; @@ -119,22 +120,29 @@ public class GameActivity extends BaseActivity implements NavigationView.OnNavig int sectionSize = (int)Math.sqrt(input.length()); 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]); - container.parseFixedValues(input); - container.parseGameType("Default_" + sectionSize + "x" + sectionSize); + try { + container.parseFixedValues(input); + container.parseGameType("Default_" + sectionSize + "x" + sectionSize); - QQWing difficultyCheck = new QQWing(container.getGameType(), GameDifficulty.Unspecified); - difficultyCheck.setRecordHistory(true); - difficultyCheck.setPuzzle(container.getFixedValues()); - boolean possibleToSolve = difficultyCheck.solve(); + difficultyCheck = new QQWing(container.getGameType(), GameDifficulty.Unspecified); + difficultyCheck.setRecordHistory(true); + difficultyCheck.setPuzzle(container.getFixedValues()); + startGame = difficultyCheck.solve(); + container.parseDifficulty(difficultyCheck.getDifficulty().toString()); - String difficulty = difficultyCheck.getDifficulty().toString(); - container.parseDifficulty(difficulty); - gameController.loadLevel(container); - - if (!possibleToSolve) { + } catch (IllegalArgumentException e) { + startGame = false; + sectionSize = GameType.Default_9x9.getSize(); + boardSize = sectionSize * sectionSize; + 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); builder.setMessage(R.string.impossible_import_notice) .setCancelable(false) @@ -147,6 +155,8 @@ public class GameActivity extends BaseActivity implements NavigationView.OnNavig alert.show(); } + gameController.loadLevel(container); + } else { if (extras != null) { gameType = GameType.valueOf(extras.getString("gameType", GameType.Default_9x9.name())); @@ -268,7 +278,7 @@ public class GameActivity extends BaseActivity implements NavigationView.OnNavig @Override public void onPause(){ super.onPause(); - if(!gameSolved) { + if(!gameSolved && startGame) { gameController.saveGame(this); } gameController.deleteTimer(); @@ -493,7 +503,7 @@ public class GameActivity extends BaseActivity implements NavigationView.OnNavig // display the time timerView.setText(timeToString(time)); - if(gameSolved) return; + if(gameSolved || !startGame) return; // save time gameController.saveGame(this); }