Skip to content

Commit

Permalink
Merge pull request #13 from youssefouru/bonus
Browse files Browse the repository at this point in the history
Bonus
  • Loading branch information
youssefouru authored May 31, 2021
2 parents a110ad1 + 215e2c5 commit e697775
Show file tree
Hide file tree
Showing 16 changed files with 25 additions and 24 deletions.
4 changes: 2 additions & 2 deletions Test/ch/epfl/tchu/gui/Client2.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public void start(Stage primaryStage) throws Exception {
String instructionSocketName = (parameters.isEmpty() || parameters.size() == 1) ?DEFAULT_HOST_NAME: parameters.get(i++);
int instructionSocketPort = parameters.isEmpty() ? DEFAULT_PORT : Integer.parseInt(parameters.get(i));
Socket messageSocket = new Socket(instructionSocketName,instructionSocketPort);
//AdvancedPlayer graphicalPlayer =new GraphicalPlayerAdapter(messageSocket);
RemotePlayerClient client = new RemotePlayerClient(new GameTest2.TestPlayer(5108, ChMap.routes()), instructionSocketName, instructionSocketPort,messageSocket);
AdvancedPlayer graphicalPlayer =new GraphicalPlayerAdapter(messageSocket);
RemotePlayerClient client = new RemotePlayerClient(graphicalPlayer, instructionSocketName, instructionSocketPort,messageSocket);
new Thread(client::run).start();
new Thread(client::manageMessages).start();
}
Expand Down
Binary file modified out/artifacts/tCHu_jar/tCHu.jar
Binary file not shown.
Binary file modified out/production/tCHu/ch/epfl/tchu/game/Game$1.class
Binary file not shown.
Binary file modified out/production/tCHu/ch/epfl/tchu/game/Game.class
Binary file not shown.
Binary file modified out/production/tCHu/ch/epfl/tchu/gui/GraphicalPlayer.class
Binary file not shown.
Binary file modified out/production/tCHu/ch/epfl/tchu/gui/Info.class
Binary file not shown.
Binary file modified out/production/tCHu/ch/epfl/tchu/gui/MenuController.class
Binary file not shown.
Binary file modified out/production/tCHu/ch/epfl/tchu/gui/MenuMain.class
Binary file not shown.
Binary file modified out/production/tCHu/ch/epfl/tchu/gui/ObservableGameState.class
Binary file not shown.
Binary file modified out/test/tCHu/ch/epfl/tchu/game/GameTest2.class
Binary file not shown.
Binary file modified out/test/tCHu/ch/epfl/tchu/gui/Client2.class
Binary file not shown.
25 changes: 12 additions & 13 deletions src/ch/epfl/tchu/game/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import ch.epfl.tchu.SortedBag;
import ch.epfl.tchu.gui.Info;

import javax.swing.*;
import java.util.*;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -33,7 +32,7 @@ private Game() {
* @param tickets (SortedBag<Ticket>) : the initial tickets of the game
* @param rng (Random) : the random object which is used several times in this method
*/
public static void play(Map<PlayerId,? extends Player> players, Map<PlayerId, String> playerNames, SortedBag<Ticket> tickets, Random rng) {
public static void play(Map<PlayerId, ? extends Player> players, Map<PlayerId, String> playerNames, SortedBag<Ticket> tickets, Random rng) {
Preconditions.checkArgument(players.size() == COUNT && playerNames.size() == COUNT);
GameState gameState = GameState.initial(tickets, rng);
players.forEach(((playerId, player) -> player.initPlayers(playerId, playerNames)));
Expand Down Expand Up @@ -70,7 +69,7 @@ public static void play(Map<PlayerId,? extends Player> players, Map<PlayerId, St
transmitInfo(players, currentPlayerInfo.canPlay());
switch (currentPlayer.nextTurn()) {
case DRAW_TICKETS:
int ticketsDrawn = Math.min(Constants.IN_GAME_TICKETS_COUNT,gameState.ticketsCount());
int ticketsDrawn = Math.min(Constants.IN_GAME_TICKETS_COUNT, gameState.ticketsCount());
SortedBag<Ticket> drawnTickets = gameState.topTickets(ticketsDrawn);
transmitInfo(players, currentPlayerInfo.drewTickets(ticketsDrawn));
SortedBag<Ticket> chosenTickets = currentPlayer.chooseTickets(drawnTickets);
Expand Down Expand Up @@ -163,19 +162,19 @@ public static void play(Map<PlayerId,? extends Player> players, Map<PlayerId, St
int bonus = playerTheLongestTrails.contains(playerId) ? Constants.LONGEST_TRAIL_BONUS_POINTS : 0;
mapPoints.put(playerId, gameState.playerState(playerId).finalPoints() + bonus);
if (bonus == Constants.LONGEST_TRAIL_BONUS_POINTS) {
Trail maximalTrail =mapOfTrails.get(playerId);
notifyLongest(players,maximalTrail);
Trail maximalTrail = mapOfTrails.get(playerId);
notifyLongest(players, maximalTrail);
transmitInfo(players, playersInfos.get(playerId).getsLongestTrailBonus(maximalTrail));
}
}

List<PlayerId> listOfPlayer = maxPoints(mapPoints);
PlayerId winner = listOfPlayer.get(0);
List<Integer> loserPoints = PlayerId.ALL.
stream().
filter(playerId -> !listOfPlayer.contains(playerId)).
map(mapPoints::get).
collect(Collectors.toList());
stream().
filter(playerId -> !listOfPlayer.contains(playerId)).
map(mapPoints::get).
collect(Collectors.toList());
if (listOfPlayer.size() == 1) {
int winnerPoint = mapPoints.get(winner);
transmitInfo(players, playersInfos.get(listOfPlayer.get(0)).won(winnerPoint, loserPoints));
Expand All @@ -191,17 +190,17 @@ public static void play(Map<PlayerId,? extends Player> players, Map<PlayerId, St
}


private static void transmitInfo(Map<PlayerId,? extends Player> map, String info) {
private static void transmitInfo(Map<PlayerId, ? extends Player> map, String info) {
map.forEach(((playerId, player) -> player.receiveInfo(info)));
}

private static void updateStates(Map<PlayerId,? extends Player> map, GameState gameState) {
private static void updateStates(Map<PlayerId, ? extends Player> map, GameState gameState) {
map.forEach(((playerId, player) -> player.updateState(gameState, gameState.playerState(playerId))));

}

private static void notifyLongest(Map<PlayerId, ? extends Player> map, Trail trail){
map.forEach(((playerId, player) -> player.notifyLongest(trail.routes())));
private static void notifyLongest(Map<PlayerId, ? extends Player> map, Trail trail) {
map.forEach(((playerId, player) -> player.notifyLongest(trail.routes())));

}

Expand Down
1 change: 0 additions & 1 deletion src/ch/epfl/tchu/gui/GraphicalPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ public GraphicalPlayer(PlayerId playerId, Map<PlayerId, String> playerNames, Act
DecksViewCreator.createHandView(gameState),
InfoViewCreator.createInfoView(playerId, playerNames, gameState, messages));
mainStage.setScene(new Scene(mainPain));

mainStage.show();
}

Expand Down
11 changes: 9 additions & 2 deletions src/ch/epfl/tchu/gui/MenuController.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package ch.epfl.tchu.gui;

import ch.epfl.tchu.game.AdvancedPlayer;
import ch.epfl.tchu.net.RemotePlayerClient;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.ReadOnlyBooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
Expand All @@ -14,11 +16,16 @@

import java.io.IOException;
import java.io.UncheckedIOException;
import java.net.Socket;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Pattern;
import java.util.stream.Collectors;


public final class MenuController {

private final static String DEFAULT_HOST_NAME = "localhost";
private final static int DEFAULT_PORT = 5108;
private final static int portNumber = 5108;

private static BooleanProperty hide = new SimpleBooleanProperty();
Expand Down Expand Up @@ -87,7 +94,7 @@ private void nodeDisabler(Node... nodes){
*/
@FXML
public void connectClient() {

ClientMain clientMain = new ClientMain();
String[] args;
if (hostNameField.getText().isEmpty() && !portNumberClient.getText().isEmpty()) {
args = new String[]{portNumberClient.getText()};
Expand Down
5 changes: 0 additions & 5 deletions src/ch/epfl/tchu/gui/MenuMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@ public void start(Stage primaryStage) throws Exception {
Parent root = FXMLLoader.load(Objects.requireNonNull(getClass().getResource("MenuMain.fxml")));
primaryStage.setScene(new Scene(root));
primaryStage.show();
hide().addListener((o,oV,nV)->{
if(nV) {
primaryStage.hide();
}
});
}
}

3 changes: 2 additions & 1 deletion src/ch/epfl/tchu/gui/ObservableGameState.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* @author Louis Yves André Barinka (329847)
*/
public final class ObservableGameState {
private final static int MINIMAL_NUMBER = 3;
private final PlayerId playerId;
private final IntegerProperty ticketPct = new SimpleIntegerProperty();
private final IntegerProperty cardPct = new SimpleIntegerProperty();
Expand Down Expand Up @@ -259,7 +260,7 @@ private void updateClaimableRoute() {
if (routeClaimed) {
for (Route gameStateRoute : gameState.claimedRoutes()) {
if (gameStateRoute.stations().containsAll(route.stations())) {
routeClaimed = PlayerId.COUNT>=3;
routeClaimed = PlayerId.COUNT >= MINIMAL_NUMBER;
break;
}
}
Expand Down

0 comments on commit e697775

Please sign in to comment.