本篇内容主要讲解“怎么用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实现拳皇小程序”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。
原文链接:https://my.oschina.net/u/4593692/blog/4465862