您好,登錄后才能下訂單哦!
這篇文章主要介紹Java如何實(shí)現(xiàn)拳皇小程序,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!
剛開始學(xué)習(xí)Java,看完老九君的視頻根據(jù)他的內(nèi)容敲的代碼,感覺還挺有成就感的,畢竟剛學(xué)習(xí)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); //初始化雙方數(shù)據(jù) int hp1 = 100, hp2 = 100; //雙方的HP int attack1 = 0, attack2 = 0; //使用循環(huán)模擬對(duì)戰(zhàn)過程 while(hp1 > 0 && hp2 > 0) { attack1 = (int)(Math.random() * 1000) % 11 + 5; //雙方隨機(jī)的攻擊力(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 + "遇到了強(qiáng)烈進(jìn)攻!"); } else { System.out.println(username + "被沉重打擊!"); } System.out.println("\n"); } //打印結(jié)果 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如何實(shí)現(xiàn)拳皇小程序”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。