Skip to content

Commit d0bb713

Browse files
committed
lot of noice fixes
1 parent d17ebee commit d0bb713

File tree

5 files changed

+30
-14
lines changed

5 files changed

+30
-14
lines changed

src/ch/epfl/chacun/Board.java

+6
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,12 @@ public boolean couldPlaceTile(Tile tile) {
344344
);
345345
}
346346

347+
public boolean couldPlaceTileAtPos(Tile tile, Pos pos) {
348+
return insertionPositions().contains(pos) &&
349+
Rotation.ALL.stream()
350+
.anyMatch(rotation -> canAddTile(new PlacedTile(tile, null, rotation, pos)));
351+
}
352+
347353
/**
348354
* Checks if the board has at least one tile, to prevent
349355
* unwanted operations on an empty board

src/ch/epfl/chacun/gui/BoardUI.java

+10-6
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public static Node create(
9191
ObservableValue<Set<Animal>> cancelledAnimalsO = boardO.map(Board::cancelledAnimals);
9292
// the fringe only exists when the next action is to place a tile
9393
ObservableValue<Set<Pos>> fringeTilesO = gameStateO.map(
94-
state -> state.nextAction() == GameState.Action.PLACE_TILE
94+
state -> (state.nextAction() == GameState.Action.PLACE_TILE && isOwnerCurrentPlayerO.getValue())
9595
// important to understand
9696
// we can not use boardO.getValue() here!
9797
// because this map may be triggered before boardO gets updated!
@@ -148,23 +148,27 @@ public static Node create(
148148
if (!isInFringeO.getValue()) return new CellData(Color.TRANSPARENT);
149149

150150
PlayerColor currentPlayer = gameStateO.getValue().currentPlayer();
151+
assert currentPlayer != null;
152+
151153

152154
// if the mouse is currently on this tile (in the fringe) we display it normally
153155
// if it can be placed there with its current position, and with a white veil otherwise
154156
if (group.isHover()) {
155157
PlacedTile willBePlacedTile = new PlacedTile(
156158
gameStateO.getValue().tileToPlace(), currentPlayer, rotationO.getValue(), pos
157159
);
158-
return new CellData(willBePlacedTile,
159-
boardO.getValue().canAddTile(willBePlacedTile) ? Color.TRANSPARENT : Color.WHITE
160-
);
160+
boolean canBePlaced = boardO.getValue().canAddTile(willBePlacedTile);
161+
return new CellData(willBePlacedTile, canBePlaced ? Color.TRANSPARENT : Color.WHITE);
161162
}
163+
164+
boolean couldBePlaced = boardO.getValue().couldPlaceTileAtPos(gameStateO.getValue().tileToPlace(), pos);
165+
162166
// finally, if the tile is in the fringe but the mouse is not on it,
163167
// we display it with a veil of the current player's color
164-
return new CellData(ColorMap.fillColor(currentPlayer));
168+
return new CellData(ColorMap.fillColor(currentPlayer).deriveColor(0, 1, 1, couldBePlaced ? 1 : .5));
165169
// these arguments are the sensibility of the code,
166170
// every time one of them changes, the code is re-executed
167-
}, isInFringeO, group.hoverProperty(), rotationO, darkVeilEnabledO, placedTileO);
171+
}, isInFringeO, group.hoverProperty(), rotationO, darkVeilEnabledO, placedTileO, isOwnerCurrentPlayerO);
168172

169173
// we bind the graphical properties of the group to the cell data's values
170174
group.rotateProperty().bind(cellDataO.map(cellData -> cellData.tileRotation().degreesCW()));

src/ch/epfl/chacun/gui/Launcher.java

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package ch.epfl.chacun.gui;
2+
3+
public class Launcher {
4+
public static void main(String[] args) {
5+
Main.main(args);
6+
}
7+
}

src/ch/epfl/chacun/gui/Main.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ public void start(Stage primaryStage) {
7878
String gameName = "androzGame";
7979
String mySuperName = "Androz" + new Random().nextInt(1000);
8080
WSClient wsClient = new WSClient(
81-
gameName,
82-
mySuperName
81+
gameName,
82+
mySuperName
8383
);
8484

8585
Parameters parameters = getParameters();
@@ -154,17 +154,17 @@ public void start(Stage primaryStage) {
154154
if (!isOwnerCurrentPlayerO.getValue()) return;
155155
GameState currentGameState = gameStateO.getValue();
156156
Board board = currentGameState.board();
157-
int tileId = Zone.tileId(occupant.zoneId());
157+
int tileId = occupant != null ? Zone.tileId(occupant.zoneId()) : -1;
158158
switch (currentGameState.nextAction()) {
159159
case OCCUPY_TILE -> {
160160
assert board.lastPlacedTile() != null;
161-
if (tileId != board.lastPlacedTile().id()) return;
161+
if (tileId != board.lastPlacedTile().id() && occupant != null) return;
162162
saveStateAndDispatch(ActionEncoder.withNewOccupant(currentGameState, occupant), gameStateO, actionsO, wsClient);
163163
}
164164
case RETAKE_PAWN -> {
165165
if (
166-
(occupant.kind() != Occupant.Kind.PAWN)
167-
|| (currentGameState.currentPlayer() != board.tileWithId(tileId).placer())
166+
occupant != null &&
167+
(occupant.kind() != Occupant.Kind.PAWN || (currentGameState.currentPlayer() != board.tileWithId(tileId).placer()))
168168
) return;
169169
saveStateAndDispatch(ActionEncoder.withOccupantRemoved(currentGameState, occupant), gameStateO, actionsO, wsClient);
170170
}

src/ch/epfl/chacun/gui/PlayersUI.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,10 @@ public static Node create(
6060
ObservableValue<List<PlayerColor>> players = gameStateO.map(GameState::players);
6161

6262
Function<List<PlayerColor>, Boolean> addPlayersNodes = (newPlayers) -> {
63+
vBox.getChildren().clear();
6364
System.out.println("rerender players");
6465
System.out.println(newPlayers.stream().map(e -> textMaker.playerName(e)).collect(Collectors.joining()));
6566
newPlayers
66-
.stream()
67-
.skip(vBox.getChildren().size())
6867
.forEach(playerColor -> {
6968
String name = textMaker.playerName(playerColor);
7069

0 commit comments

Comments
 (0)