2014-12-13 2 views
0

그래서 저는 MasterMind 게임과 관련된 프로젝트를 시작했습니다. 나는 이제 완전히 잃어 버렸고 게임을 끝내기 위해 무엇을해야할지 모릅니다. 콘솔 영역에서만 애플릿으로 실행하고 싶지 않습니다. BTW 이것은 일식에서 실행됩니다. if 문에도 문제가 있습니다. 피연산자가 호환되지 않는다고 알려줍니다. 오류 코드는 다음과 같습니다. 호환되지 않는 피연산자 유형 Scanner 및 Int [].MasterMind Game-Java

package masterMind; 

import java.util.Scanner; 

public class MasterMind { 

    public static void main(String[] args) { 
     System.out.println("This is MasterMind, a logic game"); 
     System.out.println("To win you must guess correctly where each number is(The Numbers Range from 1-4)"); 
     System.out.println("You will be told if you get one correct"); 
     System.out.println("You will only get 10 tries, then you lose"); 
     System.out.println("Lets begin"); 


     //Declare Array 
     int [] answerArray; 

     answerArray= new int [4]; 
     //Initialize Array 
     //Change these value to change the answers needed to win 
     answerArray[0]=2; 
     answerArray[1]=3; 
     answerArray[2]=2; 
     answerArray[3]=2; 
     //Create Board 
     System.out.println("__ __ __ __"); 

     Scanner userGuess = new Scanner(System.in); 
     int num = userGuess.nextInt(); 

     boolean guessedAll = false; 
     int guessedCount=0; 
     int tryCounter=0; 
     while(tryCounter<9 || !guessedAll){ 
     if (userGuess==answerArray) { 

     } else { 

     } 
     //if number equals one of the numbers above then guessedCount++ ... 
     //if guessedCount==4 then guessedAll=true 
     tryCounter++; 
     } 
    } 
} 
+1

(그것을 편집하여) 귀하의 질문에 오류 메시지를 기입하십시오. 그것은 호환성에 대해 불평 –

+0

을 ... 루프를 구현하지 않으려 고 실제 추측이며'answerArray'는 사용자가 제공해야하는 답변이 아니라 전체 답변입니다. 프로그램을 다시 생각해보고 모든 단계에서 무엇을 하려는지 이해해야합니다. – RealSkeptic

+0

저는 Java와 다른 언어에 대한 지식이 거의없는 새로운 프로그래머입니다 ... 그래서 도움을 요청하는 것입니다. – Zachary

답변

0

if 문 안에 4 개의 if 문이 필요하며 각 문은 해당 지점의 번호가 정확하게 추측되는지 확인합니다. 숫자가 표시되면 숫자를 표시하고 다른 숫자는 다시 추측하게합니다 (충분한 시간을 추측했는지 확인하는 것이 좋습니다. 또는

+0

사용자 입력을 배열 위치와 어떻게 비교합니까? – Zachary

0

) userGuess` 당신이 당신의`Scanner`에게 준 이름은`때문에,

public static void main(String[] args) { 
    Scanner userGuess = new Scanner(System.in); 
    boolean gameRunning = true; 
    while (gameRunning) { 
     // getting a line from the input 
     System.out.println("\ninput a line"); 
     String inputLine = userGuess.nextLine(); 
     System.out.println("the line is: " + inputLine); 

     // getting an integer 
     System.out.println("\ninput an integer"); 
     int inputInt = userGuess.nextInt(); // this will give you an int from the input 
     userGuess.nextLine(); 
     System.out.println("the integer is: " + inputInt); 
    } 
} 
+0

그리고 내 메인 클래스를 이것으로 바꾸라고 조언 해 주시겠습니까? – Zachary

+0

아니요, 저는 다른 프로젝트를 만들 것을 권고합니다 ... 스캐너 입력으로 놀고 나서 당신의 필요에 맞는 완벽한 조합을 찾으십시오. 이것이 내가 스캐너를 사용하는 방법을 배웠습니다. 올바른 입력을 얻었 으면 나머지 부분을 이해하는 데 도움이됩니다.) – Ubica

+0

입력을 변수와 비교할 수 있기를 원합니다. – Zachary

관련 문제