JavaWeb开发实战指南----出拳游戏

本文详细介绍了使用JavaWeb技术开发出拳游戏的过程,涵盖了前端交互、后端逻辑及胜负判断等关键环节,旨在帮助开发者提升实战技能。
摘要由CSDN通过智能技术生成
/**
*@Title: ${filename}
*@Package: ${package_name}
*@Description: ${todo}
*
出拳游戏
一个人机对战的游戏
分别出拳 石头 剪刀 布
石头 对剪刀  石头胜
剪刀对布      剪刀胜
布对石头      布胜

人  从键盘接收0,1,2的数字,分别表示石头,剪刀,布
机器,随机出拳 0,1,2

解决问题
1、随机
2、判断输赢
3*3=9
人  r        机器 c       r-c 结果
0				0				0		平
0				1				-1		人胜
0				2				-2		机器胜

1				0				1		机器胜
1				1				0		平
1				2				-1		人胜

2				0				2		人胜
2				1				1		机器胜
2				2				0		平

r-c 结果为0  平局
r-c 结果为-2,1,机器胜
r-c 结果为-1,2,人胜
*
*@author:  源代码资料尽在"清哥好课堂"公众号:qghktit
*@date: ${date}${time}
*@version: 1.0
*/
import java.util.Random;
import java.util.Scanner;
//import java.util.*
public class  FistGame
{
	public static void main(String[] args) 
	{
		//出拳游戏
		//0、说明一下游戏的规则
		System.out.println("************************************");
		System.out.println("\t一款人机出拳对战游戏");
		System.out.println("\t机器:自动出拳");
		System.out.println("\t人:手动出拳");
		System.out.println("\t0--石头,1--剪刀,2-布");
		System.out.println("************************************");
		//1、人出拳
		System.out.println("请出拳:(0,1,2)");
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		//输出人出的是什么鬼
		if(r>=0 && r<=2)
		{
			if (r==0) //石头
			{
				System.out.println("您出的是:石头");
			}
			else if (r==1) //剪刀
			{
				System.out.println("您出的是:剪刀");
			}
			else  //布
			{
				System.out.println("您出的是:布");
			}			
		}
		//2、机器出拳
		Random rand = new Random();
		int c = rand.nextInt(3); //随机出0,1,2
		if (c==0) //石头
		{
			System.out.println("机器出的是:石头");
		}
		else if (c==1) //剪刀
		{
			System.out.println("机器出的是:剪刀");
		}
		else  //布
		{
			System.out.println("机器出的是:布");
		}
		//3、判断输赢
		/*
		r-c 结果为0  平局
		r-c 结果为-2,1,机器胜
		r-c 结果为-1,2,人胜
		其它 人出拳错误
		*/
		int res = r - c;
		if (res == 0)  //平局
		{
			System.out.println("平局");
		}
		else if (res==-2 || res==1)  //机器胜
		{
			System.out.println("机器胜");
		}
		else if (res==-1 || res==2)  //人胜
		{
			System.out.println("恭喜,您胜了");
		}
		else  //人出拳错误
		{
			System.out.println("抱歉,您出拳错误");
		}
	}
	public static void main1(String[] args) 
	{
		//随机
		/*
		1、导包 import java.util.Random;
		2、申请随机器
		3、产生随机值
		*/
		Random rand = new Random();
		//产生随机数 0 1 2 3 4中的随机数
//		int r = rand.nextInt(5);  //从0到括号中数-1 中任意数
//		//输出
//		System.out.println(r);

		//要求得到6-11之间的随机数
		// 0-5
		//r + 6
		int r = rand.nextInt(6) + 6;
		System.out.println(r);
	}
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值