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.difficulty = gic.getDifficulty();
this.time = gic.getTimePlayed();
this.usedHints = gic.getHintsUsed();
setGameType(gic.getGameType());
this.gameBoard = new GameBoard(gic.getGameType());
@ -472,7 +473,6 @@ public class GameController implements IModelChangedListener, Parcelable {
undoRedoManager.addState(gameBoard);
notifyHighlightChangedListeners();
}
}
public void toggleSelectedCellsNote(int value) {
@ -487,12 +487,6 @@ public class GameController implements IModelChangedListener, Parcelable {
return selectedRow != -1 && selectedCol != -1 && !getGameCell(selectedRow, selectedCol).isFixed();
}
// public void registerListener(IModelChangeListener l) {
// if(!listeners.contains(l)) {
// listeners.add(l);
// }
// }
public int getSectionHeight() {
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) {
if(solvedListeners.contains(l)) {
solvedListeners.remove(l);

View file

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

View file

@ -2,8 +2,6 @@ package org.secuso.privacyfriendlysudoku.controller.helper;
import android.util.Log;
import java.util.Date;
import org.secuso.privacyfriendlysudoku.controller.GameController;
import org.secuso.privacyfriendlysudoku.controller.Symbol;
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.ICellAction;
import java.util.Date;
/**
* Created by Chris on 17.11.2015.
*/
@ -24,12 +24,13 @@ public class GameInfoContainer {
int[] fixedValues;
int[] setValues;
boolean[][] setNotes;
int hintsUsed;
public GameInfoContainer() {}
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.timePlayed = timePlayed;
this.difficulty = difficulty;
@ -38,6 +39,7 @@ public class GameInfoContainer {
this.fixedValues = fixedValues;
this.setValues = setValues;
this.setNotes = setNotes;
this.hintsUsed = hintsUsed;
}
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) {
try {
this.lastTimePlayed = new Date(Long.valueOf(s));
@ -130,7 +140,7 @@ public class GameInfoContainer {
throw new IllegalArgumentException("The string must be "+size+" characters long.");
}
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;
}
public int getHintsUsed() { return hintsUsed; }
public static String getGameInfo(GameController controller) {
StringBuilder sb = new StringBuilder();
Date today = new Date();
@ -176,6 +188,8 @@ public class GameInfoContainer {
sb.append(getSetCells(controller));
sb.append("/");
sb.append(getNotes(controller));
sb.append("/");
sb.append(controller.getUsedHints());
String result = sb.toString();

View file

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

View file

@ -19,13 +19,14 @@ import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;
import java.util.LinkedList;
import org.secuso.privacyfriendlysudoku.controller.GameController;
import org.secuso.privacyfriendlysudoku.game.listener.IHighlightChangedListener;
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.
@ -62,11 +63,9 @@ public class SudokuSpecialButtonLayout extends LinearLayout implements IHighligh
break;
case Do:
gameController.ReDo();
gameController.saveGame(getContext());
break;
case Undo:
gameController.UnDo();
gameController.saveGame(getContext());
break;
case Hint:
if(gameController.isValidCellSelected()) {