|
|
@ -1,5 +1,6 @@ |
|
|
|
package de.hsfulda.onses.controllers; |
|
|
|
|
|
|
|
import de.hsfulda.onses.App; |
|
|
|
import de.hsfulda.onses.Main; |
|
|
|
import de.hsfulda.onses.models.Card; |
|
|
|
import de.hsfulda.onses.models.Game; |
|
|
@ -9,13 +10,21 @@ import javafx.scene.Parent; |
|
|
|
import javafx.scene.control.Button; |
|
|
|
import javafx.scene.layout.Pane; |
|
|
|
|
|
|
|
import java.beans.PropertyChangeEvent; |
|
|
|
import java.io.IOException; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Objects; |
|
|
|
|
|
|
|
public class GameController implements Controller { |
|
|
|
private final GameService gameService; |
|
|
|
private final Game game; |
|
|
|
public GameController(GameService gameService) { |
|
|
|
private final App app; |
|
|
|
|
|
|
|
private PropertyChangeEvent lastPlayedCardPropertyChangeEvent; |
|
|
|
|
|
|
|
private final ArrayList<Controller> controllers = new ArrayList<>(); |
|
|
|
public GameController(App app, GameService gameService) { |
|
|
|
this.app = app; |
|
|
|
this.gameService = gameService; |
|
|
|
this.game = gameService.getGame(); |
|
|
|
} |
|
|
@ -27,20 +36,31 @@ public class GameController implements Controller { |
|
|
|
final Pane playerPane = (Pane) parent.lookup("#playerPane"); |
|
|
|
final Button playButton = (Button) parent.lookup("#playCardBtn"); |
|
|
|
final Button drawCardButton = (Button) parent.lookup("#drawCardBtn"); |
|
|
|
final Button exitGameButton = (Button) parent.lookup("#exitBtn"); |
|
|
|
|
|
|
|
CardController lastPlayedCardController = new CardController(game.getLastPlayedCard(), null); |
|
|
|
PlayerController playerController = new PlayerController(gameService.getGame().getPlayerService().getPlayerList().getFirst()); |
|
|
|
PlayerController enemyController = new PlayerController(gameService.getGame().getPlayerService().getPlayerList().getLast()); |
|
|
|
|
|
|
|
controllers.add(lastPlayedCardController); |
|
|
|
controllers.add(playerController); |
|
|
|
controllers.add(enemyController); |
|
|
|
|
|
|
|
game.listeners().addPropertyChangeListener(Game.PROPERTY_LAST_PLAYED_CARD, e -> { |
|
|
|
lastPlayedCardPane.getChildren().removeAll(); |
|
|
|
try { |
|
|
|
lastPlayedCardPane.getChildren().add(new CardController((Card) e.getNewValue(), null).render()); |
|
|
|
CardController tmp = new CardController((Card) e.getNewValue(), null); |
|
|
|
controllers.add(tmp); |
|
|
|
lastPlayedCardPane.getChildren().add(tmp.render()); |
|
|
|
} catch (IOException ex) { |
|
|
|
throw new RuntimeException(ex); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
exitGameButton.setOnAction(e -> { |
|
|
|
app.show(new AppController(app, new GameService())); |
|
|
|
}); |
|
|
|
|
|
|
|
playButton.setOnAction(e -> { |
|
|
|
Card cardToPlay = game.getPlayerService().getPlayerList().getFirst().getCurrentCard(); |
|
|
|
if(gameService.legalMove(cardToPlay)) { |
|
|
@ -70,6 +90,11 @@ public class GameController implements Controller { |
|
|
|
|
|
|
|
@Override |
|
|
|
public void destroy() { |
|
|
|
int i = 0; |
|
|
|
|
|
|
|
while(i < controllers.size()) { |
|
|
|
Controller controller = controllers.get(i++); |
|
|
|
controller.destroy(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |