-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathLadderGame.java
More file actions
44 lines (34 loc) · 1.48 KB
/
LadderGame.java
File metadata and controls
44 lines (34 loc) · 1.48 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
import domain.User;
import dto.GameResultDto;
import domain.Ladder;
import dto.GameInformationDto;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class LadderGame {
private GameInformationDto gameInformationDto;
private Ladder ladder;
public LadderGame(GameInformationDto gameInformationDto) {
this.gameInformationDto = gameInformationDto;
ladder = Ladder.createLadder(gameInformationDto);
}
public GameResultDto getGameResult(){
List<String> userNames = gameInformationDto.getPlayers();
List<String> executeResults = gameInformationDto.getExecuteResult();
List<User> userList = IntStream.range(0,userNames.size())
.mapToObj(i->new User(userNames.get(i),i+1))
.collect(Collectors.toList());
HashMap<User,String> userPlayResult = getUserPlayResult(userList,executeResults);
return new GameResultDto(ladder,userPlayResult,gameInformationDto);
}
public HashMap<User,String> getUserPlayResult(List<User> userList, List<String> playResults){
HashMap<User ,String> userPlayResult = new HashMap<>();
for(int i = 0; i < userList.size() ; i++){
int startColumn = userList.get(i).getStartColumn();
int resultColumn = ladder.progressAllStep(startColumn);
userPlayResult.put(userList.get(i),playResults.get(resultColumn-1));
}
return userPlayResult;
}
}