万金流
初次使用博客园,目前感觉还不错。 不知不觉用了4年零4个月了,越来越喜欢博客园。

代码如下:

package t11;

import java.util.Random;

public class Fight
{
	String name;
	int life, attack, speed, crit, armor;// 生命、攻击力,攻速,暴击,护甲

	void set_Fight(String a,int a1, int a2, int a3, int a4, int a5)//可改为构造函数
	{
		name=a;
		life = a1;
		attack = a2;
		speed = a3;
		crit = a4;
		armor = a5;
	}

	void attack(Fight x)
	{
		int send_attack;
		Random r1=new Random();
		if(r1.nextInt(100)<=crit)
		{
			send_attack=attack*speed*2;
		}
		else
		{
			send_attack=attack*speed;
		}
		System.out.println(name+"发出攻击:"+send_attack);
		x.be_Attack(send_attack);
	}

	void be_Attack(int x)
	{
		life=(int)(life-x*100.0/(100+armor));
		show_Me();
	}
	void show_Me()
	{
		System.out.println(name+",life:"+life);
	}
}

  主类调用它:

package t11;

public class c1 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Fight shoot,soldier;
		shoot=new Fight();
		soldier=new Fight();
		shoot.set_Fight("射手",300, 75, 2, 10, 30);
		soldier.set_Fight("战士",500, 90, 1, 20, 45);
		while(true)
		{
			shoot.attack(soldier);
			soldier.attack(shoot);
			if(shoot.life<=0 || soldier.life<=0)
			{
				break;
			}
		}
	}

}

  

 

posted on 2019-06-10 23:00  万金流  阅读(476)  评论(0编辑  收藏  举报