Java怎么实现拳皇小程序
作者:吹吹风会发光
时间:2023-04-26
浏览:0
代码如下:packagehelloasd;importjava.util.*;publicclasshellojava{publicstaticvoidmain(String[]args){Scannerinput=newScanner(System.in);System.out.print("输入名称:");//用户自己输入名字Stringusername=input.next();Stringcomname="阿杰";System.out.println(username+"vs"+comname);
代码如下:
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 + "获胜!");
}
}
}
作者最新文章
iphone蓝牙连接ipad有什么用及连接方法教程
2026-09-21 17:28
PDF怎么取消密码保护?4种解锁方法整理
2026-09-08 18:23
三星 Galaxy Z Fold8 内屏边角支撑偏软?实测与官方回应
2026-09-08 16:39
手机Excel表格制作教程:小屏幕高效录入与格式调整指南
2026-09-04 09:27
PDF文档按页转换成图片怎么做?在线转换步骤整理
2026-09-03 11:06
上一篇:
如何创建MySQL存储过程?
热门文章
更多
精品专题
更多
Mac软件
更多
WINDOWS
更多


































