摇滚/纸/剪刀/蜥蜴/ Spock,输出错误

时间:2017-09-21 21:23:47

标签: java

这项任务的灵感来自电视节目“生活大爆炸”,你将实现Rock,Paper,Scissors,Lizard,Spock作为Java程序。正如Sheldon在节目中解释的那样,

  

剪刀剪纸,纸覆盖岩石,岩石蜥蜴,蜥蜴   毒药Spock,Spock砸剪刀,剪刀斩首蜥蜴,   蜥蜴吃纸,纸反驳Spock,Spock蒸发岩石,和   它总是有,岩石压碎剪刀。

我的问题是,当我输入我的代码时,它说在请求玩家输入后出现的代码不应该在那里,有没有办法我可以删除它或者我错过了更大的部分?

import java.util.Random;
import java.util.Scanner;
public class P3 {

public static void main(String[] args) {
    int playerChoice = 0;
    int computerChoice = 0;
    int seedVariable = 0;
    Scanner read = new Scanner(System.in);

    System.out.print("Please enter a seed: ");
    seedVariable = read.nextInt();
    System.out.println(" ");

    System.out.println("Which game object do you choose?"+System.lineSeparator()+ "For rock, enter 1."+System.lineSeparator()+"For paper, enter 2."+System.lineSeparator()+"For scissors, enter 3."+System.lineSeparator()+"For lizard, enter 4."+System.lineSeparator()+"For Spock, enter 5.");
    playerChoice = read.nextInt();

    System.out.println("Your choice:  " + playerChoice);
    //System.out.print("Your choice: ");
    //playerChoice = read.nextInt();
    //System.out.println(" ");

    Random r = new Random();
    r.setSeed(seedVariable);
    computerChoice = r.nextInt(4) + 1;

    System.out.println("Computer's choice: " + computerChoice);
    System.out.println(" ");

    switch (playerChoice) {
    case 1: //rock
        if(playerChoice == computerChoice)
            System.out.println("Computer generated same choice. Draw game.");
        if(playerChoice == 1 && computerChoice == 3)
            System.out.println("Rock crushes scissors. Player wins.");
        if(playerChoice == 1 && computerChoice == 4)
            System.out.println("Rock crushes lizard. Player wins.");
        if(playerChoice == 1 && computerChoice == 2)
            System.out.println("Paper covers rock. Computer wins.");
        if(playerChoice == 1 && computerChoice == 5)
            System.out.println("Spock vaporizes rock. Computer wins");
        break;

    case 2: //paper
        if(playerChoice == computerChoice)
            System.out.println("Computer generated same choice. Draw game.");
        if(playerChoice == 2 && computerChoice == 1)
            System.out.print("Paper covers rock. Player wins.");
        if (playerChoice == 2 && computerChoice == 5)
            System.out.println("Paper disproves Spock. Player wins");
        if(playerChoice == 2 && computerChoice == 3)
            System.out.println("Scissors cuts paper. Computer wins.");
        if(playerChoice == 2 && computerChoice == 4)
            System.out.println("Lizard eats paper. Computer wins.");
        break;

    case 3: //scissors
        if(playerChoice == computerChoice)
            System.out.println("Computer generated same choice. Draw game.");
        if(playerChoice == 3 && computerChoice == 2)
            System.out.println("Scissors cuts paper. Player wins.");
        if(playerChoice == 3 && computerChoice == 4)
            System.out.println("Scissors decapitates lizard. Player wins.");
        if(playerChoice == 3 && computerChoice == 1)
            System.out.println("Rock crushes scissors. Computer wins.");
        if(playerChoice == 3 && computerChoice == 5)
            System.out.println("Spock smashes scissors. Computer wins.");
        break;

    case 4: //lizard
        if(playerChoice == computerChoice)
            System.out.println("Computer generated same choice. Draw game.");
        if(playerChoice == 4 && computerChoice == 2)
            System.out.println("Lizard eats paper. Player wins.");
        if(playerChoice == 4 && computerChoice == 5)
            System.out.println("Lizard poisons Spock. Player wins.");
        if(playerChoice == 4 && computerChoice == 1)
            System.out.println("Rock crushes lizard. Computer wins.");
        if(playerChoice == 4 && computerChoice == 3)
            System.out.println("Scissors decapitates lizard. Computer wins.");
        break;

    case 5://Spock
        if(playerChoice == computerChoice)
            System.out.println("Computer generated same choice. Draw game.");
        if(playerChoice == 5 && computerChoice == 1)
            System.out.println("Spock vaporizes rock. Player wins.");
        if(playerChoice == 5 && computerChoice == 3)
            System.out.println("Spock smashes scissors. Player wins.");
        if(playerChoice == 5 && computerChoice == 2)
            System.out.println("Paper disproves Spock. Computer wins.");
        if(playerChoice == 5 && computerChoice == 4)
            System.out.println("Lizard poisons Spock. Computer wins.");
        break;

    default: 
        System.out.println("1,2,3,4,or 5 was not entered. Try playing again.");
        read.close();
    }

}

}

0 个答案:

没有答案