forked from publicissapient-france/code-elevator
-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathPlayerInfo.java
More file actions
52 lines (42 loc) · 1.75 KB
/
PlayerInfo.java
File metadata and controls
52 lines (42 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package elevator.server;
import elevator.Direction;
import elevator.WaitingUser;
import elevator.engine.ElevatorEngine;
import java.io.Serializable;
import java.util.Set;
public class PlayerInfo implements Serializable {
public final String pseudo;
public final String email;
public final int score;
public final int[] peopleWaitingTheElevator;
public final int elevatorAtFloor;
public final int peopleInTheElevator;
public final boolean doorIsOpen;
public final String lastErrorMessage;
public final String state;
public boolean[] upButtonStateByFloor;
public boolean[] downButtonStateByFloor;
public boolean[] floorButtonStatesInElevator;
public PlayerInfo(ElevatorGame game, Player player) {
email = player.email;
pseudo = player.pseudo;
score = game.score();
peopleWaitingTheElevator = game.waitingUsersByFloors();
elevatorAtFloor = game.floor();
peopleInTheElevator = game.travelingUsers();
doorIsOpen = game.doorIsOpen();
lastErrorMessage = game.lastErrorMessage;
state = game.state.toString();
initializeBuildingButtonStates(game.waitingUsers());
floorButtonStatesInElevator = game.getFloorButtonStatesInElevator();
}
private void initializeBuildingButtonStates(Set<WaitingUser> waitingUsers) {
int floorNb = ElevatorEngine.HIGHER_FLOOR - ElevatorEngine.LOWER_FLOOR + 1;
upButtonStateByFloor = new boolean[floorNb];
downButtonStateByFloor = new boolean[floorNb];
for (WaitingUser user : waitingUsers) {
boolean[] states = user.getDesiredDirection().equals(Direction.DOWN) ? downButtonStateByFloor : upButtonStateByFloor;
states[user.getFloorNum()] = true;
}
}
}