Java实现回合制游戏亚瑟VS鲁班
普通⽅法
1.亚瑟类:
public class Yas {
//定义共有属性:名字,⾎量,攻击⼒
public String name;
public int blood;
public int atyas;
public void attack(Lub lb){
lb.blood -= atyas;//lb.⾎量 -= 攻击⼒
System.out.println(name+"正在攻击"+lb.name+","+lb.name+"掉⾎"+atyas+",剩余⾎量"+lb.blood); }
}
2.鲁班类:
public class Lub {
public String name;
public int blood;
public int atlub;
public void attack(Yas ys){
ys.blood -= atlub;
System.out.println(name+"正在攻击"+ys.name+","+ys.name+"掉⾎"+atlub+",剩余⾎量"+ys.blood); }
}
3.主函数:
public class YLManage {
public static void main(String[] args){
Yas ys =new Yas();
ys.name ="亚瑟";
ys.blood =10;
ys.atyas =2;
Lub lb =new Lub();
lb.name ="鲁班";
lb.blood =10;三更视频下载教程
lb.atlub =3;
while(ys.blood()>0&& lb.blood()>0){
ys.attack(lb);
if(lb.blood()<=0){
System.out.println("鲁班死亡,亚瑟获胜");
break;
}
lb.attack(ys);
if(ys.blood()<=0){
System.out.println("亚瑟死亡,鲁班获胜");
break;
}
}
}
}
运⾏结果:
构造⽅法
1.亚瑟类:
public class Yas {
private String name;
private int blood;
private int atyas;true的名词
public Yas(String name,int blood,int atyas){
this.name = name;
this.blood = blood;
this.atyas = atyas;
}
public String getName(){
return name;
}
public int getBlood(){
return blood;
}
public int getAtyas(){
return atyas;
}
public void setBlood(int blood){
this.blood = blood;
}
public void attack(Lub lb){
int b = lb.getBlood()- atyas;
lb.setBlood(b);
System.out.println(name+"正在攻击"+lb.getName()+","+lb.getName()+"掉⾎"+atyas+",剩余⾎量"+lb.getBlood()); }
}
2.鲁班类:
public class Lub {
private String name;
private int blood;
private int atlub;
public Lub(String name,int blood,int atlub){
this.name = name;
this.blood = blood;
this.atlub = atlub;
}
public String getName(){
return name;
}
public int getBlood(){
return blood;
创建数据库的操作步骤
}
public int getAtlub(){
return atlub;
}
public void setBlood(int blood){
this.blood = blood;
}
public void attack(Yas ys){
int b = ys.getBlood()- atlub;
ys.setBlood(b);
System.out.println(name+"正在攻击"+ys.getName()+","+ys.getName()+"掉⾎"+atlub+",剩余⾎量"+ys.getBlood()); }
}
3.主函数:
public class YLManage {
public static void main(String[] args){
Yas ys =new Yas("亚瑟",20,2);
Lub lb =new Lub("鲁班",15,3);
什么软件需要多核多线程Blood()>0&& lb.getBlood()>0){
ys.attack(lb);
Blood()<=0){
System.out.println("鲁班死亡,亚瑟获胜");
java手机游戏下载break;
}
lb.attack(ys);
Blood()<=0){
System.out.println("亚瑟死亡,鲁班获胜");
web前端是什么工作 通俗点
break;
}
}
}
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。