3마리의 말들이 각자 갖고 있는 기본능력치에 난수로 만들어진 각자의 컨디션상태를 더하여 오늘의 경기력을 만들었다.
승률이 높은 말은 배팅하였을때 배당금이 낮고, 승률이 낮은 말은 배팅하였을때 배당금이 높게 설정하였다.
import java.util.Scanner;
//경마 배팅 게임
public class Quiz_02 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int menu=0; //메뉴
int money=0; //충전하려는 금액
int account=0; //잔액
int choose_horse=0; //배팅하려는 말 선택기
int betting=0; // 배팅금액
int horse_a; //1번마
int horse_a_basicstat=200; //1번마 기본능력치
int horse_b; //2번마
int horse_b_basicstat=150; //2번마 기본능력치
int horse_c; //3번마
int horse_c_basicstat=100; //3번마 기본능력치
int random1; //1번마의 오늘의 컨디션 상태
int random2; //2번마의 오늘의 컨디션 상태
int random3; //3번마의 오늘의 컨디션 상태
int profit=0; //배당금
int random_max=300; //컨디션 최상
int random_min=0; //컨디션 최하
//경마게임 시작
while(true) {
//메뉴 선택 시작
while(true) {
try { //메뉴 입력
System.out.println("=====================");
System.out.println("경마게임에 오신 것을 환영합니다.");
System.out.println("1. 게임 시작");
System.out.println("2. 잔액 충전");
System.out.println("3. 잔액 조회");
System.out.println("4. 종료");
System.out.print(">> ");
menu=Integer.parseInt(sc.nextLine());
if(!(menu==1)&&!(menu==2)&&!(menu==3)&&!(menu==4)) {
System.out.println("메뉴 입력범위를 벗어났습니다.");
continue;
}
}catch(Exception e){ //메뉴 입력 예외처리
System.out.println("숫자를 입력해주세요.");
continue;
}
break;
}
//메뉴 선택 종료
//메뉴별 기능 시작
switch(menu) {
//1번메뉴 게임시작
case 1:
//잔액이 0원인 경우, 메뉴로 돌아가기
if(account==0) {
System.out.println("잔액이 0원입니다. 잔액을 충전해주세요.");
break;
}
//배팅할 말 선택
while(true) {
try {
System.out.println("몇번 말에 배팅하시겠습니까?");
System.out.println("1번마 : 이전 대회 우승마 - 기본 능력치 300 (우승시 배팅금액의 10% 지급)");
System.out.println("2번마 : 이번 대회 다크호스 - 기본 능력치 200(우승시 배팅금액의 50% 지급)");
System.out.println("3번마 : 만년 꼴찌 - 기본 능력치 100 (우승시 배팅금액의 200% 지급)");
System.out.print("배팅할 말 번호 : ");
choose_horse=Integer.parseInt(sc.nextLine());
if(!(choose_horse==1)&&!(choose_horse==2)&&!(choose_horse==3)) {
System.out.println("1~3번마 중 입력해주세요.");
continue;
}
System.out.println();
System.out.println(choose_horse+"번마를 선택하셨습니다.");
}catch(Exception e) {
System.out.println("입력값이 숫자가 아닙니다.");
continue;
}
break;
}
//배팅할 말 종료
//배팅금액 입력
while(true) {
try {
System.out.print("얼마를 배팅하겠습니까? ");
betting=Integer.parseInt(sc.nextLine());
if(betting>account) {
System.out.println("잔액보다 배팅금액이 커서, 배팅이 불가능합니다.");
continue;
}
}catch(Exception e){
System.out.println("입력값이 숫자가 아닙니다.");
continue;
}
break;
}
//배팅금액 입력 종료
//말들의 컨디션 생성(난수)
random1=(int)(Math.random()*(random_max-random_min+1)+random_min);
random2=(int)(Math.random()*(random_max-random_min+1)+random_min);
random3=(int)(Math.random()*(random_max-random_min+1)+random_min);
//오늘 말의 경기력 = 말의 기본능력치+컨디션
horse_a = horse_a_basicstat + random1;
horse_b = horse_b_basicstat + random2;
horse_c = horse_c_basicstat + random3;
//경기결과 출력
System.out.println("======경기 결과========");
System.out.println("1번마 경기력 = " + horse_a);
System.out.println("2번마 경기력 = " + horse_b);
System.out.println("3번마 경기력 = " + horse_c);
System.out.println("====================");
//1번말 배팅하여
if(choose_horse==1) {
//1번이 우승하였을 경우
if(horse_a>horse_b&&horse_a>horse_c) {
System.out.println("1번마가 우승하였습니다.");
System.out.println("배팅금액 : " + betting);
profit=betting/100*10;
System.out.println("배당금 : " + profit);
account+=(betting+profit);
}else { //1번이 우승하지 못하였을 경우
account-=betting;
System.out.println("1번말이 우승하지 못했습니다.");
System.out.println(betting+"원을 잃었습니다.");
}
}
//2번말 배팅하여
if(choose_horse==2) {
//2번이 우승하였을 경우
if(horse_b>horse_a&&horse_b>horse_c) {
System.out.println("2번마가 우승하였습니다.");
System.out.println("배팅금액 : " + betting);
profit=betting/100*50;
System.out.println("배당금 : " + profit);
account+=(betting+profit);
}else {//2번이 우승하지 못하였을 경우
account-=betting;
System.out.println("2번말이 우승하지 못했습니다.");
System.out.println(betting+"원을 잃었습니다.");
}
}
//3번말 배팅하여
if(choose_horse==3) {
//3번이 우승하였을 경우
if(horse_c>horse_a&&horse_c>horse_b) {
System.out.println("3번마가 우승하였습니다.");
System.out.println("배팅금액 : " + betting);
profit=betting/100*200;
System.out.println("배당금 : " + profit);
account+=(betting+profit);
}else {//3번이 우승하지 못하였을 경우
account-=betting;
System.out.println("3번말이 우승하지 못했습니다.");
System.out.println(betting+"원을 잃었습니다.");
}
}
break;
//1번메뉴 게임종료
//2번메뉴 잔액충전 시작
case 2:
//충전금액 입력
while(true) {
try {
System.out.println("얼마를 충전하시겠습니까?");
money=Integer.parseInt(sc.nextLine());
System.out.println(money+"원이 충전되었습니다.");
account+=money;
}catch(Exception e) {
System.out.println("입력값이 숫자가 아닙니다.");
}
break;
}
break;
//2번메뉴 잔액충전 종료
//3번메뉴 잔액조회 시작
case 3:
System.out.println("현재 잔액은 " + account +"원입니다.");
break;
//3번메뉴 잔액조회 종료
//4번메뉴 게임종료기능 시작
case 4:
System.out.println("경마게임을 종료합니다.");
System.out.println("===============");
System.exit(0);
//4번메뉴 게임종료기능 종료
}
//메뉴별 기능 종료
}
//경마게임 종료
}
}
'자바 프로그래밍 > 코드' 카테고리의 다른 글
배열참조변수 (0) | 2020.02.12 |
---|---|
Baskin Robbins 31 Game (0) | 2020.02.11 |
UP & Down Game (0) | 2020.02.11 |
가위바위보 게임-Math.random()을 이용 (0) | 2020.02.11 |
동전 앞뒤 맞추기 게임-Math.random()을 이용 (0) | 2020.02.11 |
Comment