JOptionpane对话框游戏剪刀石头布

import java.util.Scanner;

import javax.swing.JOptionPane;

public class Wukexing {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner input = new Scanner(System.in);

		int option = JOptionPane.YES_OPTION;
		while (option == JOptionPane.YES_OPTION) {
			int wo = 0, ta = 0, i = 1;
			while (true) {
				System.out.println("第" + i + "局输入如下:");
				System.out
						.println("你的输入是:scissor for 0,rock for 1,paper for 2");
				int a = input.nextInt();
				System.out
						.println("计算机的输入是:scissor for 0,rock for 1,paper for 2");
				System.out.println();
				int b = (int) (Math.random() * 3); // 产生一个0~2的随机数并赋给计算
				if (a - b == 1 || a - b == -2) {
					wo++;
					System.out.println("第" + i + "次,你赢了");

				} else if (b - a == 1 || b - a == -2) {
					ta++;
					System.out.println("第" + i + "次,计算机赢了");
				} else
					System.out.println("第" + i + "次,平局了");
				if (wo > 1 || ta > 1)
					break;
				i++;
			}
			if (wo > 1)
				System.out.println("最终结果是你赢了");
			else
				System.out.println("最终结果是计算机赢了");
			option = JOptionPane.showConfirmDialog(null, "Continue");

		}

	}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值