私は、プログラム内でユーザーの勝敗の数を表示する必要があります。ループの問題を解決するのに私は永遠にかかったが、ついにそれを手に入れた。私はJavaに慣れていませんが、以前はHTMLやその他のスクリプト言語でコード化していました。ロックペーパーはさみトカゲSpock
import java.io.InputStream;
import java.util.Random;
import java.util.Scanner;
public class RPSLS {
//AUTHOR: JOSEPH CLAY
//TODO make program continue until user chooses to stop.
//TODO then print # of user wins, losses, and ties.
public static void main(String[] args) {
//declare objects
String user;
String comp= "";
Random comprand;
String answer=null;
do
{
//scanner and random setup and imported
Scanner scan=new Scanner(System.in);
//Random gen=new Random();
//prompt to play game/instructions
System.out.println("Yo, let's play a game of Rock, Paper, Scissors, Lizard, Spock");
System.out.println("Please enter R for rock, P for paper, S for scissors, L for lizard, or V for Spock");
//User selection input
System.out.println("Pick your poison: ");
user=scan.next();
//Randomly generated # of 5
System.out.println();
comprand=new Random();
int x=comprand.nextInt(5)+1;
//translate random # to string
if(x==1)
comp="R";
else if(x==2)
comp="P";
else if(x==3)
comp="S";
else if(x==4)
comp="L";
else if(x==5)
comp="V";
//capitalize user selection
user=user.toUpperCase();
//print computer choice
System.out.println("Your adversary chose: "+comp);
//conditions of possible outcomes
//tie
if (user.equals(comp))
System.out.println("Tie!");
//if user enters r
else if (user.equalsIgnoreCase("R"))
if (comp.equals("S"))
System.out.println("Rock crushes scissors. You win!");
else if (comp.equals("P"))
System.out.println("Paper envelopes rock. You lose.");
else if (comp.equals("L"))
System.out.println("Rock destroys lizard. You win!");
else if (comp.equals("V"))
System.out.println("Spock crushes rock. You lose.");
//if user enters p
if (user.equalsIgnoreCase("P"))
if (comp.equals("R"))
System.out.println("Paper envelopes rock. You win!");
else if (comp.equals("S"))
System.out.println("Scissors cuts paper. You lose");
else if (comp.equals("L"))
System.out.println("Lizard eats paper. You lose.");
else if (comp.equals("V"))
System.out.println("Paper disproves Spock. You win!");
//if user enters s
if (user.equalsIgnoreCase("S"))
if (comp.equals("R"))
System.out.println("Rock crushes scissors. You lose.");
else if (comp.equals("P"))
System.out.println("Scissors cuts paper. You win!");
else if (comp.equals("L"))
System.out.println("Scissors eviscerates lizard. You win!");
else if (comp.equals("V"))
System.out.println("Spock vaporizes scissors. You lose.");
//if user enters l
if (user.equalsIgnoreCase("L"))
if (comp.equals("R"))
System.out.println("Rock crushes lizard. You lose.");
else if (comp.equals("P"))
System.out.println("Lizard eats paper. You win!");
else if (comp.equals("S"))
System.out.println("Scissors eviscerate lizard. You lose.");
else if (comp.equals("V"))
System.out.println("Lizard poisons Spock. You win!");
//if user enters v
if (user.equalsIgnoreCase("V"))
if (comp.equals("R"))
System.out.println("Spock crushes rock. You win!");
else if (comp.equals("P"))
System.out.println("Paper disproves Spock. You lose!");
else if (comp.equals("S"))
System.out.println("Spock vaporizes scissors. You win!");
else if (comp.equals("L"))
System.out.println("Lizard poisons Spock. You lose.");
System.out.println("Would you like to continue? (yes or no)");
answer = scan.next();
}
while(answer.equals("y"));
while (answer.equalsIgnoreCase("n"))
break;
}
}
質問を編集して、スタックトレースを理想的に示して何がうまくいかないのかを伝える必要があります。 – paisanco
現在、すべて正常に動作しており、エラーメッセージはありません。私は、ユーザーの勝利、損失、または絆の量を読み取り、印刷する機能を実装する方法がわかりません。 –