import java.util.Scanner;
//Baskin Robbins 31 Game
//1부터 시작, 31이 될때까지 서로 턴을 교대하여 숫자를 증가
//31을 먼저 외치는 사람이 지는 게임
public class Quiz_03 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int menu;
int win=0; //플레이어 승리
int lose=0; //플레이어 패배
int player_oppo=0; //플레이어 횟수
int computer_oppo=0; // 컴퓨터 횟수
int number=0; //숫자
int i=0; //for문용 int
int button=0; //31 나왔을때 종료용 버튼
//31게임 시작
while(true) {
//메뉴 입력 시작
try {
System.out.println("---------------------");
System.out.println("Baskin Robbins31 Game");
System.out.println();
System.out.println("1. Game Start");
System.out.println("2. Game Score");
System.out.println("3. End game");
System.out.print(">> ");
menu=Integer.parseInt(sc.nextLine());
if(!(menu==1)&&!(menu==2)&&!(menu==3)) {
System.out.println("입력범위를 벗어난 숫자입니다.");
continue;
}
}catch(Exception e) {
System.out.println("숫자를 입력하여주세요.");
continue;
}
//메뉴 입력 종료
//메뉴 기능 시작
switch(menu) {
//메뉴 1번:게임 시작
case 1:
System.out.println("게임 시작!!");
while(true) { //게임 구현
//플레이어 입력 시작
while(true) {
try {
System.out.print("Input Number(1~3) : ");
player_oppo=Integer.parseInt(sc.nextLine());
if(player_oppo>=4||player_oppo<=0) {
System.out.println("입력범위를 벗어난 숫자입니다");
continue;
}
break;
}catch(Exception e) {
System.out.println("숫자를 입력하여주세요.");
continue;
}
}
//플레이어 입력 종료
//플레이어 숫자 진행, 31 판정
for(i=0;i<player_oppo;i++) {
number++;
System.out.println(number+"!");
if(number==31) {
System.out.println("플레이어 패배!");
lose++;
button=1;//31이 되면 이번 판 종료스위치 on
number=0;
break;
}
}
//플레이어 숫자 진행, 31 판정 종료
//이번 판 종료스위치 확인
if(button==1) {
button=0; //버튼 초기화
break; //게임종료
}
//이번 판 종료스위치 종료
i=0;
//컴퓨터 입력(난수 생성) 시작
//computer_oppo=(int)(Math.random()*(3-1+1)+1);
//1~3값 중에서 랜덤으로 만드는 컴퓨터의 기회
computer_oppo=4-(int)(Math.random()*(3-1+1)+1);
//컴퓨터 입력(난수 생성) 종료
//컴퓨터 숫자 진행, 31판정 시작
System.out.println("<Computer Turn>");
//System.out.println(computer_oppo);
for(i=0;i<computer_oppo;i++) {
number++;
System.out.println(number+"!");
if(number==31) {
System.out.println("컴퓨터 패배!");
win++;
button=1;
number=0;
break;
}
}
//컴퓨터 숫자 진행, 31 판정 종료
//이번 판 종료스위치 확인
if(button==1) {
button=0;
break;
}
//이번 판 종료스위치 종료
}
break;
//게임 구현 종료
//전적 출력 시작
case 2:
System.out.println("<< 당신의 전적 >>");
System.out.println("W I N : " +win);
System.out.println("L O S E : "+lose);
break;
//전적 출력 종료
//게임종료 시작
case 3:
System.out.println("게임을 종료합니다.");
System.exit(0);
break;
//게임종료 끝
}
//메뉴 기능 종료
}
//31게임 종료
}
}
Comment