コード例 #1
0
        static void Main(string[] args)
        {
            BasicUnitConstructor unitConstructor = new BasicUnitConstructor();
            Builder footmanBuilder = new FootmanBuilder();
            Builder dragonBuilder  = new DragonBuilder();

            unitConstructor.Construct(footmanBuilder);
            UnitImplStrategy footman = footmanBuilder.GetUnit();

            Console.WriteLine(footman);

            unitConstructor.Construct(dragonBuilder);
            UnitImplStrategy dragon = dragonBuilder.GetUnit();

            Console.WriteLine(dragon);

            Console.WriteLine();
            footman.Move();
            dragon.Move();
            Console.WriteLine("Footman gets magic item : boots of speed");
            footman.SetMoveStrategy(new FastGroundUnit());
            footman.Move();
            Console.ReadKey();
        }
コード例 #2
0
 public void Move(UnitImplStrategy unit)
 {
     Console.WriteLine($"{unit.Name} flies");
 }
コード例 #3
0
 public void Move(UnitImplStrategy unit)
 {
     Console.WriteLine($"{unit.Name} walks faster");
 }