我是 Java 和编程的新手,我正在尝试使剪刀布摇滚成为电视节目风格。我目前被困在一些事情上,我希望得到一些帮助。我目前在结束分层 while 循环时遇到问题,因此它在获胜者赢得 2 场比赛时结束。另外,我的用户输入有问题。任何帮助,将不胜感激。这是我目前的代码。
import java.util.Random;
import java.util.Scanner;
public class rockPaperScissorsSpock {
public static void main(String[] args) {
String userMove; // User will input moved of P, R, S, O and L as moves
String computerMove = ""; // Computer input move
int computerInput; // number generator that will determine the computers move
int userScore = 0;
int computerScore=0;
int numberOfGames=0;
/* this is the introduction to the game. And explaining the rules */
System.out.println(
"Welcome to the game of Paper Rock Scissors Spock!\n\nTHE RULES OF THIS GAME ARE AS FOLLOWS: Scissors cuts paper. Paper covers Rock. Rock crushes lizard."
+ "Lizard poisons spock. Spock smashes scissors.\nSpock vaporizes rock. Rock crushes scissors. Scissors decapitates lizard."
+ "Lizard eats paper. And paper disproves spock.\n ");
System.out.println(
"To play the moves, you must input the variable associated:\n Paper = P\n Rock = R\n Scissors = S\n Spock = O\n Lizard =L\n\n");
while(true){
do {
// getting the user input
Scanner scan = new Scanner(System.in);
Random randomGenerator = new Random();
System.out.println();
// this creates a random number generator for the computers. The number will be
// associated with a move
computerInput = randomGenerator.nextInt(5) + 1;
// assigning moves to an Int
if (computerInput == 1) {
computerMove = "P";
}
else if (computerInput == 2) {
computerMove = "R";}
else if (computerInput == 3) {
computerMove = "S";}
else if (computerInput == 4) {
computerMove = "O";}
else if (computerInput == 5) {
computerMove = "L";
}
慕慕森
慕桂英546537
相关分类