代码如下:
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实现拳皇小程序的详细内容。