Java日報
部門:**大資料開發六部
姓名:cqmfx
日期:2020.10.27
練習——打怪小游戲
/**
* 2020/10/27
*
* @author cqmfx(阡陌飛絮)
*/
import java.util.*;
public class HeroGame {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("請輸入英雄的名字:");
String heroName = scanner.next();
System.out.println("請輸入英雄的血量:");
int heroBoold = scanner.nextInt();
System.out.println("請輸入英雄的攻擊力");
int heroAttack = scanner.nextInt();
System.out.println("請輸入英雄的防御力:");
int heroDefense = scanner.nextInt();
String bossName = "魔王";
int bossBlood = 1000;
int bossAttack = 50;
int bossDefense = 30;
System.out.println("開始戰斗!!!");
for (int i = 1;heroBoold > 0 && bossBlood > 0;i++){
System.out.println();
sleep(800);
System.out.println("第" + i + "回合");
sleep(800);
System.out.println();
System.out.println(heroName + "打了" + bossName + "一下," + bossName + "受到了" + (heroAttack - bossDefense) + "點傷害,血量剩余" + (heroBoold-(heroAttack - bossDefense)) + "點");
sleep(800);
System.out.println();
System.out.println(bossName + "打了" + heroName + "一下," + heroName + "受到了" + (bossAttack - heroDefense) + "點傷害,血量剩余" + (bossBlood-(heroAttack - bossDefense)) + "點");
// 掉血
heroBoold -= (bossAttack - heroDefense);
bossBlood -= (heroAttack - bossDefense);
}
if (heroBoold <= 0){
System.out.println();
System.out.println("真菜!");
System.out.println();
System.out.println("你被"+bossName+"打死了!");
}
if (bossBlood <= 0){
System.out.println();
System.out.println("好強!");
System.out.println();
System.out.println(bossName+"被你打死了!");
}
}
public static void sleep(int time){
try {
Thread.sleep(time);
} catch (Exception e) {
e.printStackTrace();
}
}
}
運行結果

還可以進行游戲升級,這兒是最基本的
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/197268.html
標籤:java
