我是 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"; }
2 回答
慕桂英546537
TA贡献1848条经验 获得超10个赞
你可以让这更容易一点,如果没有那么多。如果创建像 5 - Sc, 4 - P, 3 - R, 2 - L, 1 - S 这样的地图(哈希图),您可以看到获胜模式。如果差是偶数,则第一个获胜。如果差异是奇数,则第二个获胜。例如,P - R = 1 - 纸盖岩,Sc - L = 3 - 剪刀斩首蜥蜴,R - S = 2 - 在这种情况下,Spock 蒸发岩石并获得第二名。(如果答案是否定的,则全部反转)并摆脱双循环,1 就足够了
添加回答
举报
0/150
提交
取消