public class Plater {
public String name;
public String type;
public int life;
public int defense;
public int attack;
Random a = new Random();
Random b = new Random();
Random c = new Random();
public void say(){
System.out.println("我是"+name+",一个"+type);
System.out.println(",血量"+life+",防御"+defense+"攻击"+attack);
}
public void pk(Plater p){
int flag = 0;
//回合制,直至一方死亡
while (true) {
this.say();
p.say();
if (flag == 0) {
int harm = this.attack - p.defense;
int t = b.nextInt(2);
if (t!=0){
System.out.println(p.name + "掉血" + harm);
p.life -= harm;
}else {
System.out.println("暴击!致命一击!");
System.out.println(p.name + "掉血" + harm*2);
p.life -= harm*2;
}
flag = 1;
} else {
int harm = p.attack - this.defense;
int l = c.nextInt(2);
if (l!=0){
System.out.println(this.name + "掉血" + harm);
this.life -= harm;
}else {
System.out.println("暴击");
System.out.println(this.name + "掉血" + harm*2);
this.life -= harm*2;
}
flag = 0;
}
//有血量<=0,战斗结束
if(this.life<=0){
System.out.println(p.name+"打败了"+this.name);
break;
}
if(p.life<=0){
System.out.println(this.name+"打败了"+p.name);
break;
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
String [] stu = {"奖励1200经济","黑色切割者","名刀司命","破甲弓","十块钱人民币"," "};
for (int z = 0; z < stu.length; z++) {
z = a.nextInt(6);
System.out.println("恭喜你五连绝世并获得"+stu[z]);
break;
}
}
public Plater() {
}
public Plater(String name, String type, int life, int defense, int attack) {
this.name = name;
this.type = type;
this.life = life;
this.defense = defense;
this.attack = attack;
}
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 getLife() {
return life;
}
public void setLife(int life) {
this.life = life;
}
public int getDefense() {
return defense;
}
public void setDefense(int defense) {
this.defense = defense;
}
public int getAttack() {
return attack;
}
public void setAttack(int attack) {
this.attack = attack;
}
}
public class PlayerTest {
public static void main(String[] args) {
Plater p1 = new Plater("无名", "战士", 1000, 120, 300);
Plater p2 = new Plater("影", "法师", 1200, 130, 280);
p1.pk(p2);
}
}