2016-04-08 15 views
0

Brauchen Sie bitte eine Anleitung wenn möglich. Neu in Java. Nicht sicher, warum Code unten für Steine, Papiere, Schere Spiel funktioniert nicht. Irgendwelche Vorschläge bitte oder Beratung wäre sehr willkommen. Ich weiß, dass es in diesem großartigen Forum viele Beispiele gibt - aber ich verstehe immer noch die Grundlagen. Vielen Dank.Java Programmierung - Anfänger für Paper Rocks Schere

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

In welcher Weise funktioniert es nicht? – elhefe

+1

'humanroundsWon == humanroundsWon + 1;' sollte wahrscheinlich 'humanroundsWon = humanroundsWon + 1;' sein. Oder 'humanroundsWon + = 1;'. Oder 'humanroundsWon ++;'. –

+0

danke elhefe. Ich bekomme viele Syntaxfehler hauptsächlich, wenn der Hauptteil des Programms startet - dh nachdem der Computer die Zufallszahl zusammen mit dem 'Menschen' auswählt - es heißt: Mehrere Marker an dieser Linie \t - Syntaxfehler auf dem Token "" WIE VIELE ROUNDS WOLLEN SIE "TO PLAY", löschen \t dieses Token \t - Syntaxfehler auf Token (s), fehl am Platze Konstrukt (e) \t - Syntaxfehler auf Token ";", {erwartet nach diesem Token. Ich habe natürlich Schwierigkeiten, zu diesem Zeitpunkt die Grundlagen zu verstehen - also bin ich mir nicht sicher, was ich von diesem Fehlercode halten soll. – Chris

Antwort

1

Hier ist der Code, wenn mein Verständnis Ihres Szenarios korrekt ist. Wenn Sie Fragen stellen, geben Sie an, was die code tatsächlich ausführen muss, damit andere Ihnen helfen können. Und ein kleiner Tipp, versuchen Sie eine IDE wie eclipse zu verwenden, die Ihnen beim Codieren helfen wird. Sie können es finden here herunterladen Eclipse IDE for Java EE Developers entsprechend Ihrer Plattformarchitektur (32bit oder 64bit) und extrahieren Sie die Datei zip. Dann führen Sie die eclipse IDE ist es einfach wie das

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

Hallo Kasun. Vielen Dank für Ihre Hilfe. Sehr geschätzt. Und Sie sind genau richtig - beim nächsten Mal werde ich versuchen zu erklären, was der Code tun muss. Danke, Chris – Chris

+0

Ihre Begrüßung. Da meine Antwort Ihr Problem gelöst hat, können Sie zu dieser "Website" beitragen, indem Sie meine Antwort als die richtige akzeptieren, indem Sie auf das richtige Symbol neben meiner Antwort klicken, so dass jemand mit demselben Problem (Ihr Problem) meine finden wird Antwort nützlich. –

0

Wenn es nicht kompiliert, Scanner Keyboard = new Scanner (System.in ist eine unvollständige Aussage.

+0

Danke jpfromit. Chris – Chris