【发布时间】:2014-03-13 04:53:50
【问题描述】:
我已经用 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);
}
}
【问题讨论】:
标签: java