Я пытаюсь создать игру «Спок ящерицы Rock Paper Scissors» и хочу, чтобы пользователь мог вводить целые числа, присвоенные переменным (Rock=0, Paper=1, Scissors=2, Lizard=3 and Spock=4)
, а также вводить слова "Rock", "Paper", "Scissors", "Lizard"
или "Spock"
. Не могли бы вы помочь мне включить часть кода, где я могу назначить строковые входы целым числам. Я также не хочу менять основной каркас кода. Я также знаю, что на веб-сайте написано, что не нужно вставлять весь файл, но я не могу придумать другой способ показать мою проблему. Обратите внимание, что я использую веб-сайт под названием SoloLearn . Любая помощь будет принята с благодарностью.
import java.util.Scanner;
public class RockPaperScissorsLizardSpock {
final static int ROCK = 0;
final static int PAPER = 1;
final static int SCISSORS = 2;
final static int LIZARD = 3;
final static int SPOCK = 4;
public static void main(String[] args) {
double r = Math.random();
int computerChoice = (int)(3.0 * r);
Scanner input = new Scanner(System.in);
System.out.print("Enter 0 for Rock, 1 for Paper, 2 for Scissors, 3 for Lizard, 4 for Spock: ");
int playerChoice = input.nextInt();
System.out.println(computerChoice);
int playerChoice = 0;
switch (playerChoice) {
case "Rock":
playerChoice = 0;
break;
case "Paper":
playerChoice = 1;
break;
case "Scissors":
playerChoice = 2;
case "Lizard":
playerChoice = 3;
case "Spock":
playerChoice = 4;
if (computerChoice == playerChoice) {
System.out.println("Tie");
}
else if (computerChoice == ROCK && playerChoice == SCISSORS) {
System.out.println("I chose Rock,You chose Scissors, Rock crushes Scissors, You lose.");
}
else if (computerChoice == SCISSORS && playerChoice == PAPER) {
System.out.println("I chose Scissors, You chose Paper, Scissors cut Paper, You lose.");
}
else if (computerChoice == PAPER && playerChoice == ROCK) {
System.out.println("I chose Paper,You chose Rock, Paper covers Rock, You lose.");
}
else if (computerChoice == LIZARD && playerChoice == PAPER) {
System.out.println("I chose Lizard, You chose Paper, Lizard eats Paper, You lose.");
}
else if (computerChoice == SPOCK && playerChoice == SCISSORS) {
System.out.println("I chose Spock, You chose Scissors, Spock smashes Scissors, You lose.");
}
else if (computerChoice == ROCK && playerChoice == LIZARD) {
System.out.println("I chose Rock, You chose Lizard, Rock crushes Lizard, You lose.");
}
else if (computerChoice == SCISSORS && playerChoice == LIZARD) {
System.out.println("I chose Scissors, You chose Lizard, Scissors decapitates Lizard, You lose.");
}
else if (computerChoice == SPOCK && playerChoice == PAPER) {
System.out.println("I chose Spock, You chose Paper, Paper disproves Spock, You lose.");
}
else if (computerChoice == SPOCK && playerChoice == ROCK) {
System.out.println("I chose Spock, You chose Rock, Spock vaporizes Rock, You lose.");
}
else if (computerChoice == SCISSORS && playerChoice == ROCK) {
System.out.println("I chose Scissors, You chose Rock, Rock crushes Scissors, You win.");
}
else if (computerChoice == PAPER && playerChoice == SCISSORS) {
System.out.println("I chose Paper, You chose Scissors, Scissors cut Paper, You win.");
}
else if (computerChoice == ROCK && playerChoice == PAPER) {
System.out.println("I chose Rock, You chose Paper, Paper covers Rock,You win.");
}
else if (computerChoice == PAPER && playerChoice == LIZARD) {
System.out.println("I chose Paper, You chose Lizard, Lizard eats Paper, You win.");
}
else if (computerChoice == SCISSORS && playerChoice == SPOCK) {
System.out.println("I chose Scissors, You chose Spock, Spock smashes Scissors, You win.");
}
else if (computerChoice == LIZARD && playerChoice == ROCK) {
System.out.println("I chose Lizard, You chose Rock, Rock crushes Lizard, You win.");
}
else if (computerChoice == LIZARD && playerChoice == SCISSORS) {
System.out.println("I chose Lizard, You chose Scissors, Scissors decapitates Lizard, win.");
}
else if (computerChoice == PAPER && playerChoice == SPOCK) {
System.out.println("I chose Paper, You chose Spock, Paper disproves Spock, You win.");
}
else if (computerChoice == ROCK && playerChoice == SPOCK) {
System.out.println("I chose Rock, You chose Spock, Spock vaporizes Rock, You win.");
}else{
System.out.println("Error");
}
}
}
}