16剪刀石头布2.0

import java.util.Scanner;

public class Test16
{
    private String[] options = {"剪刀", "石头", "布"};
    private int userChoice;
    private int computerChoice;

    public void getUserChoice()
    {
        Scanner scanner = new Scanner(System.in);
        System.out.println("*************************");
        System.out.println("      剪刀!石头!布!");
        System.out.println("                作者:EREC");
        System.out.println("              游戏版本:2.0");
        System.out.println("*************************");
        System.out.println("请输入你的选择(0-剪刀,1-石头,2-布):");
        userChoice = scanner.nextInt();
    }
    public void generateComputerChoice()
    {
        computerChoice = (int) (Math.random() * 3);
    }
    public void determineWinner()
    {
        if (userChoice == computerChoice) System.out.println("平局!你和电脑都选择了" + options[userChoice]);
        else if
        ((userChoice == 0 && computerChoice == 2) || (userChoice == 1 && computerChoice == 0) || (userChoice == 2 && computerChoice == 1))
            System.out.println("恭喜你,你赢了!你选择了" + options[userChoice] + ",电脑选择了" + options[computerChoice]);
        else System.out.println("很遗憾,你输了!你选择了" + options[userChoice] + ",电脑选择了" + options[computerChoice]);
    }
    public static void main(String[] args)
    {
        Test16 game = new Test16();
        game.getUserChoice();
        game.generateComputerChoice();
        game.determineWinner();
    }
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值