// 1、创建武器类,包含字段:加攻击力,加生命值,加防御力,加速度值,类型(包括攻击,防御,法术,移动,打野
// 创建英雄类,包含字段:血量,攻击力,名字,防御力,移动速度,等级
// 英雄类当中包括的方法:
// (1)加装装备
// (2)卸载装备
// (3)攻击英雄
// (4)受到攻击会掉血,举例:攻击力为100的时候,掉血为100。当血量小于等于0的时候英雄阵亡
// (5)每杀一个英雄等级+1,同时攻击力增加200
// 模拟英雄互相伤害的场景
public class Weapon
{public enum WeaponType{
adType,
tdType,
apType,
spType,
juType
}
private int addATK;
private int addHP;
private int addDefense;
private int addSpeed;
private WeaponType equipment;
public int AddATK{
get{
return addATK;
}
}
public int AddHP{
get{
return addHP;
}
}
public int AddDefense{
get{
return addDefense;
}
}
public int AddSpeed{
get{
return addSpeed;
}
}
public WeaponType Equipment{
get{
return equipment;
}
}
public Weapon (int addATK,int addHP,int addDefense,int addSpeed,WeaponType equipment) //对已经初始化好的对象不能再次修改
{
this.addHP = AddHP;
this.addATK = AddATK;
this.addDefense = AddDefense;
this.addSpeed = AddSpeed;
this.equipment = equipment;
}
}
public class Heros
{
public string name;
public int HP;
public int ATK;
public int DF;
public int SP;
public int level = 0;
private Weapon m_weapon;
public Weapon M_weapon{
get{
return m_weapon;
}
set {
if (value == null) {
HP -= m_weapon.AddHP;
ATK -= m_weapon.AddATK;
DF -= m_weapon.AddDefense;
SP -= m_weapon.AddSpeed;
} else {
HP += value.AddHP;
ATK += value.AddATK;
DF += value.AddDefense;
SP += value.AddSpeed;
}
}
}
public Heros (string name,int HP,int ATK,int DF,int SP,Weapon m_weapon)
{
this.name = name;
this.HP = HP;
this.ATK = ATK;
this.DF = DF;
this.SP = SP;
this.m_weapon = m_weapon;
}
public void Loadweappon(Weapon weapon){
if(this.m_weapon != null) {
Unloadweapon();
}
this.M_weapon = weapon;
}
public void Unloadweapon(){
if (this.m_weapon != null) {
this.M_weapon = null;
}
}
//受伤掉血
public void Hurt(Heros enemy){
HP -= enemy.ATK;
if (HP > 0) {
Console.WriteLine ("英雄受伤!当前血量为{0}", HP);
} else {
Dead (this);
enemy.level++;
}
}
//死亡
public void Dead (Heros hero){
Console.WriteLine ("英雄死亡!");
}
//攻击英雄
public void Attack(Heros enemy){
enemy.Hurt(this);
}
}