Skip to content

Commit

Permalink
changed initial workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Triikk committed Feb 17, 2024
1 parent e70e53f commit b194f17
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
5 changes: 5 additions & 0 deletions src/main/java/it/unibo/controller/main/MainController.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
*/
public interface MainController {

/**
* Starts the application view.
*/
void start();

/**
* Build a city in the given position.
*
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/it/unibo/controller/main/MainControllerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import it.unibo.model.GameManagerImpl;
import it.unibo.model.player.Player;
import it.unibo.view.app.AppView;
import it.unibo.view.app.AppViewImpl;

/**
* Main controller implementation.
Expand All @@ -47,8 +48,7 @@ public final class MainControllerImpl implements MainController {
* @param appView the main view
* @param players list of players' names
*/
public MainControllerImpl(final AppView appView, final List<String> players) {
this.appView = appView;
public MainControllerImpl(final List<String> players) {
this.gameManager = new GameManagerImpl(players);

this.getPlayerByName = name -> gameManager.getPlayers().stream().filter(p -> p.getName().equals(name))
Expand All @@ -59,6 +59,13 @@ public MainControllerImpl(final AppView appView, final List<String> players) {
this.gameManager.getPropertyManager(), this.gameManager.getRoadManager());
this.resourceController = new ResourceControllerImpl(getPlayerByName, gameManager.getResourceManager());
this.turnController = new TurnControllerImpl(gameManager.getTurnManager());

this.appView = new AppViewImpl(this);
}

@Override
public void start() {
appView.draw();
}

@Override
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/it/unibo/view/app/AppViewImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import it.unibo.controller.main.MainController;
import it.unibo.controller.main.MainControllerImpl;
import it.unibo.view.board.BoardView;
import it.unibo.view.log.LogView;
import it.unibo.view.player.CurrentPlayerView;
Expand Down Expand Up @@ -45,11 +44,11 @@ public final class AppViewImpl implements AppView {
* @param players the list of players names
*/
@SuppressFBWarnings(value = "EI_EXPOSE_REP2", justification = "The stage needs to be updated")
public AppViewImpl(final Stage stage, final List<String> players) {
this.controller = new MainControllerImpl(this, players);
public AppViewImpl(final MainController controller) {
this.controller = controller;
final var colors = List.of(Color.RED, Color.ORANGE, Color.LIMEGREEN, Color.MAGENTA);
controller.getPlayerNames().stream().forEach(p -> playerColors.put(p, colors.get(playerColors.size())));
this.stage = stage;
this.stage = new Stage();
boardView = new BoardView(controller, playerColors);
bankView = new BankView(controller);
playersView = new PlayersView(controller, playerColors);
Expand All @@ -61,8 +60,8 @@ public AppViewImpl(final Stage stage, final List<String> players) {
public void draw() {
stage.setTitle("I Coloni di Cesena");
stage.setScene(getScene());
// stage.setMaximized(true);
// stage.show();
stage.setMaximized(true);
stage.show();
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/it/unibo/view/app/StartMenuView.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import java.io.IOException;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import it.unibo.controller.main.MainController;
import it.unibo.controller.main.MainControllerImpl;

/**
* Application.
Expand Down Expand Up @@ -107,7 +109,9 @@ public Scene getScene() {

playButton.setOnMouseClicked(e -> {
if (players.size() >= 1) {
new AppViewImpl(stage, players).draw();
final MainController controller = new MainControllerImpl(players);
controller.start();
this.stage.close();
} else {
popUp.setHeaderText("You need at least one player to start the game");
popUp.showAndWait();
Expand Down

0 comments on commit b194f17

Please sign in to comment.