先看看效果如下 (代码附上)此刻A,B都是相互简单来回攻击,下一步将会进行改进
package demo1204;
public class Apeople {
//属性
public String name;
public int blood;
//方法
public void xueliang(Bpeople c){
for(int blood=95;blood>0; blood-=5) {
System.out.println(name + "正在攻击" + c.name + "导致其血量减少5" + "血量,亚索现在的血量是" + blood);
System.out.println(c.name + "正在攻击" + name + "导致其血量减少5" + "血量,后裔现在的血量是" + blood);
}
}
}
package demo1204;
public class Bpeople {
//属性
public String name;
public int blood;
//方法
public void xueliang(Apeople c){
for(int blood=95;blood>0; blood-=5) {
System.out.println(name + "正在攻击" + c.name + "导致其血量减少5" + "血量,后裔现在的血量是" + blood);
System.out.println(c.name + "正在攻击" + name + "导致其血量减少5" + "血量,亚索现在的血量是" + blood);
}
}
}
package demo1204;
public class Project {
public static void main(String[]args){
//创建类的对象
Apeople houyi=new Apeople();
houyi.blood=100;
houyi.name="后裔";
//创建类的对象
Bpeople yasuo=new Bpeople();
yasuo.blood=100;
yasuo.name="亚索";
houyi.xueliang(yasuo);
yasuo.xueliang(houyi);
if( houyi.blood>yasuo.blood){
System.out.println("后裔赢了");
}else {
System.out.println("亚索赢了");
}
}
}