日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

java宠物小精灵,简单的Java口袋妖怪扑灭模拟器

發(fā)布時間:2024/9/19 43 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java宠物小精灵,简单的Java口袋妖怪扑灭模拟器 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

我寫了一個類來創(chuàng)建和戰(zhàn)斗口袋妖怪,但我無法弄清楚如何在測試器類中調(diào)用battle方法來測試我寫的類.

我的任務(wù)是編寫和測試模擬兩個神奇寶貝之間的戰(zhàn)斗的模擬.每個神奇寶貝都有一個健康值,一個力量值和一個速度值.運行狀況,強度和速度值作為參數(shù)傳遞給構(gòu)造函數(shù).這些值最初必須介于1到300之間,并且最初應(yīng)為非零值.完成游戲的總體思路是兩個口袋妖怪將在模擬中相互“戰(zhàn)斗”,口袋妖怪輪流攻擊. (具有最高速度值的那一個每輪首先出現(xiàn))攻擊口袋妖怪的力量將從“攻擊者”的生命值中減去.

public class Pokemon{

private int health;

private int strength;

private int speed;

/**

* Constructs the pokemon

* @Require:

* health is an integer greater than or equal to 1 but less than or equal to 300

* strength is and integer greater than or equal to 1 but less than or equal to 300

* speed is an integer greater than or equal to 1 but less than or equal to 300

*/

public Pokemon(int health, int strength, int speed){

assert health >= 1;

assert health <= 300;

assert strength >= 1;

assert strength <= 300;

assert speed >= 1;

assert speed <= 300;

this.health = health;

this.strength = strength;

this.speed = speed;

}

public void battle(Pokemon pokemon1, Pokemon pokemon2){

do{

System.out.println(pokemon1+" begins the fight against "+pokemon2);

pokemon2.health = pokemon2.health - pokemon1.strength;

System.out.println(pokemon1 +" does "+ pokemon1.strength +" damage to "+

pokemon2 +" and "+ pokemon2 +" has "+ pokemon2.health +" left.");

pokemon1.health = pokemon1.health - pokemon2.strength;

System.out.println(pokemon2 +" does "+ pokemon2.strength +" damage to "+

pokemon1 +" and "+ pokemon1 +" has "+ pokemon1.health +" left.");

}while(pokemon1.health >= 1 || pokemon2.health >= 1);

if(pokemon1.health < 1)

System.out.println(pokemon1 +" has lost the fight");

else

System.out.println(pokemon2 +" has lost the fight");

}

}

口袋妖怪測試員

public class PokemonTester{

private Pokemon charizard;

private Pokemon blastoise;

private Pokemon venusaur;

public PokemonTester(){

charizard = new Pokemon(100,50,50);

blastoise = new Pokemon(150,25,150);

venusaur = new Pokemon(300,10,100);

}

public static void main(String[] args){

Pokemon.battle(charizard, blastoise); //will not compile

}

}

我確實意識到我還沒有在輪流中實現(xiàn)速度方面,因為我正試圖讓它工作.

添加靜態(tài)到戰(zhàn)斗功能,就像在main中一樣.

此外,你不能在主要使用charizard和blastoise.非靜態(tài)變量不能用于靜態(tài)函數(shù).您需要在`main中創(chuàng)建局部變量

public static void main(String[] args){

Pokemon charizard = new Pokemon(100,50,50);

Pokemon blastoise = new Pokemon(150,25,150);

Pokemon.battle(charizard, blastoise);

}

您還可以創(chuàng)建新的PokemonTester并使用它的變量:

public static void main(String[] args){

PokemonTester tester=new PokemonTester();

Pokemon.battle(tester.charizard, tester.blastoise);

}

您可以了解有關(guān)靜態(tài)成員here的更多信息

總結(jié)

以上是生活随笔為你收集整理的java宠物小精灵,简单的Java口袋妖怪扑灭模拟器的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。