gpt4 book ai didi

java - 我的剪刀石头布游戏不会显示平局

转载 作者:行者123 更新时间:2023-12-02 06:12:29 24 4
gpt4 key购买 nike

我已经用 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);
}
}

最佳答案

您似乎正在尝试比较 "1""Paper"并期待true .

要么进行两个比较true ,即将用户输入与 "1" 进行比较并将计算机发送至"Paper" ,或翻译"1""Paper" (以及相应的其他两个值)并直接比较响应。

关于java - 我的剪刀石头布游戏不会显示平局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21769024/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com