模拟王者荣耀单挑

package com.ambow.java09;

import java.util.Random;

public class Hero {
//属性
String name;//名字
int blood;//血量
int aggressivity;//攻击力

//行为
public void move() {
	System.out.println(name+"在移动...");
}
//战斗
public void fight(Hero hero,int type) {
	if (type == 1) {
		skill01(hero);
		hero.blood = hero.blood - 10;
	}else if (type == 2) {
		skill02(hero);
		hero.blood = hero.blood - 20;
	}else if (type == 3) {
		skill03(hero);
		hero.blood = hero.blood - 30;
	}else {
		System.out.println("-------普通攻击--------");
		hero.blood = hero.blood - 5;
	}
	
}

public void skill01(Hero hero){
	System.out.println("-------"+name+"对"+hero.name+"释放一技能-------");
	aggressivity = 10;
}
public void skill02(Hero hero){
	System.out.println("-------"+name+"对"+hero.name+"释放二技能-------");
	aggressivity = 20;
}
public void skill03(Hero hero){
	System.out.println("-------"+name+"对"+hero.name+"释放三技能-------");
	aggressivity = 30;
}

//显示当前状态的方法
public void show() {
	System.out.println(name+"当前血量:"+blood);
}

}

public class TestHero {
public static void main(String[] args) throws InterruptedException {
//创建英雄一
Hero hero1 = new Hero();
hero1.name = “妲己”;
hero1.blood = 100;

	//创建英雄二
	Hero hero2 = new Hero();
	hero2.name = "孙悟空";
	hero2.blood = 100;
	
	Random random = new Random();
	int type = 0;
	
	while(hero1.blood > 0 && hero2.blood > 0) {
		//英雄一  攻击  英雄二 
		type = random.nextInt(6)+1;//1-8    1-3技能        4-6普攻
		hero1.fight(hero2, type);
		
		hero1.show();
		hero2.show();
		
		//英雄二  攻击  英雄一 
		type = random.nextInt(6)+1;//1-8    1-3技能        4-6普攻
		hero2.fight(hero1, type);
		
		hero1.show();
		hero2.show();
		
		
		//休息
		Thread.sleep(2000);
	}
	
}

}

你可能感兴趣的:(模拟王者荣耀单挑)