import java.util.*;
import java.util.concurrent.ThreadLocalRandom;
class Const {
static final int PARTICIPANTS_NUM = 2;
static final int GAMBLE_NUM = 3;
static final int FIRST_NUM = 1;
static final int LAST_NUM = 3;
}
class Person {
private String name;
Person(String name) {
this.name = name;
}
String getName() {
return this.name;
}
}
class PrintStringBuilder {
private static StringBuilder print = new StringBuilder();
PrintStringBuilder() {
}
private static void printAndReset() {
System.out.print(print);
print.setLength(0);
}
static void intro() {
print.append("참가자의 이름을 입력해주세요: ");
printAndReset();
}
static void victory(String name) {
print.append(name);
print.append("님이 이겼습니다. 게임을 종료합니다.");
printAndReset();
}
static void randomNums(int[] nums) {
for (int i = 0; i < nums.length; i++) {
print.append(i + 1);
print.append("번째 숫자는 ");
print.append(nums[i]);
print.append(" 입니다.\n");
};
printAndReset();
}
static void randomStart(String name) {
print.append(name);
print.append("님의 차례입니다. 진행하시려면 <Enter>를 눌러주세요.");
printAndReset();
}
}
class GameGambling {
static Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
Person[] participants = new Person[Const.PARTICIPANTS_NUM];
for (int i = 0; i < Const.PARTICIPANTS_NUM; i++) {
PrintStringBuilder.intro();
String name = scanner.nextLine();
participants[i] = new Person(name);
};
randomRun:
while(true) {
for (int i = 0; i < Const.PARTICIPANTS_NUM; i++) {
String tempName = participants[i].getName();
PrintStringBuilder.randomStart(tempName);
scanner.nextLine();
int[] gambleNums = new int[Const.GAMBLE_NUM];
boolean win = true;
int firstNum = 0;
for (int j = 0; j < Const.GAMBLE_NUM; j++) {
int tempRanNum = ThreadLocalRandom.current().nextInt(Const.FIRST_NUM, Const.LAST_NUM + 1);
gambleNums[j] = tempRanNum;
if (j == 0) {
firstNum = tempRanNum;
} else if (win && (firstNum != tempRanNum)) {
win = false;
};
};
PrintStringBuilder.randomNums(gambleNums);
if (win) {
PrintStringBuilder.victory(tempName);
break randomRun;
};
};
};
scanner.close();
}
}