Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
4062f43c40
@ -16,10 +16,12 @@ import javafx.stage.Stage;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Application starting point
|
||||
*/
|
||||
public class App extends Application {
|
||||
|
||||
private static LinkedList<String> argsList;
|
||||
public static HashMap<Player, ClientPlayer> playerList = new HashMap<>();
|
||||
private static Game game;
|
||||
private static ViewManager viewManager;
|
||||
|
||||
@ -48,36 +50,33 @@ public class App extends Application {
|
||||
}
|
||||
}
|
||||
|
||||
public static void startGame(ViewLambda lambda) throws IllegalArgumentException, InvocationTargetException, NoSuchMethodException,
|
||||
public static void startGame() throws IllegalArgumentException, InvocationTargetException, NoSuchMethodException,
|
||||
InstantiationException, IllegalAccessException {
|
||||
List<Player> players = parsePlayers();
|
||||
GridFactoryBuilder builder = LockGridFactoryBuilder.create().energyProbability(0.95F).wallProbability(0.80F).gridDimensions(12, 12);
|
||||
game = new Game(builder, players);
|
||||
for (Player player : game.getPlayers()) {
|
||||
playerList.put(player, new ClientPlayer(player, lambda.createViewLambda(player)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(Stage stage) {
|
||||
try {
|
||||
startGame(player -> new Window(stage, game, player));
|
||||
startGame();
|
||||
} catch (IllegalArgumentException | InvocationTargetException | NoSuchMethodException | InstantiationException
|
||||
| IllegalAccessException e) {
|
||||
throw new CrashException(e.getMessage(), e);
|
||||
}
|
||||
viewManager = new ViewManager(playerList, game, Window.class);
|
||||
viewManager = new ViewManager(game, Window.class, player -> new Window(stage, game, player));
|
||||
viewManager.run();
|
||||
}
|
||||
|
||||
public static void launchTerminal() {
|
||||
try {
|
||||
startGame(player -> new Terminal(game, player));
|
||||
startGame();
|
||||
} catch (IllegalArgumentException | InvocationTargetException | NoSuchMethodException | InstantiationException
|
||||
| IllegalAccessException e) {
|
||||
throw new CrashException(e.getMessage(), e);
|
||||
}
|
||||
viewManager = new ViewManager(playerList, game, Terminal.class);
|
||||
viewManager = new ViewManager(game, Terminal.class, player -> new Terminal(game, player));
|
||||
viewManager.run();
|
||||
}
|
||||
|
||||
|
@ -1,17 +1,29 @@
|
||||
package fr.lnl.game.client.view;
|
||||
|
||||
import fr.lnl.game.client.ClientPlayer;
|
||||
import fr.lnl.game.client.ViewLambda;
|
||||
import fr.lnl.game.client.listener.DisplayWinnerEvent;
|
||||
import fr.lnl.game.server.games.Game;
|
||||
import fr.lnl.game.server.games.player.HumanPlayer;
|
||||
import fr.lnl.game.server.games.player.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Objects;
|
||||
|
||||
public record ViewManager(
|
||||
HashMap<Player, ClientPlayer> players,
|
||||
Game game, Class<? extends View> viewType) {
|
||||
public final class ViewManager {
|
||||
private final Game game;
|
||||
private final Class<? extends View> viewType;
|
||||
|
||||
public ViewManager(Game game, Class<? extends View> viewType, ViewLambda lambda) {
|
||||
this.game = game;
|
||||
this.viewType = viewType;
|
||||
for (Player player : game.getPlayers()) {
|
||||
players.put(player, new ClientPlayer(player, lambda.createViewLambda(player)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public HashMap<Player, ClientPlayer> players = new HashMap<>();
|
||||
|
||||
public void updateView() {
|
||||
players.get(game.getCurrentPlayer()).getView().show();
|
||||
@ -24,11 +36,11 @@ public record ViewManager(
|
||||
System.out.println("\n\033[0;34m====== Tour n°" + game.getNbrTurn() + " =======\033[0m");
|
||||
System.out.println("\nA \033[0;31m" + player + " " + player.getId() + "\033[0m de jouer");
|
||||
players.get(game.getCurrentPlayer()).getView().show();
|
||||
if(game.getCurrentPlayer() instanceof HumanPlayer human) {
|
||||
if (game.getCurrentPlayer() instanceof HumanPlayer human) {
|
||||
game.setSelectedAction(((Terminal) players.get(human).getView()).choseAction());
|
||||
}
|
||||
boolean isOver = game.play();
|
||||
System.out.println("\n\033[0;31m" + player + " " + player.getId() + "\033[0m utilise l'action \033[0;36m"+
|
||||
System.out.println("\n\033[0;31m" + player + " " + player.getId() + "\033[0m utilise l'action \033[0;36m" +
|
||||
game.getSelectedAction().getClass().getSimpleName() + "\033[0m");
|
||||
if (isOver) {
|
||||
displayWinnerEvent.updateModel(game.getWinner());
|
||||
@ -48,4 +60,34 @@ public record ViewManager(
|
||||
updateView();
|
||||
}
|
||||
}
|
||||
|
||||
public Game game() {
|
||||
return game;
|
||||
}
|
||||
|
||||
public Class<? extends View> viewType() {
|
||||
return viewType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == this) return true;
|
||||
if (obj == null || obj.getClass() != this.getClass()) return false;
|
||||
var that = (ViewManager) obj;
|
||||
return Objects.equals(this.game, that.game) &&
|
||||
Objects.equals(this.viewType, that.viewType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(game, viewType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ViewManager[" +
|
||||
"game=" + game + ", " +
|
||||
"viewType=" + viewType + ']';
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,3 +1,6 @@
|
||||
/**
|
||||
* Client module, include every view and controller classes from MVC model
|
||||
*/
|
||||
module client {
|
||||
requires javafx.controls;
|
||||
requires transitive javafx.graphics;
|
||||
|
Loading…
Reference in New Issue
Block a user