2015-02-02 2 views
0

그래서 basiclly, 나는 자바로 텍스트 기반 게임을 만들고있다. (그것은 cookie clicker과 같은 은폐 게임이다.) 나는 문제를 만났다. 알다시피, 모든 다른 시간을 명령을 입력하면 아무것도 얻지 못합니다. 여기 자바로 대기 게임 만들기

코드입니다 :

수입 java.util.Scanner;

공용 클래스 사과 {

public static int upQuarks = 0; 
public static int downQuarks = 0; 
public static int electrons = 0; 

public static int protons = 0; 
public static int neutrons = 0; 

public static int HAtoms = 0; 

public static int upQuarkCreation = 1; 
public static int downQuarkCreation = 1; 
public static int electronCreation = 1; 

public static int protonCreation = 1; 
public static int neutronCreation = 1; 

public static int atomCreation = 1; 

public static String question = "0"; 


public static void main(String[] args) { 
    Scanner dad = new Scanner(System.in); 

    while(true) { 

    switch(question) { 

     case "0": 
      System.out.println("Welcome to this untitled text adventure game, created by Adam and Benjamin Roache."); 
      System.out.println("Please enter your name."); 
      question = "1"; 
      break; 

     case "01": 
      dad.next(); 
      question = "1A"; 
      break; 

     case "1A": 
      System.out.println("\n\nAre you sure this is your name?\n[1]Yes\n[2]No"); 
      switch(dad.next()) { 
       case "1": 
        System.out.println("Type help to get help."); 
        question = "2"; 
        break; 

       case "2": 
        System.out.println("\n\n"); 
        question = "0"; 
        break; 


      } 

     case "2": 
      switch(dad.next()) { 
       case "help": 
        if (electrons >=1 && protons >= 1) { 
         System.out.println("\n\nTo go to the Atom Creator, type atom."); 

        } 
        if (upQuarks >= 2 && downQuarks >= 2) { 
        } else { 
         System.out.println("\n\nTo create a Proton, type pro.\nTo create a Neutron, type neu."); 
         break; 
        } 
        System.out.println("\nTo create an Up Quark, type upq.\nTo create a Down Quark, type dwnq.\nTo create a electron, type el.\nTo go to your inventory, type in."); 
        break; 

       case "upq": 
        upQuarks += upQuarkCreation; 
        System.out.println("\n\nYou have 1 new Up Quark."); 
        break; 

       case "dwnq": 
        downQuarks += downQuarkCreation; 
        System.out.println("\n\nYou have 1 new Down Quark."); 
        break; 

       case "el": 
        electrons += electronCreation; 
        System.out.println("\n\nYou have 1 new Electron."); 
        break; 

       case "pro": 
        if (upQuarks >= 2 && downQuarks >= 1) { 
         protons += protonCreation; 
         upQuarks -= 2; 
         downQuarks -= 1; 
         System.out.println("\n\nYou have 1 new proton."); 
         break; 
        }else{ 
         System.out.println("\n\nYou don't have those materials yet."); 
         break; 
        } 

       case "neu": 
        if (downQuarks >= 2 && upQuarks >=1) { 
         neutrons += neutronCreation; 
         upQuarks -= 1; 
         downQuarks -= 2; 
         System.out.println("\n\nYou have 1 new neutron."); 
         break; 
        }else{ 
         System.out.println("\n\nYou don't have those materials yet."); 
         break; 
        } 

       case "atom": 
        if(protons >= 1 && electrons >=1){ 
         System.out.println("\n\nWelcome to the Atom Creator!"); 
         question = "3"; 
         break; 
        }else{ 
         System.out.println("\n\nYou can't acsess this yet."); 
         break; 
        } 


       case "in": 
        if (protons >= 1 || neutrons >=1) { 
         System.out.println("\n\n" + protons + " protons, \n" + neutrons + " neutrons."); 
         break; 
        } 
        System.out.println("\n\n" + upQuarks + " up quarks, \n" + downQuarks + " down Quarks, \nand " + electrons + " electrons."); 
        break; 

      } 
     break; 
     case "3": 
      switch(dad.next()){ 

       case "help": 
        System.out.println("\n\nTo create an atom, type in its atomic symbol."); 
        break; 

       case "H": 
        if(protons >= 1 && electrons >= 1) { 
         HAtoms += atomCreation; 
         protons -= 1; 
         electrons -= 1; 
         System.out.println("\n\nYou have created 1 new hydrogen atom."); 
         break; 
        }else{ 
         System.out.println("You don't have the right materials."); 
        } 
        break; 
      } 
     break; 
     } 
    } 
} 

}

코드가 이러한 입력 명령을 생성합니다

  1. "upq"= 새로운 업 쿼크 모형을 만들어
  2. "dwnq은"= 새로운 생성 다운 쿼크
  3. "el"= 새로운 전자 생성

  4. "프로"= 새로운 양성자를 (물론, 당신이 바로 mateirials을 가지고있는 경우.)

  5. 는 "NEU가"= 새로운 중성자

  6. "원자"=이 아톰 창조주를 입력을 생성 생성

  7. 는 "H"는 = =는 도움말 부 간다 수소 원자를

  8. "도움"을 생성한다. = "에서"

  9. 인벤토리를

    을 enteres 그리고 그 모든 명령을합니다. 이 제목 텍스트 어드벤처 게임에

    에 오신 것을 환영합니다, 아담과 벤자민 Roache 만든이 :

    는 그리고 이것은 출력됩니다. 이름을 입력하십시오. 아담

당신의 이름이 맞습니까? 1 예 [2] 아니요 도움을 받으려면 help를 입력하십시오. upq

새로운 Quark이 1 개 있습니다. upq dwnq

새로운 다운 쿼크가 1 개 있습니다. 아래 쿼크

1 업 쿼크에서 에 , 0 전자. upq dwnq

새로운 다운 쿼크가 1 개 있습니다. neu neu

당신은 1 개의 새로운 중성자를 가지고 있습니다. 에서 에서

0 양성자, 1 중성자.

0 업 쿼크, 0 다운 쿼크, 전자.

+0

"case"1A ","case "2"'및'case "3"'의 끝에서'break;'를 호출하지 않습니다. 그리고 그 외에 현재 당신이 묻고있는 것이 명확하지 않습니다. 샘플 입력, 실제 출력 및 예상 출력을 제공하십시오. – Tom

+0

나는'break;'를 추가하려고 시도했다. 그리고 ** no ** 출력이 전혀 없었다. – addemup

답변

0

nextLine() 또는 호출 된 것을 사용하십시오. 문제가 될 수 있다고 생각하십시오

+1

무엇이 불려지나요? – addemup