-
Notifications
You must be signed in to change notification settings - Fork 252
Expand file tree
/
Copy pathGame2.java
More file actions
85 lines (63 loc) · 2.29 KB
/
Game2.java
File metadata and controls
85 lines (63 loc) · 2.29 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package ladder2;
import java.util.ArrayList;
import java.util.List;
public class Game2 {
public static void main(String[] args) {
InputView2 inputView = new InputView2();
ResultView2 resultView = new ResultView2();
List<String> participantNames;
List<String> resultList;
int ladderHeight;
try {
participantNames = inputView.getParticipantNames();
} catch (IllegalArgumentException e) {
System.out.println(e.getMessage());
return; // 오류 발생 시 프로그램을 종료
}
try {
resultList = inputView.getResult(participantNames);
} catch (IllegalArgumentException e) {
System.out.println(e.getMessage());
return; // 오류 발생 시 프로그램을 종료
}
try {
ladderHeight = inputView.getLadderHeight();
}catch (Exception e) {
System.out.println(e.getMessage());
return; // 오류 발생 시 프로그램을 종료
}
resultView.printStringList(participantNames);
List<Ladder2> completeLadder = new ArrayList<>();
for (int i = 0; i < ladderHeight; i++) {
Ladder2 l = new Ladder2(participantNames.size(), ladderHeight);
l.makeLadder();
completeLadder.add(l);
}
for (Ladder2 l : completeLadder) {
resultView.printLadder(l.getLadder());
}
resultView.printStringList(resultList);
String selection = inputView.selectMember();
int n = 0;
int location = 0;
for(String name : participantNames) {
location += findLocation(name,n,selection);
n++;
}
if(selection.equals("all")) {
location = -1;
}
if(location!=-1) {
resultView.printResult(completeLadder, location, resultList);
}
if(location == -1) {
resultView.printAllResult(completeLadder,resultList,participantNames);
}
}
public static int findLocation(String name, int i, String selection) {
if(name.equals(selection)) {
return i;
}
return 0;
}
}