2016-10-23 6 views
-1

私は、使用者の入力に使用されている文字の配列をスキャンして教えてくれるので、私はこの時点で迷っています。使用されている見知らぬ人が私の推測で使用する推測を確認する


/** 
    * 
    */ 
    package Hangman; 

    import java.io.IOException; 

    /** 
    * @author 
    * 
    */ 
    public class Hangman { 
     static int choice; 
     static String solve; 
     static String promt; 
     static String guess; 
     static char chaGuess; 
     static char[] guesses = new char[25]; 
     static char[] check; 
     static int counter = 1; 
     static boolean contine; 

     public static void main(String[] args) throws IOException,  InterruptedException { 
      playerOne(); 
      for (int i = 0; i < 300; i++) { 
       System.out.println(" "); 
      } 
      while (contine = true) { 
       playerTwo(); 
       choiceMade(choice); 
      } 
     } 

     public static String playerOne() throws IOException { 
      System.out.println("Welcome player one"); 
      promt = ConsoleUI.promptForInput("Enter a Phrase or word for Player Two to guess", true); 
      return promt; 
     } 

     public static int playerTwo() throws IOException { 
      String[] ask = new String[3]; 
      ask[0] = "Give up"; 
      ask[1] = "Guess a letter"; 
      ask[2] = "Solve the puzle"; 
      choice = ConsoleUI.promptForMenuSelection(ask, true); 
      return choice; 
     } 

     public static void choiceMade(int c) throws IOException { 
      if (c == 0) { 
       contine = false; 
       System.out.println("Thank you for playing"); 
       System.exit(0); 
      } 
      if (c == 1) { 
       guess = ConsoleUI.promptForInput("Enter your guess", true); 
       guessChar(guess); 


       contine = true; 
      } else if (c == 2) { 
       solve = ConsoleUI.promptForInput("Enter your answer", true); 

       if (solve.equals(promt)) { 
        System.out.println("You solved it you're amazing"); 
        contine= false; 
       } else { 
        System.out.println("Sorry you guessed it wrong."); 
        System.exit(0); 
        contine= false; 
       } 
      } 
     } 

     public static char guessChar(String g) { 
      chaGuess = g.charAt(0); 
      promt = promt.replace(" ", ""); 
      check = promt.toCharArray(); 

        if(guesses[counter -1] != chaGuess) 
if (chaGuess >= 'a' && chaGuess <= 'z' || chaGuess >= 'A' && chaGuess <= 'Z') { 
          guesses[counter] = chaGuess; 


         System.out.println(guesses); 
        } 
        if(guesses[counter - 1] == chaGuess) 
        { 
         System.out.println("You all ready guessed that"); 
        } 
       } 
       counter++; 
      return chaGuess; 
     } 
    } 
+0

あなたの質問に詳細を追加します。 –

+0

そして、あなたがそれをしている間に質問をするかもしれません。 – shmosel

+0

*私はこの時点で紛失しています。*大丈夫です。コードから離れる。あなたのハングマンプログラムがしなければならないことを、英語の文章で正確に書き留めます。それぞれの文に対してJavaメソッドをコーディングできるようになるまで、文章をより詳細に分割します。それでは、紛失することなくコード作成する準備が整います。 –

答えて

-1

、文字列を使用して、それの最後に、各使用の推測を追加して、ちょうど(のindexOfを使用)

関連する問題