ErrorList is now updated when the field is updated.

This commit is contained in:
Christopher Beckmann 2016-02-03 20:14:13 +01:00
parent ad4eb476f9
commit 6e96ee8904
3 changed files with 23 additions and 10 deletions

View file

@ -14,7 +14,6 @@ import org.secuso.privacyfriendlysudoku.game.GameCell;
import org.secuso.privacyfriendlysudoku.game.GameDifficulty;
import org.secuso.privacyfriendlysudoku.game.GameType;
import org.secuso.privacyfriendlysudoku.game.ICellAction;
import org.secuso.privacyfriendlysudoku.game.listener.IGameErrorListener;
import org.secuso.privacyfriendlysudoku.game.listener.IGameSolvedListener;
import org.secuso.privacyfriendlysudoku.game.listener.IHighlightChangedListener;
import org.secuso.privacyfriendlysudoku.game.listener.IHintListener;
@ -45,7 +44,6 @@ public class GameController implements IModelChangedListener, Parcelable {
private LinkedList<IHighlightChangedListener> highlightListeners = new LinkedList<>();
private LinkedList<IGameSolvedListener> solvedListeners = new LinkedList<>();
private LinkedList<IHintListener> hintListener = new LinkedList<>();
private LinkedList<IGameErrorListener> errorListeners = new LinkedList<>();
private boolean notifiedOnSolvedListeners = false;
// Game
@ -207,7 +205,6 @@ public class GameController implements IModelChangedListener, Parcelable {
public void setValue(int row, int col, int value) {
GameCell cell = gameBoard.getCell(row, col);
if (!cell.isFixed() && isValidNumber(value)) {
cell.deleteNotes();
cell.setValue(value);
if(settings != null && settings.getBoolean("pref_automatic_note_deletion",true)) {
@ -323,7 +320,6 @@ public class GameController implements IModelChangedListener, Parcelable {
if(!c.isFixed()) {
c.setValue(0);
//notifyListeners();
return true;
}
return false;
@ -507,6 +503,9 @@ public class GameController implements IModelChangedListener, Parcelable {
@Override
public void onModelChange(GameCell c) {
checkErrorList();
if(gameBoard.isFilled()) {
errorList = new CellConflictList();
if(gameBoard.isSolved(errorList)) {
@ -525,6 +524,16 @@ public class GameController implements IModelChangedListener, Parcelable {
}
}
public void checkErrorList() {
LinkedList<CellConflict> toRemove = new LinkedList<>();
for(CellConflict cc : errorList) {
if(cc.getCell1().getValue() != cc.getCell2().getValue()) {
toRemove.add(cc);
}
}
errorList.removeAll(toRemove);
}
public void resetSelects() {
selectedCol = -1;
selectedRow = -1;
@ -774,7 +783,6 @@ public class GameController implements IModelChangedListener, Parcelable {
solvedListeners = new LinkedList<>();
hintListener = new LinkedList<>();
timerListeners = new LinkedList<>();
errorListeners = new LinkedList<>();
}
public void setContextAndSettings(Context applicationContext, SharedPreferences sharedPref) {

View file

@ -27,6 +27,8 @@ public class CellConflict implements Parcelable {
return c2.getCol();
}
public GameCell getCell1() { return c1; }
public GameCell getCell2() { return c2; }
public CellConflict(GameCell first, GameCell second) {
c1 = first;

View file

@ -28,11 +28,8 @@ import android.widget.LinearLayout;
import android.widget.RatingBar;
import android.widget.TextView;
import java.util.LinkedList;
import java.util.List;
import org.secuso.privacyfriendlysudoku.controller.GameStateManager;
import org.secuso.privacyfriendlysudoku.controller.GameController;
import org.secuso.privacyfriendlysudoku.controller.GameStateManager;
import org.secuso.privacyfriendlysudoku.controller.SaveLoadStatistics;
import org.secuso.privacyfriendlysudoku.controller.Symbol;
import org.secuso.privacyfriendlysudoku.controller.helper.GameInfoContainer;
@ -42,11 +39,14 @@ import org.secuso.privacyfriendlysudoku.game.listener.IGameSolvedListener;
import org.secuso.privacyfriendlysudoku.game.listener.ITimerListener;
import org.secuso.privacyfriendlysudoku.ui.listener.IHintDialogFragmentListener;
import org.secuso.privacyfriendlysudoku.ui.listener.IResetDialogFragmentListener;
import org.secuso.privacyfriendlysudoku.ui.view.WinDialog;
import org.secuso.privacyfriendlysudoku.ui.view.R;
import org.secuso.privacyfriendlysudoku.ui.view.SudokuFieldLayout;
import org.secuso.privacyfriendlysudoku.ui.view.SudokuKeyboardLayout;
import org.secuso.privacyfriendlysudoku.ui.view.SudokuSpecialButtonLayout;
import org.secuso.privacyfriendlysudoku.ui.view.WinDialog;
import java.util.LinkedList;
import java.util.List;
public class GameActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener, IGameSolvedListener ,ITimerListener, IHintDialogFragmentListener, IResetDialogFragmentListener {
@ -184,6 +184,9 @@ public class GameActivity extends AppCompatActivity implements NavigationView.On
gameController.notifyHighlightChangedListeners();
gameController.notifyTimerListener(gameController.getTime());
// run this so the error list gets build again.
gameController.onModelChange(null);
}
@Override