[Java] 숫자야구 프로그램
본 자료는 미리보기를 지원하지 않습니다.
닫기
  • 1
  • 2
  • 3
  • 4
해당 자료는 1페이지 까지만 미리보기를 제공합니다.
1페이지 이후부터 다운로드 후 확인할 수 있습니다.

소개글

[Java] 숫자야구 프로그램에 대한 보고서 자료입니다.

본문내용

package BaseballGame;

import java.io.IOException;
import java.util.Scanner;
import Case.*;
import Input.*;

public class BaseballMain {

public static void main(String[] args) {
System.out.println(\"=====숫자 야구 게임을 시작합니다======\");
System.out.println(\"( o_o)=! 0>>>(o_o )\");

boolean game = true;
int cnt = 0;
int cnt1 = 0;
int c = 0;
int Uscore = 0;
int Cscore = 0;
Scanner s = new Scanner(System.in);

// Game 시작(반복)
while (game) {
System.out.println(\"\");
try {
System.out.println(\"=Game Start=\");
System.out.println(\"1. 공격 (Attack)\");
System.out.println(\"2. 방어 (Defense)\");
System.out.println(\"3. 결과 확인 (Check Result)\");
System.out.println(\"4. 종료 (End)\");
System.out.print(\"선택 : \");

c = s.nextInt();
System.out.println(\"\");
} catch (Exception e) {
System.out.println(\"\");
System.out.println(\"숫자를 입력해 주세요!!!\");
continue;
}

// 유저 공격
if (c == 1) {
System.out.println(\"Attack\");
System.out.println(\"유저가 공격을 시작 합니다. ( o_o)=!\");

Dcomputer ac = new Dcomputer();
Iuser au = new Iuser();

int[] cnum1 = ac.ran();
boolean t = true;

// 비교문
while (t) {
cnt1++;
int strike1 = 0;
int ball1 = 0;
System.out.println(cnt1 + \"set 입니다.\");
int[] unum1 = au.input();
for (int i = 0; i < unum1.length; i++) {
for (int j = 0; j < cnum1.length; j++) {
if (unum1[i] == cnum1[j]) {
if (i == j) {
strike1++;
} else
ball1++;
}
}
}

// 확인문
System.out.println(cnt1 + \"set에서 유저가 선택한 숫자는 \" + unum1[0] + unum1[1] + unum1[2]);
if (strike1 == 0 && ball1 == 0) {
System.out.println(\"Out 입니다... (OㅁO )\");
if (strike1 != 3)
System.out.println(\"\");
} else {
System.out.println(strike1 + \" 스트라이크\");
System.out.println(ball1 + \" 볼\");
if (strike1 != 3)
System.out.println(\"\");
}
if (strike1 == 3)
t = false;
}
System.out.println(\"\( >o<)/ User가 \" + cnt1 + \"번 만에 성공하셨습니다! \" + \"(-_-;;)\");
try {
System.in.read();
} catch (IOException e) {
e.printStackTrace();
}
Uscore = cnt1;
cnt1 = 0;
}

// 유저 방어
else if (c == 2) {
System.out.println(\"Defense\");
System.out.println(\"유저가 방어을 시작 합니다. ( o_o)<<<0\");

Dcomputer dc = new Dcomputer();
Duser du = new Duser();

int[] cnum = dc.ran();
int[] unum = du.input();
int strike = 0;
int ball = 0;

// 비교문
for (int i = 0; i < unum.length; i++) {
for (int j = 0; j < cnum.length; j++) {
if (unum[i] == cnum[j]) {
if (i == j) {
strike++;
} else
ball++;
}
}
}

// 확인문
System.out.println(\"1set에서 컴퓨터가 선택한 숫자는 \" + cnum[0] + cnum[1] + cnum[2]);
if (strike == 0 && ball == 0) {
System.out.println(\"Out 입니다... (OㅁO )\");
try {
Thread.sleep(1000);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
System.out.println(\" \");
} else {
System.out.println(strike + \" 스트라이크\");
System.out.println(ball + \" 볼\");
if (strike != 3)
try {
Thread.sleep(1000);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
System.out.println(\" \"

키워드

  • 가격1,900
  • 페이지수4페이지
  • 등록일2017.12.07
  • 저작시기2017.11
  • 파일형식압축파일(zip)
  • 자료번호#1040243
본 자료는 최근 2주간 다운받은 회원이 없습니다.
청소해
다운로드 장바구니