Added an IGameSolvedListener. The GameActivity now listens for it.

This commit is contained in:
Christopher Beckmann 2015-11-19 14:38:41 +01:00
parent 643c45070f
commit 86581ffd8e
7 changed files with 47 additions and 11 deletions

View file

@ -15,7 +15,8 @@ import tu_darmstadt.sudoku.controller.helper.GameInfoContainer;
import tu_darmstadt.sudoku.game.GameDifficulty; import tu_darmstadt.sudoku.game.GameDifficulty;
import tu_darmstadt.sudoku.game.GameType; import tu_darmstadt.sudoku.game.GameType;
import tu_darmstadt.sudoku.game.ICellAction; import tu_darmstadt.sudoku.game.ICellAction;
import tu_darmstadt.sudoku.game.IModelChangedListener; import tu_darmstadt.sudoku.game.listeners.IGameSolvedListener;
import tu_darmstadt.sudoku.game.listeners.IModelChangedListener;
/** /**
* Created by Chris on 06.11.2015. * Created by Chris on 06.11.2015.
@ -35,7 +36,7 @@ public class GameController implements IModelChangedListener {
private int gameID = 0; private int gameID = 0;
private CellConflictList errorList = new CellConflictList(); private CellConflictList errorList = new CellConflictList();
private int selectedValue; private int selectedValue;
//private LinkedList<IModelChangeListener> listeners = new LinkedList<>(); private LinkedList<IGameSolvedListener> solvedListeners = new LinkedList<>();
// private Solver solver; // private Solver solver;
// private SudokuGenerator generator; // private SudokuGenerator generator;
@ -396,7 +397,7 @@ public class GameController implements IModelChangedListener {
if(gameBoard.isFilled()) { if(gameBoard.isFilled()) {
List<CellConflict> errorList = new LinkedList<>(); List<CellConflict> errorList = new LinkedList<>();
if(gameBoard.isSolved(errorList)) { if(gameBoard.isSolved(errorList)) {
// TODO: WE WON! :D notifySolvedListeners();
} else { } else {
// TODO: errorList now holds all the errors // TODO: errorList now holds all the errors
// TODO: display errors .. notify some view? // TODO: display errors .. notify some view?
@ -404,9 +405,21 @@ public class GameController implements IModelChangedListener {
} }
} }
// public void notifyListeners() { public void registerGameSolvedListener(IGameSolvedListener l) {
// for(IModelChangeListener l : listeners) { if(!solvedListeners.contains(l)) {
// l.onModelChanged(); solvedListeners.add(l);
// } }
// } }
public void removeGameSolvedListener(IGameSolvedListener l) {
if(solvedListeners.contains(l)) {
solvedListeners.remove(l);
}
}
public void notifySolvedListeners() {
for(IGameSolvedListener l : solvedListeners) {
l.onSolved();
}
}
} }

View file

@ -3,6 +3,8 @@ package tu_darmstadt.sudoku.game;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import tu_darmstadt.sudoku.game.listeners.IModelChangedListener;
/** /**
* Created by Christopher Beckmann on 06.11.2015. * Created by Christopher Beckmann on 06.11.2015.
*/ */

View file

@ -4,6 +4,8 @@ import java.util.Arrays;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import tu_darmstadt.sudoku.game.listeners.IModelChangedListener;
/** /**
* Created by Chris on 06.11.2015. * Created by Chris on 06.11.2015.
*/ */

View file

@ -0,0 +1,11 @@
package tu_darmstadt.sudoku.game.listeners;
import tu_darmstadt.sudoku.controller.GameController;
import tu_darmstadt.sudoku.game.GameBoard;
/**
* Created by Chris on 19.11.2015.
*/
public interface IGameSolvedListener {
public void onSolved();
}

View file

@ -1,4 +1,6 @@
package tu_darmstadt.sudoku.game; package tu_darmstadt.sudoku.game.listeners;
import tu_darmstadt.sudoku.game.GameCell;
/** /**
* Created by Chris on 19.11.2015. * Created by Chris on 19.11.2015.

View file

@ -22,13 +22,14 @@ import tu_darmstadt.sudoku.controller.SaveLoadController;
import tu_darmstadt.sudoku.controller.GameController; import tu_darmstadt.sudoku.controller.GameController;
import tu_darmstadt.sudoku.controller.helper.GameInfoContainer; import tu_darmstadt.sudoku.controller.helper.GameInfoContainer;
import tu_darmstadt.sudoku.game.GameType; import tu_darmstadt.sudoku.game.GameType;
import tu_darmstadt.sudoku.game.listeners.IGameSolvedListener;
import tu_darmstadt.sudoku.ui.view.R; import tu_darmstadt.sudoku.ui.view.R;
import tu_darmstadt.sudoku.ui.view.SudokuFieldLayout; import tu_darmstadt.sudoku.ui.view.SudokuFieldLayout;
import tu_darmstadt.sudoku.ui.view.SudokuKeyboardLayout; import tu_darmstadt.sudoku.ui.view.SudokuKeyboardLayout;
import tu_darmstadt.sudoku.ui.view.SudokuSpecialButtonLayout; import tu_darmstadt.sudoku.ui.view.SudokuSpecialButtonLayout;
import tu_darmstadt.sudoku.ui.view.SudokuTimer; import tu_darmstadt.sudoku.ui.view.SudokuTimer;
public class GameActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener { public class GameActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener, IGameSolvedListener {
GameController gameController; GameController gameController;
SudokuFieldLayout layout; SudokuFieldLayout layout;
@ -71,6 +72,7 @@ public class GameActivity extends AppCompatActivity implements NavigationView.On
//Create new GameField //Create new GameField
layout = (SudokuFieldLayout)findViewById(R.id.sudokuLayout); layout = (SudokuFieldLayout)findViewById(R.id.sudokuLayout);
gameController = new GameController(sharedPref); gameController = new GameController(sharedPref);
gameController.registerGameSolvedListener(this);
List<GameInfoContainer> loadableGames = SaveLoadController.getLoadableGameList(); List<GameInfoContainer> loadableGames = SaveLoadController.getLoadableGameList();
@ -223,4 +225,9 @@ public class GameActivity extends AppCompatActivity implements NavigationView.On
drawer.closeDrawer(GravityCompat.START); drawer.closeDrawer(GravityCompat.START);
return true; return true;
} }
@Override
public void onSolved() {
// TODO: WE WON.. do something awesome :)
}
} }

View file

@ -12,7 +12,6 @@ import android.widget.RelativeLayout;
import tu_darmstadt.sudoku.game.GameCell; import tu_darmstadt.sudoku.game.GameCell;
import tu_darmstadt.sudoku.controller.Symbol; import tu_darmstadt.sudoku.controller.Symbol;
import tu_darmstadt.sudoku.game.IModelChangedListener;
/** /**
* Created by TMZ_LToP on 10.11.2015. * Created by TMZ_LToP on 10.11.2015.