Advertisement
ivanov_ivan

FromMeToYou

Aug 17th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.46 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Reflection;
  5. using System.Text;
  6.  
  7. public class HeroManager
  8. {
  9.     public Dictionary<string, IHero> heroes;
  10.  
  11.     public string AddHero(List<String> arguments)
  12.     {
  13.         string result = null;
  14.  
  15.         string heroName = arguments[0];
  16.         string heroType = arguments[1];
  17.  
  18.         try
  19.         {
  20.             Type clazz = Type.GetType(heroType);
  21.             var constructors = clazz.GetConstructors();
  22.             IHero hero = (IHero) constructors[0].Invoke(new object[] {heroName});
  23.  
  24.  
  25.             result = string.Format($"Created {heroType} - {hero.GetType().Name}");
  26.         }
  27.         catch (Exception e)
  28.         {
  29.             return e.Message;
  30.         }
  31.  
  32.         return result;
  33.     }
  34.  
  35.     public string AddItemToHero(List<String> arguments, Hero hero)
  36.     {
  37.         string result = null;
  38.  
  39.         //Ма те много бе! // Ма ти нищо не разбираш
  40.         string itemName = arguments[0];
  41.         string heroName = arguments[1];
  42.         int strengthBonus = int.Parse(arguments[2]);
  43.         int agilityBonus = int.Parse(arguments[3]);
  44.         int intelligenceBonus = int.Parse(arguments[4]);
  45.         int hitPointsBonus = int.Parse(arguments[5]);
  46.         int damageBonus = int.Parse(arguments[6]);
  47.  
  48.         CommonItem newItem = new CommonItem(itemName, strengthBonus, agilityBonus, intelligenceBonus, hitPointsBonus,
  49.             damageBonus);
  50.         //тука трябваше да добавя към hero ама промених едно нещо и то много неща се счупиха и реших просто да не добавям // щот толкоз си можеш
  51.  
  52.         result = string.Format(Constants.ItemCreateMessage, newItem.Name, heroName);
  53.         return result;
  54.     }
  55.  
  56.     public string CreateGame()
  57.     {
  58.         StringBuilder result = new StringBuilder();
  59.  
  60.         foreach (var hero in heroes)
  61.         {
  62.             result.AppendLine(hero.Key);
  63.         }
  64.  
  65.         return result.ToString();
  66.     }
  67.  
  68.     public string Inspect(List<String> arguments)
  69.     {
  70.         string heroName = arguments[0];
  71.  
  72.         return this.heroes[heroName].ToString();
  73.     }
  74.  
  75.     //Само Батман знае как работи това
  76.     // И един истински Javatar - Викай ми Батман
  77.     public static void GenerateResult()
  78.     {
  79.         const string PropName = "_connectionString";
  80.  
  81.         var type = typeof(HeroCommand);
  82.  
  83.         FieldInfo fieldInfo = null;
  84.         PropertyInfo propertyInfo = null;
  85.         while (fieldInfo == null && propertyInfo == null && type != null)
  86.         {
  87.             fieldInfo = type.GetField(PropName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
  88.             if (fieldInfo == null)
  89.             {
  90.                 propertyInfo = type.GetProperty(PropName,
  91.                     BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
  92.             }
  93.  
  94.             type = type.BaseType;
  95.         }
  96.     }
  97.  
  98.     public static void DontTouchThisMethod()
  99.     {
  100.         //това не трябва да го пипаме, че ако го махнем ще ни счупи цялата логика
  101.         // Ще счупи ... ако я има!
  102.         var l = new List<string>();
  103.         var m = new Manager();
  104.         HeroCommand cmd = new HeroCommand(l, m);
  105.         var str = "Execute";
  106.         Console.WriteLine(str);
  107.     }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement