13章 人机猜拳

package com.dd;

import java.util.Scanner;

public class guess {
	String name;
	int Score;

	public int showguess() {
		System.out.println("请出拳:1.剪刀  2.石头  3.布(请输入相应数字):");
		Scanner input = new Scanner(System.in);
		int g = input.nextInt();
		switch (g) {
		case 1:
			System.out.println("你出拳:剪刀");
			break;
		case 2:
			System.out.println("你出拳:石头");
			break;
		case 3:
			System.out.println("你出拳:布");
			break;
		}
		return g;
	}

}
******************************


 

 


 

package com.dd;

public class computer {
	String name;
	int Score;
	computer guess;

	public int showcomputer() {
		int random = (int) (Math.random() * 3 + 1);
		switch (random) {
		case 1:
			System.out.println("电脑出拳:剪刀");
			break;
		case 2:
			System.out.println("电脑出拳:石头");
			break;
		case 3:
			System.out.println("电脑出拳:布");
			break;
		}
		return random;
	}
}

游戏类


package com.dd;

import java.util.Scanner;

public class games {

	guess jia;
	computer yi;
	int count;

	public void initial() {
		jia = new out();
		yi = new out11();

		count = 0;
	}

	public void showgames() {
		initial();
		System.out.println("----------欢迎进入游戏世界-----------");
		System.out.println("**********************************");
		System.out.println("***   猜拳,开始         ***");
		System.out.println("**********************************");
		System.out.println("出拳规则:1.剪刀  2.石头  3.布");
		System.out.println("请选择对方角色(1:刘备   2:孙权  3:曹操):");
		Scanner input = new Scanner(System.in);
		int h = input.nextInt();
		switch (h) {
		case 1:
			yi.name = "刘备";
			break;
		case 2:
			yi.name = "孙权";
			break;
		case 3:
			yi.name = "曹操";
			break;
		}
		System.out.println("请输入你的名字:");
		jia.name = input.next();
		System.out.println("你选择了" + yi.name + "对战");
		System.out.println("要开始吗?y:是  n:否");
		String sum = input.next();
		while (sum.equals("y")) {
			int y;
			int y1;
			if (sum.equals("y")) {
				y = jia.showout();
				y1 = yi.showout11();
				if ((y == 1 && y1 == 1) || (y == 2 && y1 == 2)
						|| (y == 3 && y1== 3)) {
					System.out.println("结果:和局,真衰!");
				} else if ((y == 1 && y1== 3) || (y == 2 && y1 == 1)
						|| (y== 3 && y1== 2)) {
					System.out.println("结果:恭喜,你赢了!");
					jia.Score++;
				} else {
					System.out.println("结果说:^_^,你输了,真笨!");
					yi.Score++;
				}
				count++;
			}

			System.out.println("是否进行下一轮.y:是   n:否");
			sum = input.next();
		}
		showmm();
	}

	public void showmm() {
		System.out.println("-----------------------------");
		System.out.println(jia.name + " VS " + yi.name);
		System.out.println("对战次数:" + count);
		System.out.println("姓名" + "\t" + "积分");
		System.out.println(jia.name + "\t" + jia.Score);
		System.out.println(yi.name + "\t" + yi.Score);

		if (jia.Score > yi.Score) {
			System.out.println("客户赢了");

		} else if (jia.Score < yi.Score) {
			System.out.println("电脑赢了");

			System.out.println("-----------------------------");
		}
	}

}



 

 
显示方法
<pre class="java" name="code">package com.dd;

import java.util.Scanner;

public class dada{

	public static void main(String[] args) {
		guess guess= new guess();

		games games = new games();
		games.showgames();
		computer computer = new computer();

	}
}

 





 

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值