接上文的二号人物属性面板

package hero;

public class Gongben{

String name;

String sex;

float gjl;

float fyl;

int booldnum;

boolean isopen = true;

public Gongben(String name, String sex, float gjl, float fyl, int booldnum) {

this.name = name;

this.sex = sex;

this.gjl = gjl;

this.fyl = fyl;

this.booldnum = booldnum;

}

public void firstaction(){

System.out.println("**********************************");

System.out.println(this.name+"发动了一技能");

this.gjl = this.gjl+400.0f;

this.fyl = this.fyl+300.0f;

System.out.println("当前"+this.name+"攻击力为:"+this.gjl);

System.out.println("当前"+this.name+"防御力为:"+this.fyl);

System.out.println("**********************************");

}

public String getName() {

return name;

}

public String getSex() {

return sex;

}

public float getGjl() {

return gjl;

}

public float getFyl() {

return fyl;

}

public int getBooldnum() {

return booldnum;

}

public boolean isIsopen() {

return isopen;

}

public void secondaction(){

System.out.println("**********************************");

System.out.println(this.name+"发动了二技能");

this.gjl = this.gjl+400.0f;

this.fyl = this.fyl+500.0f;

System.out.println("当前"+this.name+"攻击力为:"+this.gjl);

System.out.println("当前"+this.name+"防御力为:"+this.fyl);

System.out.println("**********************************");

}

public void thirdction(){

System.out.println("**********************************");

System.out.println(this.name+"发动了三技能");

this.gjl = this.gjl+900.0f;

this.fyl = this.fyl+250.0f;

System.out.println("当前"+this.name+"攻击力为:"+this.gjl);

System.out.println("当前"+this.name+"防御力为:"+this.fyl);

System.out.println("**********************************");

}

public void beiDong(){

while(this.isopen){

if(this.booldnum<1000){

System.out.println(this.name+"现在触发被动中");

this.booldnum = this.booldnum+1000;

this.isopen = false;

}else{

System.out.println(this.name+"现在满血");

}

}

}

public void kouXue(float num){

System.out.println(this.name+"被打");

this.booldnum = this.booldnum-(int)num/2;

if(this.booldnum<0){

System.out.println(this.name+"死亡"+",游戏结束");

System.out.println(this.name+"当前血量:"+this.booldnum);

}

System.out.println(this.name+"当前血量:"+this.booldnum);

}

public void norAction(){

System.out.println(this.name+"平A...........");

}

}

可以看到,核心思想就是给一个变量附加一个属性,使其可以依据数学运算产生扣血等攻击和受击效果,枪战游戏亦是如此,通过为人物编写受击属性,当子弹打到身上的时候可以进行运算,从而产生扣血的效果。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值