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; }
}