private void FillArea(Hero hero, IMonster monster) { DrawScreen.AddLineToBuffer(ref battleArea1, Environment.NewLine); DrawScreen.AddLineToBuffer(ref battleArea1, " ".PadLeft(4, ' ') + hero.Name.PadRight(50, ' ') + monster.ToString()); DrawScreen.AddLineToBuffer(ref battleArea1, " ".PadLeft(4, ' ') + ("Damage " + hero.DamageMin + " - " + hero.DamageMax).PadRight(50, ' ') + "Damage " + monster.DamageMin + " - " + monster.DamageMax); DrawScreen.AddLineToBuffer(ref battleArea1, " ".PadLeft(4, ' ') + ("HP: " + hero.Health).PadRight(50, ' ') + "HP: " + monster.Health); DrawScreen.AddLineToBuffer(ref battleArea1, " ".PadLeft(4, ' ') + ("LVL: " + hero.Level).PadRight(50, ' ') + "LVL: " + monster.Level); for (int i = 0; i < 2; i++) { DrawScreen.AddLineToBuffer(ref battleArea1, Environment.NewLine); } DrawScreen.AddLineToBuffer(ref battleArea1, new string('-', 90)); }
static void Main() { string separator = "**********************************************************************"; string title = String.Empty; #region Lazy objects testing title = "Lazy objects testing"; Console.WriteLine(separator); Console.WriteLine(String.Format(CultureInfo.InvariantCulture, "\t{0}", title)); Console.WriteLine(separator); Console.WriteLine(); LazyCustomer customer = new LazyCustomer(1); Console.WriteLine("LazyCustomer customer = new LazyCustomer(1);"); Console.WriteLine(String.Format(CultureInfo.InvariantCulture, "Are orders created ? {0}", customer.Orders.IsValueCreated ? "Yes" : "No")); Console.ReadLine(); List <Order> orders = customer.Orders.Value; Console.WriteLine("List<Order> orders = customer.Orders.Value;"); Console.WriteLine(String.Format(CultureInfo.InvariantCulture, "Are orders created ? {0}", customer.Orders.IsValueCreated ? "Yes" : "No")); Console.ReadLine(); #endregion #region Factory testing Console.Clear(); title = "Factory testing"; Console.WriteLine(separator); Console.WriteLine(String.Format(CultureInfo.InvariantCulture, "\t{0}", title)); Console.WriteLine(separator); Console.WriteLine(); Console.WriteLine("IMonster monster = MonsterFactory.CreateRandom();"); for (int i = 0; i < 10; i++) { IMonster monster = MonsterFactory.CreateRandom(); Console.WriteLine(monster.Attack()); } Console.ReadLine(); #endregion #region Reflection Console.Clear(); title = "Reflection"; Console.WriteLine(separator); Console.WriteLine(String.Format(CultureInfo.InvariantCulture, "\t{0}", title)); Console.WriteLine(separator); Console.WriteLine(); Assembly assembly = Assembly.LoadFrom(@"C:\Projects\Git\Playground\Playground\bin\Debug\Playground.exe"); List <Type> listClass = assembly.GetTypes().Where(x => typeof(IMonster).IsAssignableFrom(x) && !x.IsInterface && !x.IsAbstract).ToList(); Console.WriteLine("Liste des classes qui implémentent l'interface IMonster : "); Console.WriteLine(); List <IMonster> listMonsters = new List <IMonster>(); foreach (Type item in listClass) { var inst = (IMonster)Activator.CreateInstance(item); listMonsters.Add(inst); } Console.WriteLine("Instanciation dynamique des classes : "); foreach (IMonster monster in listMonsters) { Console.WriteLine(monster.ToString()); } Console.ReadLine(); #endregion #region WrapperPattern Console.Clear(); title = "Wrapper Pattern"; Console.WriteLine(separator); Console.WriteLine(String.Format(CultureInfo.InvariantCulture, "\t{0}", title)); Console.WriteLine(separator); Console.WriteLine(); EmailCreator.CreateEmailFrom("*****@*****.**") .To("*****@*****.**", "*****@*****.**") .CC("*****@*****.**") .BCC("*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**") .WithSubject("Email subject here") .WithBody("Email body here").Send(); #endregion #region Decorator Pattern Console.Clear(); title = "Decorator Pattern"; Console.WriteLine(separator); Console.WriteLine(String.Format(CultureInfo.InvariantCulture, "\t{0}", title)); Console.WriteLine(separator); Console.WriteLine(); AbstractCoffee coffee = null; // We cannot create instance of abstract class coffee = new Topping(coffee); coffee = new Sugar(coffee); coffee = new Milk(coffee); Console.WriteLine("Coffee with " + coffee.ShowCoffee()); Console.ReadLine(); #endregion }