经过几天的工作,我又整了一个宝可梦对战的类,(虽然有点花哨,但本质上是减法运算。)代码如下
import java.util.Scanner;标签:String,int,可梦,hp,宝可梦,System,对宝,println,out From: https://www.cnblogs.com/zyz-hhh/p/17015641.html
class poke_player{
public static void PVP(){
Scanner zyz=new Scanner(System.in);
System.out.println("请输入你的宝可梦名字:");
String zyz1=zyz.next();
System.out.println("请依次输入您宝可梦的血量(HP)、攻击/特攻(DAMAGE)、防御/特防(ARMOR)");
int z1=zyz.nextInt();
int z2=zyz.nextInt();
int z3=zyz.nextInt();
System.out.println("请输入对手宝可梦名字:");
String zg1=zyz.next();
System.out.println("请依次输入对手宝可梦的血量(HP)、攻击/特攻(DAMAGE)、防御/特防(ARMOR)");
int g1=zyz.nextInt();
int g2=zyz.nextInt();
int g3=zyz.nextInt();
System.out.println("战斗开始!");
new poke_player(zyz1,z1,z2,z3).Attack(new poke_player(zg1,g1,g2,g3));
System.out.println("战斗结束!");
}
private String name;
private int hp;
private int damage;
private int armor;
public poke_player(String name,int hp,int damage,int armor){
this.name = name;
this.hp = hp;
this.damage = damage;
this.armor = armor;
}
public String GetName(){
return this.name;
}
public void Attack(poke_player target){
System.out.println(String.format("%1$s正在攻击%2$s!",this.GetName(),target.GetName()));
target.HurtFrom(this, this.damage);
}
public void CounterAttack(poke_player enemy){
System.out.println(String.format("%1$s正在反击%2$s!",this.GetName(),enemy.GetName()));
this.Attack(enemy);
}
public void HurtFrom(poke_player enemy,int damage){
int realDamage = damage - this.armor;
this.hp = this.hp - realDamage;
System.out.println(String.format("%1$s受到%2$s的攻击,伤害%3$s,真实伤害%4$s,当前血量%5$s!",this.GetName(),enemy.GetName(),damage,realDamage,this.hp));
if(this.hp<50)
System.out.println(String.format("哈哈,%1$s快濒死了!", this.GetName()));
if(this.hp < 0){
System.out.println(String.format("%1$s已濒死!", this.GetName()));
return;
}
this.CounterAttack(enemy);
}
}
大该就是这样,下次发文,应该就是整个程序出来的时候了。