-
Notifications
You must be signed in to change notification settings - Fork 581
Expand file tree
/
Copy pathApplication.java
More file actions
116 lines (102 loc) · 3.26 KB
/
Copy pathApplication.java
File metadata and controls
116 lines (102 loc) · 3.26 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package baseball;
import camp.nextstep.edu.missionutils.test.Randoms;
import camp.nextstep.edu.missionutils.test.Console;
public class Application {
public static void main(String[] args) {
Computer computer = new Computer();
Player player = new Player();
boolean gameover = true;
Again again = new Again();
Judging judge = new Judging();
while(gameover){
List<Integer> ComputerNumber = computer.computerNum();
String answer = "";
while(answer != "3스트라이크"){
answer = judge.Result(ComputerNumber, player.PlayerNum());
System.out.println(answer);
}
gameover = again.doitagain();
}
}
}
public class Computer{
public int computerNum{
List<Integer> randomNum = new ArrayList<>();
while (randomNum.size()<3) {
int num = Randoms.pickNumberInRange(1,9);
if (!randomNum.contains(num)) {
randomNum,add(num);
}
}
return randomNum;
}
}
public class Player{
public int PlayerNum(){
System.out.println("숫자를 입력하세요: ");
String input = Console.readLine();
List<Integer> playerNum = new ArrayList<Integer>(3);
try {
for (String number : input) {
playerNum.add(Integer.parseInt(number));
}
} catch (IllegalArgumentException e) {
System.out.println("입력이 올바르지 않습니다.");
}
return playerNum;
}
}
public class Guessing{
public int Strikes(List<Integer> computerNum, List<Integer> playerNum){
int strike = 0;
for(int i = 0; i < 3; i++){
if(computerNum[i] = playerNum[i]){
strike+=1;
}
}
return strike
}
public int TotalCounts(List<Integer> computerNum, List<Integer> playerNum){
int total = 0;
for(int i = 0;i < 3; i++){
if(computerNum.contains(playerNum[i])){
total += 1;
}
}
return total;
}
}
public class Judging{
Guessing guess = new Guessing;
public String Result(List<Integer> computerNum, List<Integer> playerNum){
int strike = guess.Strikes(computerNum, playerNum);
int total = guess.TotalCounts(computerNum, playerNum);
int ball = total - strike;
if (strike == 3){
return "3스트라이크";
}
else if (total == 0){
return "낫싱";
}
else if (strike == 0){
return ball + "볼";
}
else if (ball == 0){
return stirke + "스트라이크";
}
return ball + "볼 " + strike + "스트라이크";
}
}
public class Again{
public boolean doitagain(){
System.out.println("3개의 숫자를 모두 맞히셨습니다! 게임 종료");
Syste.out.println("게임을 새로 시작하려면 1, 종료하려면 2를 입력하세요.");
int again = Console.readLine();
if (again == 1){
return true;
}
else{
return false;
}
}
}