Found and fixed a bug, that would prevent the game from being deleted, when using the regular input method for the last number to solve the puzzle.

Also found and fixed a bug, where the game would not save the amount of hints used, when continueing a game.
This commit is contained in:
Christopher Beckmann 2016-02-04 00:45:14 +01:00
parent 6e96ee8904
commit 763ea0b6e7
5 changed files with 30 additions and 31 deletions

View file

@ -116,6 +116,7 @@ public class GameController implements IModelChangedListener, Parcelable {
this.gameID = gic.getID(); this.gameID = gic.getID();
this.difficulty = gic.getDifficulty(); this.difficulty = gic.getDifficulty();
this.time = gic.getTimePlayed(); this.time = gic.getTimePlayed();
this.usedHints = gic.getHintsUsed();
setGameType(gic.getGameType()); setGameType(gic.getGameType());
this.gameBoard = new GameBoard(gic.getGameType()); this.gameBoard = new GameBoard(gic.getGameType());
@ -472,7 +473,6 @@ public class GameController implements IModelChangedListener, Parcelable {
undoRedoManager.addState(gameBoard); undoRedoManager.addState(gameBoard);
notifyHighlightChangedListeners(); notifyHighlightChangedListeners();
} }
} }
public void toggleSelectedCellsNote(int value) { public void toggleSelectedCellsNote(int value) {
@ -487,12 +487,6 @@ public class GameController implements IModelChangedListener, Parcelable {
return selectedRow != -1 && selectedCol != -1 && !getGameCell(selectedRow, selectedCol).isFixed(); return selectedRow != -1 && selectedCol != -1 && !getGameCell(selectedRow, selectedCol).isFixed();
} }
// public void registerListener(IModelChangeListener l) {
// if(!listeners.contains(l)) {
// listeners.add(l);
// }
// }
public int getSectionHeight() { public int getSectionHeight() {
return sectionHeight; return sectionHeight;
} }
@ -554,12 +548,6 @@ public class GameController implements IModelChangedListener, Parcelable {
} }
} }
/*public void registerGameErrorListener(IGameErrorListener l) {
if(!errorListeners.contains(l)) {
errorListeners.add(l);
}
}*/
public void removeGameSolvedListener(IGameSolvedListener l) { public void removeGameSolvedListener(IGameSolvedListener l) {
if(solvedListeners.contains(l)) { if(solvedListeners.contains(l)) {
solvedListeners.remove(l); solvedListeners.remove(l);

View file

@ -4,6 +4,8 @@ import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.util.Log; import android.util.Log;
import org.secuso.privacyfriendlysudoku.controller.helper.GameInfoContainer;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
@ -11,8 +13,6 @@ import java.io.IOException;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import org.secuso.privacyfriendlysudoku.controller.helper.GameInfoContainer;
/** /**
* Created by Chris on 16.11.2015. * Created by Chris on 16.11.2015.
*/ */
@ -86,9 +86,13 @@ public class GameStateManager {
gic.parseFixedValues(values[i++]); gic.parseFixedValues(values[i++]);
gic.parseSetValues(values[i++]); gic.parseSetValues(values[i++]);
gic.parseNotes(values[i++]); gic.parseNotes(values[i++]);
gic.parseHintsUsed(values[i++]);
} catch(IllegalArgumentException e) { } catch(IllegalArgumentException e) {
file.delete(); file.delete();
continue; continue;
} catch(IndexOutOfBoundsException e) {
file.delete();
continue;
} }
// then add it to the list // then add it to the list

View file

@ -2,8 +2,6 @@ package org.secuso.privacyfriendlysudoku.controller.helper;
import android.util.Log; import android.util.Log;
import java.util.Date;
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.game.GameCell; import org.secuso.privacyfriendlysudoku.game.GameCell;
@ -11,6 +9,8 @@ import org.secuso.privacyfriendlysudoku.game.GameDifficulty;
import org.secuso.privacyfriendlysudoku.game.GameType; import org.secuso.privacyfriendlysudoku.game.GameType;
import org.secuso.privacyfriendlysudoku.game.ICellAction; import org.secuso.privacyfriendlysudoku.game.ICellAction;
import java.util.Date;
/** /**
* Created by Chris on 17.11.2015. * Created by Chris on 17.11.2015.
*/ */
@ -24,12 +24,13 @@ public class GameInfoContainer {
int[] fixedValues; int[] fixedValues;
int[] setValues; int[] setValues;
boolean[][] setNotes; boolean[][] setNotes;
int hintsUsed;
public GameInfoContainer() {} public GameInfoContainer() {}
public GameInfoContainer(int ID, GameDifficulty difficulty, GameType gameType, int[] fixedValues, int[] setValues, boolean[][] setNotes) { public GameInfoContainer(int ID, GameDifficulty difficulty, GameType gameType, int[] fixedValues, int[] setValues, boolean[][] setNotes) {
this(ID, difficulty, new Date(), 0, gameType, fixedValues, setValues, setNotes); this(ID, difficulty, new Date(), 0, gameType, fixedValues, setValues, setNotes, 0);
} }
public GameInfoContainer(int ID, GameDifficulty difficulty, Date lastTimePlayed, int timePlayed, GameType gameType, int[] fixedValues, int[] setValues, boolean[][] setNotes) { public GameInfoContainer(int ID, GameDifficulty difficulty, Date lastTimePlayed, int timePlayed, GameType gameType, int[] fixedValues, int[] setValues, boolean[][] setNotes, int hintsUsed) {
this.ID = ID; this.ID = ID;
this.timePlayed = timePlayed; this.timePlayed = timePlayed;
this.difficulty = difficulty; this.difficulty = difficulty;
@ -38,6 +39,7 @@ public class GameInfoContainer {
this.fixedValues = fixedValues; this.fixedValues = fixedValues;
this.setValues = setValues; this.setValues = setValues;
this.setNotes = setNotes; this.setNotes = setNotes;
this.hintsUsed = hintsUsed;
} }
public void setID(int ID) { public void setID(int ID) {
@ -67,6 +69,14 @@ public class GameInfoContainer {
} }
} }
public void parseHintsUsed(String s) {
try {
this.hintsUsed = Integer.valueOf(s);
} catch(NumberFormatException e) {
throw new IllegalArgumentException("GameInfoContainer: Can not parse hints used.", e);
}
}
public void parseDate(String s) { public void parseDate(String s) {
try { try {
this.lastTimePlayed = new Date(Long.valueOf(s)); this.lastTimePlayed = new Date(Long.valueOf(s));
@ -130,7 +140,7 @@ public class GameInfoContainer {
throw new IllegalArgumentException("The string must be "+size+" characters long."); throw new IllegalArgumentException("The string must be "+size+" characters long.");
} }
for(int k = 0; k < strings[i].length(); k++) { for(int k = 0; k < strings[i].length(); k++) {
setNotes[i][k] = (strings[i].charAt(k)) == '1' ? true : false; setNotes[i][k] = (strings[i].charAt(k)) == '1';
} }
} }
} }
@ -159,6 +169,8 @@ public class GameInfoContainer {
return ID; return ID;
} }
public int getHintsUsed() { return hintsUsed; }
public static String getGameInfo(GameController controller) { public static String getGameInfo(GameController controller) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
Date today = new Date(); Date today = new Date();
@ -176,6 +188,8 @@ public class GameInfoContainer {
sb.append(getSetCells(controller)); sb.append(getSetCells(controller));
sb.append("/"); sb.append("/");
sb.append(getNotes(controller)); sb.append(getNotes(controller));
sb.append("/");
sb.append(controller.getUsedHints());
String result = sb.toString(); String result = sb.toString();

View file

@ -1,20 +1,16 @@
package org.secuso.privacyfriendlysudoku.ui.view; package org.secuso.privacyfriendlysudoku.ui.view;
import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.Gravity; import android.view.Gravity;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout; import android.widget.LinearLayout;
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.game.listener.IHighlightChangedListener; import org.secuso.privacyfriendlysudoku.game.listener.IHighlightChangedListener;
import org.w3c.dom.Text;
/** /**
* Created by TMZ_LToP on 12.11.2015. * Created by TMZ_LToP on 12.11.2015.
@ -37,8 +33,6 @@ public class SudokuKeyboardLayout extends LinearLayout implements IHighlightChan
SudokuButton btn = (SudokuButton)v; SudokuButton btn = (SudokuButton)v;
gameController.selectValue(btn.getValue()); gameController.selectValue(btn.getValue());
gameController.saveGame(getContext());
} }
} }
}; };

View file

@ -19,13 +19,14 @@ import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.Toast; import android.widget.Toast;
import java.util.LinkedList;
import org.secuso.privacyfriendlysudoku.controller.GameController; import org.secuso.privacyfriendlysudoku.controller.GameController;
import org.secuso.privacyfriendlysudoku.game.listener.IHighlightChangedListener; import org.secuso.privacyfriendlysudoku.game.listener.IHighlightChangedListener;
import org.secuso.privacyfriendlysudoku.ui.listener.IHintDialogFragmentListener; import org.secuso.privacyfriendlysudoku.ui.listener.IHintDialogFragmentListener;
import static org.secuso.privacyfriendlysudoku.ui.view.SudokuButtonType.*; import java.util.LinkedList;
import static org.secuso.privacyfriendlysudoku.ui.view.SudokuButtonType.Spacer;
import static org.secuso.privacyfriendlysudoku.ui.view.SudokuButtonType.getSpecialButtons;
/** /**
* Created by TMZ_LToP on 17.11.2015. * Created by TMZ_LToP on 17.11.2015.
@ -62,11 +63,9 @@ public class SudokuSpecialButtonLayout extends LinearLayout implements IHighligh
break; break;
case Do: case Do:
gameController.ReDo(); gameController.ReDo();
gameController.saveGame(getContext());
break; break;
case Undo: case Undo:
gameController.UnDo(); gameController.UnDo();
gameController.saveGame(getContext());
break; break;
case Hint: case Hint:
if(gameController.isValidCellSelected()) { if(gameController.isValidCellSelected()) {