Java 石头剪刀布游戏

Java 石头剪刀布游戏_第1张图片

public class GAME
{
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter scissor-rock-paper:");
        System.out.println("scissor(0),rock(1),paper(2)");
        int myChoice = sc.nextInt();
        Random rand = new Random();
        int pcChoice = rand.nextInt(3) + 0;
        switch (pcChoice) {
            case 0:
                System.out.println("The computer is scissor.");
                break;
            case 1:
                System.out.println("The computer is rock.");
                break;
            case 2:
                System.out.println("The computer is paper.");
                break;
        }
        switch (myChoice) {
            case 0:
               System.out.println("You are scissor.");
               break;
            case 1:
               System.out.println("You are rock.");
               break;
            case 2:
               System.out.println("You are paper.");
               break;
            default:
               System.out.println("Please enter rightly. Such as scissor(0),rock(1),paper(2)!");
               break;
        }
        int mp = myChoice-pcChoice;
        switch (mp) {
            case -2:
            case 1:
                System.out.println("You won.");
                break;
            case -1:
            case 2:
                System.out.println("You lost.");
                break;
            case 0:
                System.out.println("It's is a draw.");
                break;
        }
	}
}

 

你可能感兴趣的:(java,游戏,开发语言)