// 这是方法类
public class Practice_1 {
private int num;
private String nickname;
private String name;
private String type;
private int atk;
private int def;
private int health;
private int magic;
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
public String getNickname() {
return nickname;
}
public void setNickname(String nickname) {
this.nickname = nickname;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public int getAtk() {
return atk;
}
public void setAtk(int atk) {
this.atk = atk;
}
public int getDef() {
return def;
}
public void setDef(int def) {
this.def = def;
}
public int getHealth() {
return health;
}
public void setHealth(int health) {
this.health = health;
}
public int getMagic() {
return magic;
}
public void setMagic(int magic) {
this.magic = magic;
}
public void fight1_2() { System.out.println("盖伦 对 瑞兹"+" 进行攻击"); } public void
fight2_1() { System.out.println("瑞兹 对 盖伦"+"进行攻击"); } public void move() {
System.out.println("移动"); } public void die() { System.out.println("角色死亡"); }
public void rebirth() { getHealth();
System.out.println("复活"+"血量满了"+getHealth()); }
}
//这是主类,调用前一个类的方法.

public class TestPractice_1 {
public static void main(String[] args) { Practice_1 p1= new Practice_1();
Practice_1 p2= new Practice_1(); p1.setType("战士"); p1.setNum(1);
p1.setNickname("德玛西亚之力"); p1.setName("盖伦"); p1.setAtk(10); p1.setDef(10);
p1.setHealth(102); p1.setMagic(0);
System.out.println("类型"+"\t昵称"+"\t\t名称"+"\t攻击力"+"\t防御力"+"\t血量"+"\t魔法值");
System.out.print(p1.getType()+"\t"); System.out.print(p1.getNickname()+"\t");
System.out.print(p1.getName()+"\t"); System.out.print(p1.getAtk()+"\t");
System.out.print(p1.getDef()+"\t"); System.out.print(p1.getHealth()+"\t");
System.out.println(p1.getMagic()+"\t"); p2.setType("法师"); p2.setNum(1);
p2.setNickname("流浪法师\t"); p2.setName("瑞兹"); p2.setAtk(20); p2.setDef(5);
p2.setHealth(80); p2.setMagic(100); System.out.print(p2.getType()+"\t");
System.out.print(p2.getNickname()+"\t"); System.out.print(p2.getName()+"\t");
System.out.print(p2.getAtk()+"\t"); System.out.print(p2.getDef()+"\t");
System.out.print(p2.getHealth()+"\t"); System.out.print(p2.getMagic()+"\t");
int a=p1.getHealth(); System.out.println(a); int b = p2.getHealth(); int
b1=p2.getMagic(); System.out.println(); int count1 =0; int count2 =0; do {
p1.fight1_2(); b-=5; if(b>0) { count1++; System.out.println("瑞兹被击中剩余血量为"+b);
}else { System.out.println("瑞兹血量为 0"); break; } if(b1>13) { p2.fight2_1();
a-=10; b1-=13; }else { System.out.println("瑞兹法力剩余不足,不足以释放技能"); continue; }
if(a>0) { count2++; System.out.println("盖伦被魔法击中剩余血量为"+a+" 瑞兹法力剩余"+b1); }else {
System.out.println("盖伦血量为 0"); break; } }while(a!=0&&b!=0); if(a==0&&b!=0) {
p1.getName(); p1.die(); }else { p2.getName(); p2.die(); }
System.out.println("盖伦一共攻击了"+count1+"次");
System.out.println("瑞兹一共攻击了"+count2+"次"); }
}

技术
今日推荐
下载桌面版
GitHub
百度网盘(提取码:draw)
Gitee
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:[email protected]
QQ群:766591547
关注微信