我正在制作一个有趣的口袋妖怪游戏,我希望能够减少两个口袋妖怪战斗的HP。我正在做的是在一个'if语句'中调用一个方法,它在一个循环中,让Java从另一个类调用一个方法来减少HP。
以下是我的代码......
disaster.loc[pd.isnull(disaster['Country_code']),
'Country_code'] = disaster['Country'].map(country_se)
也像我上面说过的那样,我正在调用另一个类的方法..
import java.util.Scanner;
public class gameTester {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner inputSystem = new Scanner(System.in);
Scanner playerName = inputSystem;
System.out.println("Hello Player please type in the name of your pokemon.");
pokemon playerOne = new pokemon(playerName.nextLine());
pokemon playerTwo = new pokemon();
System.out.println(playerOne.toString());//shows player pokemon
System.out.println(playerTwo.toString());//shows enemy pokemon
System.out.println("Let's Battle! What do you do?");
while (playerOne.getHealthPoints() >= 0 || playerTwo.getHealthPoints() >= 0){
System.out.println("1. Bite 2. Slash 3. Flee");
int userChoice = inputSystem.nextInt();
if (userChoice == 3){
break;
}
else if (userChoice == 1 || userChoice == 2){
//playerTwo.getHealthPoints()
}
}
}
}
public class pokemon {
private String pokemonSpecies;
private String nameOfpokemon;
private int attackDamage;
private int healthPoints;
public pokemon (){
nameOfpokemon = "Enemy";
attackDamage = 1;
healthPoints = 3;
}
public pokemon (String desiredName){
nameOfpokemon = desiredName;
attackDamage = 1;
healthPoints = 3;
}
public String getPokemonSpecies() {
return pokemonSpecies;
}
public void setPokemonSpecies(String pokemonSpecies) {
this.pokemonSpecies = pokemonSpecies;
}
public String getNameOfpokemon() {
return nameOfpokemon;
}
public void setNameOfpokemon(String nameOfpokemon) {
this.nameOfpokemon = nameOfpokemon;
}
public int getAttackDamage() {
return attackDamage;
}
public void setAttackDamage(int attackDamage) {
this.attackDamage = attackDamage;
}
public int getHealthPoints() {
return healthPoints;
}
public void setHealthPoints() {
this.healthPoints = healthPoints;
}
@Override
public String toString(){
return "Name of Pokemon: " + nameOfpokemon + " Attack Damage: " + attackDamage + " Health Points: " + healthPoints;
}
public int enemyDamage(int damage){
setHealthPoints() = getAttackDamage() - getHealthPoints();
}
}
中关于公众的最后一点是我被困住的地方。我不知道是否应该发送一个可以降低HP的整数。或者我应该使用这种方法来调用其他方法......
有什么建议吗?
答案 0 :(得分:1)
首次使用可以将setHealthPoints()
方法更改为
public void setHealthPoints(int healthPoints) {
this.healthPoints = healthPoints;
}
我假设
伤害=对手的口袋妖怪攻击/伤害。
getHealthPoints()=我的口袋妖怪的健康。
然后enemyDamage()
就这样了。
public void enemyDamage(int damage){
setHealthPoints(getHealthPoints() - damage);
}