标签:style blog http color 使用 sp strong on div
1 public interface IWeapon 2 { 3 string Name { get; set; } 4 5 void Use(); 6 } 7 8 public abstract class Person 9 { 10 public string Name { get; set; } 11 12 protected IWeapon Weapon; 13 14 public void SetWeapon(IWeapon weapon) 15 { 16 Weapon = weapon; 17 } 18 19 public abstract void UseWeapon(); 20 21 } 22 23 public class Gun : IWeapon 24 { 25 public string Name { get; set; } 26 27 public void Use() 28 { 29 Name = "95步枪"; 30 Console.WriteLine("装备+15的{0}", Name); 31 } 32 } 33 34 public class Stone : IWeapon 35 { 36 public string Name { get; set; } 37 38 public void Use() 39 { 40 Name = "疯狂的石头"; 41 Console.WriteLine("装备+12{0}", Name); 42 } 43 } 44 45 public class Troch : IWeapon 46 { 47 public string Name { get; set; } 48 49 public void Use() 50 { 51 Name = "折断的电棒"; 52 Console.WriteLine("装备+15{0}", Name); 53 } 54 } 55 56 public class HorseMan : Person 57 { 58 public override void UseWeapon() 59 { 60 Console.WriteLine("圣骑士{0}:", Name); 61 Weapon.Use(); 62 Console.WriteLine("哈哈,圣骑士{1}用{0}秒杀了你!!", Weapon.Name, Name); 63 } 64 } 65 66 public class Lancer : Person 67 { 68 public override void UseWeapon() 69 { 70 Console.WriteLine("枪兵{0}:", Name); 71 Weapon.Use(); 72 Console.WriteLine("哈哈,枪兵{1}用{0}爆了你的菊花!!", Weapon.Name, Name); 73 } 74 } 75 //调用 76 Person p=new HorseMan(); 77 p.Name = "李二狗"; 78 p.SetWeapon(new Gun()); 79 p.UseWeapon();
标签:style blog http color 使用 sp strong on div
原文地址:http://www.cnblogs.com/cnDqf/p/4152720.html