我已經寫在BlueJ岩石剪刀代碼和迄今爲止一切工作很好......除了一件事。當我和電腦綁在一起時,遊戲不會告訴我。它會告訴我電腦使用了什麼,它會告訴我,如果我贏了或輸了。但是,如果我綁定了,它只會告訴我電腦使用了什麼,而忽略了這條領帶。代碼如下。 ~~~我的岩石紙剪刀遊戲將不會顯示關係
/**
*A simple game of Rock Paper Scissors.
*
*@author Erik Ingvoldsen
*@version 1.0
*/
import java.util.Scanner;
import java.util.Random;
public class Rock
{
public static void main(String[] args)
{
String playAgain = "4";
do
{
String personPlay;
String computerPlay = "";
int computerInt;
String response;
Scanner scan = new Scanner(System.in);
Random generator = new Random();
System.out.println(" ");
System.out.println("Press 1 for Rock, 2 for Scissors, 3 for Paper, and 4 to quit.");
System.out.println();
computerInt = generator.nextInt(3)+1;
if (computerInt == 1)
computerPlay = "Rock";
else if (computerInt == 2)
computerPlay = "Scissors";
else if (computerInt == 3)
computerPlay = "Paper";
//1=Rock 2=Scissors 3=Paper
{System.out.println("Rock Paper Scissors: ");
{personPlay = scan.next();
System.out.println("Computer chooses: " + computerPlay);
if (personPlay.equals(computerPlay)){
System.out.println("It's a tie!");}
else if (personPlay.equals("1")){
if (computerPlay.equals("Paper"))
System.out.println("Paper beats rock. Loser.");
else if (computerPlay.equals("Scissors"))
System.out.println("Rock beats scissors. Winner.");}
else if(personPlay.equals("2")){
if (computerPlay.equals("Paper"))
System.out.println("Scissors beats paper. Winner");
else if (computerPlay.equals("Rock"))
System.out.println("Rock beats scissors. Loser.");}
else if (personPlay.equals("3")) {
if (computerPlay.equals("Rock"))
System.out.println("Paper beats rock. Winner.");
else if (computerPlay.equals("Scissors"))
System.out.println("Scissors beats paper. Loser.");}
else
System.out.println("Not a valid key. Cheaters never win.");}
System.out.println("Press 4 to quit or any other key to continue.");
Scanner End = new Scanner(System.in);
String quit=End.nextLine();
if(quit.equals("4"))
{
System.exit(0);}
}
}while(true);
}
}