Commit 68c1e43e authored by Anders H. Rebner's avatar Anders H. Rebner
Browse files

Players pieces are removed after leaving

parent 90e3681b
......@@ -97,8 +97,9 @@ public class GameController {
// External player left midgame (called by CLobbyLeave command)
public void setPlayerLeftMidGame(int playerId) {
System.out.println("Player with id " + playerId + " left");
model.setPlayerLeftMidGame(playerId);
// Tell the model that the player left. Tell view to remove those pieces
List<Vector3> removedPieceCoordinates = model.setPlayerLeftMidGame(playerId);
this.view.removePieces(removedPieceCoordinates);
setPlayerFinished(playerId, -1);
this.view.placeTurnIndicator(playerNameTextFieldCoordinates.get(model.getPlayerTurnSlot()));
}
......
......@@ -126,11 +126,12 @@ class Game(gameState: GameState, playerIds: LinkedHashSet<Int>) {
return gameState.getRules().getPlayerNameCoordinates(hex_side_length)
}
fun setPlayerLeftMidGame(playerId: Int) {
fun setPlayerLeftMidGame(playerId: Int): List<Vector3> {
playerLeftIds = playerLeftIds + playerId
if (playerTurnId == playerId) {
nextPlayer()
}
return this.gameState.getBoardState().playerLeftMidGame(playerId)
}
private fun thereArePlayersLeft(): Boolean {
......
......@@ -11,4 +11,20 @@ abstract class AbstractBoard {
abstract fun placePiecesAtStart(rules: AbstractRules, playerIds: HashSet<Int>) // Places pieces at startfields
abstract fun movePiece(fromCoordinates: Vector3, toCoordinates: Vector3): Boolean // Moves piece
abstract fun getBoardImagePath(): String // Returns path to board image
fun playerLeftMidGame(playerId: Int): List<Vector3> { // Removes a players pieces and returns their coordinates
var removedPieces: List<Vector3> = listOf()
// Get coordinates of pleyers pieces
for (coordinate: Vector3 in fields.keys) {
if (fields[coordinate]?.getPiece()?.getOwnerId() == playerId) {
removedPieces = removedPieces + coordinate
}
}
// Remove piece from fields
for (coordinate: Vector3 in removedPieces) {
fields[coordinate]?.removePiece()
}
return removedPieces
}
}
\ No newline at end of file
......@@ -366,6 +366,12 @@ public class PlayView extends AbstractView {
pieces.put(toCoordinates, pieces.remove(fromCoordinates));
}
public void removePieces(List<Vector3> coordinates) {
for (Vector3 coordinate : coordinates) {
pieces.remove(coordinate);
}
}
private void debugDraw(SpriteBatch sb, String text, int xPos, int yPos){
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment