public static void Attack(IMonster a, IMonster b) { if (a.Speed >= b.Speed) { a.Attack(b); if (b.IsAlive) { b.Attack(a); } } else { b.Attack(a); if (a.IsAlive) { a.Attack(b); } } }
private static void Attack(int counter, IMonster player, IMonster enemy) { ConsoleExtras.ColorLine($"\nRound {counter + 1}:"); if (player.Speed >= enemy.Speed) { player.Attack(enemy); if (enemy.IsAlive) { enemy.Attack(player); } } else { enemy.Attack(player); if (player.IsAlive) { player.Attack(enemy); } } }
public Battle(Hero hero, IMonster monster) { while (hero.Health > 0 && monster.Health > 0) { monster.Health -= hero.Attack(); hero.Health -= monster.Attack(); } if (hero.Health > 0) { Console.WriteLine(@" /$$ |__/ /$$ /$$ /$$$$$$ /$$ /$$ /$$ /$$ /$$ /$$ /$$$$$$$ | $$ | $$ /$$__ $$| $$ | $$ | $$ | $$ | $$| $$| $$__ $$ | $$ | $$| $$ \ $$| $$ | $$ | $$ | $$ | $$| $$| $$ \ $$ | $$ | $$| $$ | $$| $$ | $$ | $$ | $$ | $$| $$| $$ | $$ | $$$$$$$| $$$$$$/| $$$$$$/ | $$$$$/$$$$/| $$| $$ | $$ \____ $$ \______/ \______/ \_____/\___/ |__/|__/ |__/ /$$ | $$ | $$$$$$/ \______/"); } else { Console.WriteLine(@" /$$ /$$ /$$ | $$|__/ | $$ /$$ /$$ /$$$$$$ /$$ /$$ /$$$$$$$ /$$ /$$$$$$ /$$$$$$$ | $$ | $$ /$$__ $$| $$ | $$ /$$__ $$| $$ /$$__ $$ /$$__ $$ | $$ | $$| $$ \ $$| $$ | $$ | $$ | $$| $$| $$$$$$$$| $$ | $$ | $$ | $$| $$ | $$| $$ | $$ | $$ | $$| $$| $$_____/| $$ | $$ | $$$$$$$| $$$$$$/| $$$$$$/ | $$$$$$$| $$| $$$$$$$| $$$$$$$ \____ $$ \______/ \______/ \_______/|__/ \_______/ \_______/ /$$ | $$ | $$$$$$/ \______/ "); } }
public static void Fight(IPlayer player) { Random rnd = new Random(); CreateMonsters(player); //Select a monster appropriate for player level int index = rnd.Next(monstersList.Count); monster = monstersList[index]; Console.WriteLine($"You encounter a {monster.Name}!"); //Starts the Combat resolution while (monster.Hp > 0 && player.Hp > 0) { if (player.Hp < player.MaxHp && player.Consumable != null) { Potions heal = new Potions(); Console.WriteLine("Do you wish to use a potion? y or n"); string usePotion = Console.ReadLine(); if (usePotion.ToUpper() == "Y") { heal.Restore(player); // IConsumable potion = player.Consumable.First(); // player.Hp += potion.Amount; // if (player.Hp > player.MaxHp) // { // player.Hp = player.MaxHp; // } // player.Consumable.RemoveAt(0); } } var playerDamage = player.Attack(player.Weapon); var monsterDamage = monster.Attack(monster.Strength); Console.WriteLine($"You attack and deal {playerDamage} damage!, {monster.Name} negates {monster.Armor} damage"); monster.Hp -= playerDamage - monster.Armor; Console.WriteLine($"{monster.Name} has {monster.Hp} HP left"); if (monster.Hp <= 0) { Console.WriteLine("you won the fight!"); monster.Gold = monster.DropGold(monster.Level); Console.WriteLine($"{monster.Name} yielded {monster.Exp} experience and dropped {monster.Gold} gold"); player.Exp += monster.Exp; player.Gold += monster.Gold; Console.WriteLine($"you now have {player.Gold} gold"); if (player.Exp >= player.ExpToLevel) { player = player.LevelUp(player); Console.WriteLine($"You gained a level! you are now level {player.Level}"); if (player.Level == 10) { wonGame = !wonGame; } } Console.WriteLine(""); Console.WriteLine("Press enter to continue"); Console.ReadLine(); break; } Console.WriteLine($"{monster.Name} attacks and deal {monsterDamage}, you negate {player.Armor.StatType} damage"); player.Hp -= monsterDamage - player.Armor.StatType; Console.WriteLine($"You have {player.Hp} HP left"); if (player.Hp <= 0) { Console.WriteLine("You died..."); Console.WriteLine("Press enter to exit"); lostGame = !lostGame; break; } Console.WriteLine(""); Console.WriteLine("*******************************************************************"); Console.ReadLine(); } }
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 }
static void Start() { string answer; bool Finish = true; bool turn = false; while (Finish) { answer = Console.ReadLine().ToUpper(); PrintInterface(); if (answer == "АТАКА") { Player.Attack(monster); } else if (answer == "ОСМОТРЕТЬ") { Player.checkHp(monster); Console.Read(); } else if (answer == "СБЕЖАТЬ") { Console.WriteLine("Ну и беги, жалкий трус"); Finish = false; turn = true; Thread.Sleep(800); } else { Console.WriteLine("Введите корректный ответ"); turn = true; } if (Finish && !turn) { PrintInterface(); if (monster.GetHp() <= 0) { Console.WriteLine("Монстр умер, Ты герой"); Finish = false; Thread.Sleep(800); } else { Console.WriteLine("Монстр Атакует"); monster.Attack(Player); Thread.Sleep(800); } if (Player.Hp <= 0) { Console.WriteLine("Ты умер, Игра окончена"); Finish = false; Thread.Sleep(800); } PrintInterface(); } turn = false; } }