欢迎光临
我们一直在努力

Java怎么实现拳皇小程序

这篇文章主要介绍了Java怎么实现拳皇小程序的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇Java怎么实现拳皇小程序文章都会有所收获,下面我们一起来看看吧。

代码如下:

package helloasd;import java.util.*;
public class hellojava {
		public static void main(String[] args) {
			Scanner input = new Scanner(System.in);
			System.out.print("输入名称: ");
			//用户自己输入名字
			String username = input.next();
			String comname = "阿杰";
			System.out.println(username + "vs" + comname);
			//初始化双方数据
			int hp1 = 100, hp2 = 100;       //双方的HP  
			int attack1 = 0, attack2 = 0;

			//使用循环模拟对战过程
			while(hp1 > 0 && hp2 > 0) {
				attack1 = (int)(Math.random() * 1000) % 11 + 5; //双方随机的攻击力(10~15)
				attack2 = (int)(Math.random() * 1000) % 11 + 5; 

				//玩家先攻击
				hp2 -= attack1; //玩家攻击,电脑掉血
				System.out.println(comname + ": " + hp2);
				if(attack1 > 0 && attack1 <=5) {
					System.out.println("阿杰被命中攻击!");
				}
				else if(attack1 > 5 && attack1 <=10) {
					System.out.println("阿杰被重重的攻击!");
				}
				else {
					System.out.println("阿杰被致命一击!");
				}

				//显示电脑血量

				hp1 -= attack2; //电脑攻击,玩家掉血
				System.out.println(username + ": " + hp2);
				//显示玩家血量
				if(attack1 > 0 && attack1 <=5) {
					System.out.println(username + "被" + comname + "侥幸攻击了一下!");
				}
				else if(attack1 > 5 && attack1 <=10) {
					System.out.println(username + "遇到了强烈进攻!");
				}
				else {
					System.out.println(username + "被沉重打击!");
				}

				System.out.println("\n");
			}
			//打印结果
			System.out.println("\n");
			System.out.println("KO!");
			System.out.println("玩家姓名\t血量");
			System.out.println(username + "\t" + hp1);
			System.out.println(comname + "\t" + hp2);
			if(hp1 < 0) {
				System.out.println("阿杰获胜!");
			}
			else {
				System.out.println(username + "获胜!");
			}
	}
}

关于“Java怎么实现拳皇小程序”这篇文章的内容就介绍到这里,感谢各位的阅读!相信大家对“Java怎么实现拳皇小程序”知识都有一定的了解,大家如果还想学习更多知识,欢迎关注云搜网行业资讯频道。

赞(0)
【声明】:本博客不参与任何交易,也非中介,仅记录个人感兴趣的主机测评结果和优惠活动,内容均不作直接、间接、法定、约定的保证。访问本博客请务必遵守有关互联网的相关法律、规定与规则。一旦您访问本博客,即表示您已经知晓并接受了此声明通告。