Added an IGameSolvedListener. The GameActivity now listens for it.
This commit is contained in:
parent
643c45070f
commit
86581ffd8e
7 changed files with 47 additions and 11 deletions
|
@ -15,7 +15,8 @@ import tu_darmstadt.sudoku.controller.helper.GameInfoContainer;
|
|||
import tu_darmstadt.sudoku.game.GameDifficulty;
|
||||
import tu_darmstadt.sudoku.game.GameType;
|
||||
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.
|
||||
|
@ -35,7 +36,7 @@ public class GameController implements IModelChangedListener {
|
|||
private int gameID = 0;
|
||||
private CellConflictList errorList = new CellConflictList();
|
||||
private int selectedValue;
|
||||
//private LinkedList<IModelChangeListener> listeners = new LinkedList<>();
|
||||
private LinkedList<IGameSolvedListener> solvedListeners = new LinkedList<>();
|
||||
|
||||
// private Solver solver;
|
||||
// private SudokuGenerator generator;
|
||||
|
@ -396,7 +397,7 @@ public class GameController implements IModelChangedListener {
|
|||
if(gameBoard.isFilled()) {
|
||||
List<CellConflict> errorList = new LinkedList<>();
|
||||
if(gameBoard.isSolved(errorList)) {
|
||||
// TODO: WE WON! :D
|
||||
notifySolvedListeners();
|
||||
} else {
|
||||
// TODO: errorList now holds all the errors
|
||||
// TODO: display errors .. notify some view?
|
||||
|
@ -404,9 +405,21 @@ public class GameController implements IModelChangedListener {
|
|||
}
|
||||
}
|
||||
|
||||
// public void notifyListeners() {
|
||||
// for(IModelChangeListener l : listeners) {
|
||||
// l.onModelChanged();
|
||||
// }
|
||||
// }
|
||||
public void registerGameSolvedListener(IGameSolvedListener l) {
|
||||
if(!solvedListeners.contains(l)) {
|
||||
solvedListeners.add(l);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeGameSolvedListener(IGameSolvedListener l) {
|
||||
if(solvedListeners.contains(l)) {
|
||||
solvedListeners.remove(l);
|
||||
}
|
||||
}
|
||||
|
||||
public void notifySolvedListeners() {
|
||||
for(IGameSolvedListener l : solvedListeners) {
|
||||
l.onSolved();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@ package tu_darmstadt.sudoku.game;
|
|||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import tu_darmstadt.sudoku.game.listeners.IModelChangedListener;
|
||||
|
||||
/**
|
||||
* Created by Christopher Beckmann on 06.11.2015.
|
||||
*/
|
||||
|
|
|
@ -4,6 +4,8 @@ import java.util.Arrays;
|
|||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import tu_darmstadt.sudoku.game.listeners.IModelChangedListener;
|
||||
|
||||
/**
|
||||
* Created by Chris on 06.11.2015.
|
||||
*/
|
||||
|
|
|
@ -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();
|
||||
}
|
|
@ -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.
|
|
@ -22,13 +22,14 @@ import tu_darmstadt.sudoku.controller.SaveLoadController;
|
|||
import tu_darmstadt.sudoku.controller.GameController;
|
||||
import tu_darmstadt.sudoku.controller.helper.GameInfoContainer;
|
||||
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.SudokuFieldLayout;
|
||||
import tu_darmstadt.sudoku.ui.view.SudokuKeyboardLayout;
|
||||
import tu_darmstadt.sudoku.ui.view.SudokuSpecialButtonLayout;
|
||||
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;
|
||||
SudokuFieldLayout layout;
|
||||
|
@ -71,6 +72,7 @@ public class GameActivity extends AppCompatActivity implements NavigationView.On
|
|||
//Create new GameField
|
||||
layout = (SudokuFieldLayout)findViewById(R.id.sudokuLayout);
|
||||
gameController = new GameController(sharedPref);
|
||||
gameController.registerGameSolvedListener(this);
|
||||
|
||||
List<GameInfoContainer> loadableGames = SaveLoadController.getLoadableGameList();
|
||||
|
||||
|
@ -223,4 +225,9 @@ public class GameActivity extends AppCompatActivity implements NavigationView.On
|
|||
drawer.closeDrawer(GravityCompat.START);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSolved() {
|
||||
// TODO: WE WON.. do something awesome :)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,6 @@ import android.widget.RelativeLayout;
|
|||
|
||||
import tu_darmstadt.sudoku.game.GameCell;
|
||||
import tu_darmstadt.sudoku.controller.Symbol;
|
||||
import tu_darmstadt.sudoku.game.IModelChangedListener;
|
||||
|
||||
/**
|
||||
* Created by TMZ_LToP on 10.11.2015.
|
||||
|
|
Loading…
Reference in a new issue