왜 에러가 나는지 모르겠네요..가르쳐주세요.
행복녀
자바공부 하기위해서 빙고를 짠겁니다. 1~100까지 숫자중 25개 숫자 랜덤으로 집어넣고, 나하고 컴퓨터가 한번씩 하면서, 진행되는 게임인데요... 여기서 빙고테이블 25개숫자 랜덤으로 주고, 나는 선택한 숫자를 넣고 컴퓨터는 25개 숫자중 아무거나 넣는 것입니다. 제가 좀 허접해서 함수를 불린으로 해야하는지, 정수형 반환을 해야하는지도..헤깔리네요..어느부분을 수정해야 되는지 충고 부탁드립니다.
혹시 두개함수를 합치면 좋은경우가 있는지도 알려주세요.import java.io.*; // 입출력 예외처리를 위해서
import java.util.*;
class Binggo {
private int[][] BinggoTable = new int[5][5];
public int getScore() {
return this.getSucceedLine();
}
public int getSucceedLine() {
int SucceedLine=0;
for(int i=0; i5; i++) {
if((BinggoTable[0][i]==0) && (BinggoTable[1][i]==0) && (BinggoTable[2][i]==0) && (BinggoTable[3][i]==0) && (BinggoTable[4][i]==0))
SucceedLine++;
else if((BinggoTable[i][0]==0) && (BinggoTable[i][1]==0) && (BinggoTable[i][2]==0) && (BinggoTable[i][3]==0) && (BinggoTable[i][4]==0))
SucceedLine++;
else if((BinggoTable[0][0]==0) && (BinggoTable[1][1]==0) && (BinggoTable[2][2]==0) && (BinggoTable[3][3]==0) && (BinggoTable[4][4]==0))
SucceedLine++;
else if((BinggoTable[4][0]==0) && (BinggoTable[3][1]==0) && (BinggoTable[2][2]==0) && (BinggoTable[1][3]==0) && (BinggoTable[0][4]==0))
SucceedLine++;
}
return SucceedLine;
}
// 1~100사이의 중복되지 않은 숫자를 가지고 빙고를 초기화 한다.
public void ShowBinggoTable() {
int RandomNumber1, RandomNumber2;
for(int i=0; i5; i++) {
for(int j=0; j5; j++) {
while(true){
RandomNumber1=(int)(Math.random()*100)+1;
RandomNumber2=(int)(Math.random()*100)+1;
if(RandomNumber1!=RandomNumber2) {
BinggoTable[i][j]=RandomNumber1;
System.out.println(BinggoTable[i][j]+ );
}
}
}
}
}
// Select Number that I want to Choose = 선택된수가 테이블에 있으면 0으로 교환
public void SelectNumber(int SelectNumber) {
for(int i=0; i5; i++)
for(int j=0; j5; j++) {
if(BinggoTable[i][j]==SelectNumber)
BinggoTable[i][j]=0;
}
}
}class BinggoTest extends Thread
{
public static void main(String[] argv) throws IOException
{
Binggo myBinggo = new Binggo();
Binggo comBinggo = new Binggo();
boolean isBinggo = false;
int choice;
int computerChoice;
BufferedReader br = new BufferedReader (new InputStreamReader(System.in)) ;
// Display first BinggoTable
myBinggo.ShowBinggoTable();
while(!isBinggo) {
//My turn
System.out.println(Choose any Number);
choice = Integer.parseInt(br.readLine());
if(!myBinggo.SelectNumber(choice)) = 테이블에 있지 않으면 있는수 넣을때까지 다시
continue;
myBinggo.ShowBinggoTable(); = 0으로 변화시키고 다시 출력
if(myBinggo.getScore()==5) {
System.out.println(I won);
&nbsbsp; isBinggo = true;
}
else if(comBinggo.getScore()==5) {
System.out.println(Computer won);
isBinggo = true;
}
//Computer turn
try {
System.out.println(Computer Chooses ..........);
sleep(1000);
computerChoice = (int)(Math.random()*100)+1;
}
catch(IOException e) {
System.out.println(Error +e.getMessage());}
if(!comBinggo.SelectNumber(computerChoice))
continue;
myBinggo.ShowBinggoTable();
if(comBinggo.getScore()==5) {
System.out.println(Computer won);
isBinggo = true;
}
else if(myBinggo.getScore()==5) {
System.out.println(You won);
isBinggo = true;
}
myBinggo.ShowBinggoTable();
}
}
}
-
황소자리
감사합니다. 제가 C를 하다가 ... C에선 에러는 아니거든요~~ 결과는 모르겠지만요
-
자올
boolean SelectNumber() 라고 가정한다면...
return false;
또는 return true;
저 둘중 하나겠죠^^ -
맑은
네 저두 그건 아는데요...불린형으로 만들면 어떻게 리턴형을 주는지 몰라서요~~ 어쨌든 감사요
-
라미
SelectNumber() 메소드는 리턴형이 없는데
if 문에 사용될 수 없겠죠^^