对象
package com.fqs.GeDou; public class GeDou { //属性 private String name; private int xue; private int shangHai; public GeDou() { } public GeDou(String name, int xue, int shangHai) { this.name = name; this.xue = xue; this.shangHai = shangHai; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getXue() { return xue; } public void setXue(int xue) { this.xue = xue; } public int getShangHai() { return shangHai; } public void setShangHai(int shangHai) { this.shangHai = shangHai; } public void ko() { System.out.println("举起拳头"); } }
方法
package com.fqs.GeDou;
public class GeDouTest {
public static void main(String[] args) {
GeDou q=new GeDou("qiaoF",100,5);
GeDou j=new GeDou("jiuZhiMo",100,2);
while (q.getXue()>=0 && j.getXue()>=0) {//乔峰剩余的血量
//乔峰剩余的血量
q.setXue(q.getXue() - j.getShangHai());
System.out.println("鸠智摩举起拳头打了乔峰一下,造成了" + j.getShangHai() + "的伤害,乔峰剩余" + q.getXue());
//鸠摩智剩余的血量
j.setXue(j.getXue() - q.getShangHai());
System.out.println("乔峰举起拳头打了鸠智摩一下,造成了" + q.getShangHai() + "的伤害,鸠智摩剩余" + j.getXue());
}
if(q.getXue()>j.getXue()){
System.out.println("乔峰KO了鸠智摩");
}else{
System.out.println("鸠智摩KO了乔峰");
}
}
}
标签:回合制,智摩,int,GeDou,shangHai,乔峰,getXue,public From: https://www.cnblogs.com/haha1988/p/17478451.html