Add private verification method to CreateSudokuActivity

This commit is contained in:
uykek 2020-06-30 10:14:30 +02:00
parent bc88df46f1
commit bc047addea

View file

@ -8,10 +8,14 @@ import android.preference.PreferenceManager;
import android.view.View; import android.view.View;
import android.view.WindowManager; import android.view.WindowManager;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatDelegate;
import org.secuso.privacyfriendlysudoku.controller.GameController; import org.secuso.privacyfriendlysudoku.controller.GameController;
import org.secuso.privacyfriendlysudoku.controller.Symbol; import org.secuso.privacyfriendlysudoku.controller.Symbol;
import org.secuso.privacyfriendlysudoku.controller.helper.GameInfoContainer; import org.secuso.privacyfriendlysudoku.controller.helper.GameInfoContainer;
import org.secuso.privacyfriendlysudoku.controller.qqwing.QQWing;
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.ui.view.R; import org.secuso.privacyfriendlysudoku.ui.view.R;
@ -30,6 +34,17 @@ public class CreateSudokuActivity extends BaseActivity {
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
if (sharedPref.getBoolean("pref_dark_mode_setting", false )) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
} else {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
}
if(sharedPref.getBoolean("pref_keep_screen_on", true)) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
gameController = new GameController(sharedPref, getApplicationContext()); gameController = new GameController(sharedPref, getApplicationContext());
if(sharedPref.getBoolean("pref_keep_screen_on", true)) { if(sharedPref.getBoolean("pref_keep_screen_on", true)) {
@ -92,4 +107,26 @@ public class CreateSudokuActivity extends BaseActivity {
finish(); finish();
super.onBackPressed(); super.onBackPressed();
} }
private void verify() {
Toast.makeText(CreateSudokuActivity.this, "Verifying...", Toast.LENGTH_SHORT).show();
GameType gameType = gameController.getGameType();
int boardSize = gameType.getSize() * gameType.getSize();
QQWing verifier = new QQWing(gameType, GameDifficulty.Unspecified);
GameInfoContainer container = new GameInfoContainer(0, GameDifficulty.Unspecified,
gameType, new int [boardSize], new int [boardSize], new boolean [boardSize][gameType.getSize()]);
container.parseFixedValues(gameController.getCodeOfField());
verifier.setRecordHistory(true);
verifier.setPuzzle(container.getFixedValues());
boolean solvable = verifier.solve();
if(solvable) {
Toast.makeText(CreateSudokuActivity.this, "Done verifying!", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(CreateSudokuActivity.this, "Your sudoku cannot be solved!", Toast.LENGTH_LONG).show();
}
}
} }