2016-04-08 25 views
0

可能であればガイダンスが必要です。 Javaを初め。岩、紙、はさみゲームの下のコードがなぜ機能していないのかわからない。何かアドバイスをお願いしますか、アドバイスが大歓迎です。私はこの素晴らしいフォーラムに多くの例があることを知っています - しかし、私はまだ基​​本を掴んでいます。ありがとうございました。Javaプログラミング - ペーパーロッカー用はさみ

import java.util.*;   
import java.util.Scanner; 
import java.util.Random;  
public class Game  
{       
    public static void main (String[] args){  

     int NumberofRoundsPlayed;   
     int NumberofRoundsWonbyHuman = 0; 

     Scanner Keyboard = new Scanner (System.in  

     System.out.println("DO YOU WANT TO PLAY ROCK PAPER SCISSORS- Y/N");      
     String HumanPlaying = Keyboard.nextLine(); 


     if(HumanPlaying ==("No")) 
     { 
      System.out.println("Game Over"); 
      System.exit(0);} 
     }  

    int Paper = 1; 
    int Scissor = 2;  
    int Rock = 3;  

    int HumanSelection; 
    int humanroundsWon =0; 

    System.out.println("HOW MANY ROUNDS DO YOU WANT TO PLAY"); 
    NumberofRoundsPlayed = Keyboard.nextInt();  

    while (NumberofRoundsPlayed <= NumberofRoundsPlayed +1) 
    { 
     Scanner Computer = new Scanner (System.in); 
     Random rand = new Random(); 

     int ComputerChoice =Computer.nextInt(3)+1; 
     System.out.println(ComputerChoice); 

     System.out.println("Select 1 for Paper, 2 for Scissor or 3 for Rock");      
     HumanSelection = Keyboard.nextInt(); 

     //SEE WHO WINS 

     If (ComputerChoice== 1) 
     { 
      If (HumanSelection==1) 
      { 
      System.out.println("Computer and Human Have Tied"); 
      } Else if (HumanSelection==2) 
      { 
       System.out.println("Person Wins"); 
       humanroundsWon == humanroundsWon+1; 
      } 
      Else if (HumanSelection==3) 
      { 
       System.out.println("Computer Wins"); 
      } 

     Else if (ComputerChoice==2) 
     { 
      If (HumanSelection==1) 
      { 
       System.out.println("computer Wins"); 

      } 
      Else if (HumanSelection==2) 
      { 
      System.out.println("Computer and Person Have Tied"); 
      } 
      Else if (HumanSelection==3) 
      { 
       System.out.println("Person Wins"); 
       humanroundsWon == humanroundsWon+1; 

      } 
     } 

     Else if (ComputerChoice==3) 
     { 

    } 
      If (HumanSelection==1) 
      { 
       System.out.println("Person Wins"); 
       humanroundsWon == humanroundsWon+1; 
      } 

     Else if (HumanSelection==2) 
     { 
      {  System.out.println("Computer Wins"); 
      } 

      Else if (HumanSelection==) 
      { 
        System.out.println("Tie"); 
        roundsWon == roundsone+1; 
      } 
     } 
     } 
    } 
    } 
} 

     System.out.println("Game Over"); 
      System.exit(0);} 
+0

どのように動作しませんか? – elhefe

+1

'humanroundsWon == humanroundsWon + 1;'おそらく 'humanroundsWon = humanroundsWon + 1;'でなければなりません。または 'humanroundsWon + = 1;'。または 'humanroundsWon ++;' –

+0

おかげさまでelhefe。主にプログラムの主要部分が始まるときに文法エラーがたくさん出る - コンピュータが「人間」と一緒に乱数を選択した後、 - この行に複数のマーカーがある \t - トークンに構文エラーがある \tこのトークン \t - トークンの構文エラー、置き換えられた構文 \t - このトークンの後には、 "{"が必要です。私はこの段階で基礎を理解することに問題があります。だから私はこのエラーコードをどうすればいいのか分かりません。 – Chris

答えて

1

あなたのシナリオを正しく理解していれば、ここにコードがあります。質問をするときには、codeが実際に実行する必要があるものを示し、他の人があなたを助けることができるようにします。ちょっとしたヒント、コーディングに役立つeclipseのようなIDEを使ってみてください。あなたはそれを見つけることができますhereEclipse IDE for Java EE Developersプラットフォームアーキテクチャ(32bitまたは64bit)に応じてダウンロードし、zipファイルを抽出します。その後、eclipse IDEを実行すると、それは簡単です

import java.util.*;   
import java.util.Scanner; 
import java.util.Random;  
public class Game  
{       
    public static void main (String[] args){  

     int NumberofRoundsPlayed;   
     int NumberofRoundsWonbyHuman = 0; 

     Scanner Keyboard = new Scanner (System.in);  

     System.out.println("DO YOU WANT TO PLAY ROCK PAPER SCISSORS- Y/N");      
     String HumanPlaying = Keyboard.nextLine(); 


     if(HumanPlaying.equals("No")) 
     { 
      System.out.println("Game Over"); 
      System.exit(0); 
     } 



     int Paper = 1; 
     int Scissor = 2;  
     int Rock = 3;  

     int HumanSelection; 
     int humanroundsWon =0; 

     System.out.println("HOW MANY ROUNDS DO YOU WANT TO PLAY"); 
     NumberofRoundsPlayed = Keyboard.nextInt();  

     while (NumberofRoundsPlayed < NumberofRoundsPlayed++) 
     { 
      Scanner Computer = new Scanner (System.in); 
      Random rand = new Random(); 

      int ComputerChoice =Computer.nextInt()+1; 
      System.out.println(ComputerChoice); 

      System.out.println("Select 1 for Paper, 2 for Scissor or 3 for Rock");      
      HumanSelection = Keyboard.nextInt(); 

      //SEE WHO WINS 

      if (ComputerChoice== 1) 
      { 
       if (HumanSelection==1) 
       { 
        System.out.println("Computer and Human Have Tied"); 
       } 
       else if (HumanSelection==2) 
       { 
        System.out.println("Person Wins"); 
        humanroundsWon++; 
       } 
       else if (HumanSelection==3) 
       { 
        System.out.println("Computer Wins"); 
       } 
      } 
       else if (ComputerChoice==2) 
       { 
        if (HumanSelection==1) 
        { 
         System.out.println("computer Wins"); 

        } 
        else if (HumanSelection==2) 
        { 
         System.out.println("Computer and Person Have Tied"); 
        } 
        else if (HumanSelection==3) 
        { 
         System.out.println("Person Wins"); 
         humanroundsWon++; 

        } 
       } 

       else if (ComputerChoice==3) 
       { 


        if (HumanSelection==1) 
        { 
         System.out.println("Person Wins"); 
         humanroundsWon++; 
        } 

        else if (HumanSelection==2) 
        { 
         System.out.println("Computer Wins"); 
        } 

        else if (HumanSelection==3) 
        { 
         System.out.println("Tie"); 

        } 
       } 

      } 

     System.out.println("Game Over"); 
     System.exit(0); 
     } 
    } 
+0

こんにちはカズン。あなたのお手伝いをしていただきありがとうございます。とても有難い。そして、あなたは注目を集めています - 次回は、コードが何をする必要があるのか​​を説明しようと努力します。ありがとう、クリス – Chris

+0

ようこそ。私の答えはあなたの問題を解決したので、私の答えを正しいものとして受け入れることで、この「ウェブサイト」に貢献することができます。同じ問題(あなたの問題)便利な答え。 –

0

コンパイルできない場合、Scanner Keyboard = new Scanner (System.inは不完全なステートメントです。

+0

jpfromitありがとうございます。クリス – Chris

関連する問題