C#练习题答案: PatternCraft - 装饰【难度:2级】--景越C#经典编程题库,1000道C#基础练习题等你来挑战

PatternCraft - 装饰【难度:2级】:

答案1:

using System;

public interface IMarine
{
  int Damage { get; set; }
  int Armor { get; set; }
}

public class Marine : IMarine
{
  public Marine(int damage, int armor)
  {
    Damage = damage;
    Armor = armor;
  }
  
  public int Damage { get; set; }
  public int Armor { get; set; }
}

public class MarineDecorator : IMarine
{
  protected IMarine marine;
  public MarineDecorator(IMarine marine) 
  {
    this.marine = marine;
  }
  
  virtual public int Damage { get { return marine.Damage; } set { marine.Damage = value; } }
  virtual public int Armor { get{ return marine.Armor; } set { marine.Armor = value; } }
}

public class MarineWeaponUpgrade : MarineDecorator
{
  public MarineWeaponUpgrade(IMarine marine) : base(marine)
  {
    this.marine = marine;
  }
  override public int Damage { get { return marine.Damage + 1; } }
}

public class MarineArmorUpgrade : MarineDecorator
{
  public MarineArmorUpgrade(IMarine marine) : base(marine)
  {
    this.marine = marine;
  }
  
  override public int Armor { get{ return marine.Armor + 1; } }
}

答案2:

using System;

public interface IMarine
{
    int Damage { get; set; }
    int Armor { get; set; }
}

public class Marine : IMarine
{
    public Marine(int damage, int armor)
    {
        Damage = damage;
        Armor = armor;
    }

    public int Damage { get; set; }
    public int Armor { get; set; }
}

public class MarineWeaponUpgrade : IMarine
{
    private IMarine marine;

    public MarineWeaponUpgrade(IMarine marine)
    {
        this.marine = marine;
    }

    public int Damage
    {
        get { return this.marine.Damage + 1; }
        set { this.marine.Damage = value; }
    }

    public int Armor
    {
        get { return this.marine.Armor; }
        set { this.marine.Armor = value; }
    }
}

public class MarineArmorUpgrade : IMarine
{
    private IMarine marine;

    public MarineArmorUpgrade(IMarine marine)
    {
        this.marine = marine;
    }

    public int Damage
    {
        get { return this.marine.Damage; }
        set { this.marine.Damage = value; }
    }

    public int Armor
    {
        get { return this.marine.Armor + 1; }
        set { this.marine.Armor = value; }
    }
}

答案3:

using System;

public interface IMarine
{
    int Damage { get; set; }
    int Armor { get; set; }
}

public class Marine : IMarine
{
    public Marine(int damage, int armor)
    {
        Damage = damage;
        Armor = armor;
    }

    public int Damage { get; set; }
    public int Armor { get; set; }
}

public class MarineWeaponUpgrade : IMarine
{
    private IMarine marine;

    public MarineWeaponUpgrade(IMarine marine)
    {
        marine = marine;
        this.Damage = marine.Damage + 1;
        this.Armor = marine.Armor;
    }

    public int Damage { get; set; }

    public int Armor { get; set; }
}

public class MarineArmorUpgrade : IMarine
{
    private IMarine marine;

    public MarineArmorUpgrade(IMarine marine)
    {
        marine = marine;
        this.Armor = marine.Armor + 1;
        this.Damage = marine.Damage;
    }
    

    public int Damage { get; set; }

    public int Armor { get; set; }
}

答案4:

using System;

public interface IMarine
{
    int Damage { get;}
    int Armor { get; }
}

public class Marine : IMarine
{
    public Marine(int damage, int armor)
    {
        Damage = damage;
        Armor = armor;
    }

    public int Damage { get; }
    public int Armor { get; }
}

public class MarineWeaponUpgrade : IMarine
{
    private IMarine marine;

    public MarineWeaponUpgrade(IMarine marine)
    {
        this.marine = marine;
    }

    public int Damage => marine.Damage + 1;

    public int Armor => marine.Armor;
}

public class MarineArmorUpgrade : IMarine
{
    private IMarine marine;

    public MarineArmorUpgrade(IMarine marine)
    {
        this.marine = marine;
    }

    public int Damage => marine.Damage;

    public int Armor => marine.Armor + 1;
}

答案5:

using System;

        public interface IMarine
    {
        int Damage { get; set; }
        int Armor { get; set; }
    }

    public class MarineDecorator : IMarine
    {
        protected IMarine marine;

        public MarineDecorator(IMarine marine)
        {
            this.marine = marine;
        }

        public virtual int Damage { get => marine.Damage; set => marine.Damage = value; }
        public virtual int Armor { get => marine.Armor; set { marine.Armor = value; } }
    }

    public class Marine : IMarine
    {
        public Marine(int damage, int armor)
        {
            Damage = damage;
            Armor = armor;
        }

        public int Damage { get; set; }
        public int Armor { get; set; }
    }

    public class MarineWeaponUpgrade : MarineDecorator
    {
        public MarineWeaponUpgrade(IMarine marine)
            : base(marine)
        {
            this.marine = marine;
        }

        override public int Damage => marine.Damage + 1;
    }

    public class MarineArmorUpgrade : MarineDecorator
    {
        public MarineArmorUpgrade(IMarine marine)
            :base(marine)
        {
            this.marine = marine;
        }

        override public int Armor => marine.Armor + 1;
    }

答案6:

using System;

public interface IMarine
{
    int Damage { get; set; }
    int Armor { get; set; }
}

public class Marine : IMarine
{
    public Marine(int damage, int armor)
    {
        Damage = damage;
        Armor = armor;
    }

    public int Damage { get; set; }
    public int Armor { get; set; }
}

public class MarineWeaponUpgrade : IMarine
{
    private IMarine marine;
    int rate =1;
    public MarineWeaponUpgrade(IMarine marine)
    {
        this.marine = marine;
    }

    public int Damage { get{ return marine.Damage +rate; } set{rate = value;}}

    public int Armor { get{ return marine.Armor; } set {}}
}

public class MarineArmorUpgrade : IMarine
{
    private IMarine marine;
    int rate =1;
    public MarineArmorUpgrade(IMarine marine)
    {
        this.marine = marine;
    }

     public int Damage { get{ return marine.Damage; } set{}}

    public int Armor { get{ return marine.Armor +rate; } set {rate = value;}}
}

答案7:

using System;

public interface IMarine
{
    int Damage { get; set; }
    int Armor { get; set; }
}

public class Marine : IMarine
{
    public Marine(int damage, int armor)
    {
        Damage = damage;
        Armor = armor;
    }

    public int Damage { get; set; }
    public int Armor { get; set; }
}

public class MarineWeaponUpgrade : IMarine
{
    private IMarine marine;

    public MarineWeaponUpgrade(IMarine marine)
    {
        this.marine = marine;
    }

    public int Damage { get => this.marine.Damage + 1; set => this.marine.Damage = value; }

    public int Armor { get => this.marine.Armor; set=> this.marine.Armor = value; }
}

public class MarineArmorUpgrade : IMarine
{
    private IMarine marine;

    public MarineArmorUpgrade(IMarine marine)
    {
         this.marine = marine;
    }

    public int Damage { get => this.marine.Damage; set=> this.marine.Damage = value; }

    public int Armor { get => this.marine.Armor + 1; set => this.marine.Armor = value; }
}

答案8:

using System;

public interface IMarine
{
    int Damage { get; set; }
    int Armor { get; set; }
}

public class Marine : IMarine
{
    public Marine(int damage, int armor)
    {
        Damage = damage;
        Armor = armor;
    }

    public int Damage { get; set; }
    public int Armor { get; set; }
}

public class MarineWeaponUpgrade : IMarine
{
    private IMarine marine;

    public MarineWeaponUpgrade(IMarine _marine)
    {
        marine = new Marine (_marine.Damage + 1, _marine.Armor);
    }

    public int Damage { get{return marine.Damage;} set{} }

    public int Armor { get{ return marine.Armor;} set{} }
}

public class MarineArmorUpgrade : IMarine
{
    private IMarine marine;

    public MarineArmorUpgrade(IMarine _marine)
    {
          marine = new Marine (_marine.Damage, _marine.Armor + 1);
          
    }

    public int Damage { get {return marine.Damage;} set{} }

    public int Armor { get {return marine.Armor;} set{} }
}

答案9:

using System;

public interface IMarine
{
    int Damage { get; set; }
    int Armor { get; set; }
}

public class Marine : IMarine
{
    public Marine(int damage, int armor)
    {
        Damage = damage;
        Armor = armor;
    }

    public int Damage { get; set; }
    public int Armor { get; set; }
}

public class MarineWeaponUpgrade : IMarine
{
    private IMarine marine;

    public MarineWeaponUpgrade(IMarine marine)
    {
        this.marine = marine;
    }

    public int Damage { get=> marine.Damage + 1; set => marine.Damage = value; }

    public int Armor { get => marine.Armor; set => marine.Armor = value; }
}

public class MarineArmorUpgrade : IMarine
{
    private IMarine marine;

    public MarineArmorUpgrade(IMarine marine)
    {
         this.marine = marine;
    }

    public int Damage { get=> marine.Damage; set => marine.Damage = value; }

    public int Armor { get => marine.Armor + 1; set => marine.Armor = value; }
}

答案10:

using System;

public interface IMarine
{
    int Damage { get; set; }
    int Armor { get; set; }
}

public class Marine : IMarine
{
    public Marine(int damage, int armor)
    {
        Damage = damage;
        Armor = armor;
    }

    public int Damage { get; set; }
    public int Armor { get; set; }
}

public class MarineWeaponUpgrade : IMarine
{
    private IMarine marine;

    public MarineWeaponUpgrade(IMarine marine)
    {
        this.marine = marine;
    }

    public int Damage { get => marine.Damage + 1; set => marine.Damage  = value - 1;  }

    public int Armor { get => marine.Armor; set => marine.Armor = value; }
}

public class MarineArmorUpgrade : IMarine
{
    private IMarine marine;

    public MarineArmorUpgrade(IMarine marine)
    {
        this.marine = marine;
    }

    public int Damage { get => marine.Damage; set => marine.Damage = value; }

    public int Armor { get => marine.Armor + 1; set => marine.Armor = value - 1; }
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值