import java.applet.Applet;
import java.applet.AudioClip;
import java.io.File;
import java.net.MalformedURLException;
import java.util.Scanner;
public class KolDemo {
public static void main(String[] args) throws MalformedURLException, InterruptedException {
Scanner input = new Scanner(System.in);
//1.插入音乐
//播放音乐代码
// File sound1 = new File("sounds/hit.wav");
// AudioClip sound_choose = Applet.newAudioClip(sound1.toURL());
// sound_choose.play();//播放音乐
System.out.print("请输入玩家名称:");//提示输入玩家名称
String username = input.next();//玩家输入名字
String cpuname = "大蛇丸";//定义电脑玩家的名称
System.out.println(username + "Vs" + cpuname);
int hp1 = 100;
int hp2 = 100;//定义Hp血量值为100
int attack1 = 0, attack2 = 0;
// Thread.sleep(500);//单位为毫秒,指程序暂停500毫秒后开始执行
// sound_choose.stop();//暂停音乐播放
while(hp1 > 0 && hp2 >= 0) {//定义循环的条件,玩家和电脑的血量大于0时,执行循环
attack1 = (int)(Math.random() * 10000) % 11 + 5;//随机生成玩家的攻击力
attack2 = (int)(Math.random() * 10000) % 11 + 5;//随机生成电脑的攻击力
hp2 -= attack1;//电脑玩家的血量 == 100 - 玩家的伤害
// sound_choose.stop();//暂停音乐
// sound1 = new File("sounds/hit.wav");
// sound_choose = Applet.newAudioClip(sound1.toURL());
// sound_choose.play();//播放音乐
Thread.sleep(1000);//暂停1000毫秒用来播放音乐
System.out.println(username + "有力的攻击了" + cpuname + "," + cpuname + "剩余血量为:" + hp2);
hp1 -= attack2;
// sound_choose.stop();//暂停音乐
// sound1 = new File("sounds/hit.wav");
// sound_choose = Applet.newAudioClip(sound1.toURL());
// sound_choose.play();//播放音乐
Thread.sleep(1000);
System.out.println(cpuname + "回击了" + username + "一下" + "," + username + "剩余血量为" + hp1);
}
if(hp1 > hp2) {
System.out.println(username + "击败了" + cpuname + "\n" +username + "剩余血量为:" + hp1);
}else
System.out.println(cpuname + "击败了" + username + "\n" + cpuname + "剩余血量为:" + hp2);
}
}
java实例之拳皇
最新推荐文章于 2024-02-19 22:04:47 发布