コード例 #1
0
ファイル: Gem.cs プロジェクト: ulivegenov/SoftUni
 protected Gem(ClarityEnum clarity, int baseStrength, int baseAgility, int baseVitality)
 {
     this.Clarity      = clarity;
     this.BaseStrength = baseStrength;
     this.BaseAgility  = baseAgility;
     this.BaseVitality = baseVitality;
 }
コード例 #2
0
        public override void Execute()
        {
            string[] commandArgs = this.Data.Split(';');
            string   weaponName  = commandArgs[0];
            int      slotIndex   = int.Parse(commandArgs[1]);

            string[]    gemArgs = commandArgs[2].Split();
            ClarityEnum clarity = (ClarityEnum)Enum.Parse(typeof(ClarityEnum), gemArgs[0], true);
            string      gemName = gemArgs[1];

            GemFactory gemFactory = new GemFactory();
            IGem       gem        = gemFactory.CreateGem(clarity, gemName);

            this.Repository.Weapons
            .FirstOrDefault(w => w.Name == weaponName)
            .AddGem(slotIndex, gem);
        }
コード例 #3
0
ファイル: GemFactory.cs プロジェクト: ulivegenov/SoftUni
        public IGem CreateGem(ClarityEnum clarity, string gemName)
        {
            Assembly assembly = Assembly.GetExecutingAssembly();
            Type     type     = assembly.GetTypes().FirstOrDefault(t => t.Name == gemName);

            if (type == null)
            {
                throw new InvalidOperationException("Invalid Gem Type!");
            }

            if (!typeof(IGem).IsAssignableFrom(type))
            {
                throw new InvalidOperationException($"{type} is not a Gem!");
            }

            return((IGem)Activator.CreateInstance(type, new object[] { clarity }));
        }
コード例 #4
0
 public Amethyst(ClarityEnum clarity) : base(clarity, 2, 8, 4)
 {
 }
コード例 #5
0
 public Ruby(ClarityEnum clarity) : base(clarity, 7, 2, 5)
 {
 }
コード例 #6
0
 public Emerald(ClarityEnum clarity) : base(clarity, 1, 4, 9)
 {
 }