コード例 #1
0
        public void Run()
        {
            while (true)
            {
                string   userInput   = Console.ReadLine();
                string[] data        = userInput.Split(";");
                string   commandName = data[0];


                if (commandName == "Create")
                {
                    string[] weaponInfo   = data[1].Split(" ");
                    string   weaponRarity = weaponInfo[0];
                    string   weaponType   = weaponInfo[1];
                    string   weaponName   = data[2];

                    var weapon = WeaponFactory.CreateWeapon(weaponType, weaponRarity, weaponName);

                    this.repository.AddWeapon(weapon);
                }
                else if (commandName == "Add")
                {
                    string  weaponName = data[1];
                    IWeapon weapon     = this.repository.GetWeapon(weaponName);

                    int gemSocketIndex = int.Parse(data[2]);

                    string[] gemInfo    = data[3].Split(" ");
                    string   gemClarity = gemInfo[0];
                    string   gemType    = gemInfo[1];

                    var gem = GemFactory.CreateGem(gemType, gemClarity);

                    weapon.AddGem(gem, gemSocketIndex);
                }
                else if (commandName == "Remove")
                {
                    string  weaponName = data[1];
                    IWeapon weapon     = this.repository.GetWeapon(weaponName);

                    int socketToRemoveIndex = int.Parse(data[2]);

                    weapon.RemoveGem(socketToRemoveIndex);
                }
                else if (commandName == "Print")
                {
                    string weaponName = data[1];

                    var weapon = this.repository.GetWeapon(weaponName);

                    Console.WriteLine(weapon.ToString());
                }
                else if (commandName == "END")
                {
                    break;
                }
            }
        }
コード例 #2
0
        public override void ExecuteCommand()
        {
            var     weaponName = data[1];
            IWeapon weapon     = weaponRepository.GetWeapon(weaponName);
            int     socket     = int.Parse(data[2]);
            IGem    gem        = gemFactory.CreateGem(data);

            weapon.AddGem(gem, socket);
        }
コード例 #3
0
    public void Execute()
    {
        IWeapon weapon = this.weapons.FirstOrDefault(x => x.Name == weaponName);

        if (weapon != null)
        {
            weapon.AddGem(this.gemFactory.CreateGem(gemType.Split(' ')[1], Enum.Parse <Clarity>(gemType.Split(' ')[0]))
                          , this.socketIndex);
        }
    }
コード例 #4
0
    public override void Execute()
    {
        string  weaponName = this.Data[0];
        IWeapon weapon     = this.Armory.GetWeapon(weaponName);

        string[] gemArgs = this.Data.Last().Split().ToArray();
        IGem     gem     = this.GemFactory.CreateGem(gemArgs);
        int      gemSlot = int.Parse(this.Data[1]);

        weapon.AddGem(gem, gemSlot);
    }
コード例 #5
0
        public override void Execute()
        {
            string weaponName  = this.Data[1];
            int    socketIndex = int.Parse(this.Data[2]);
            string clarity     = this.Data[3].Split()[0];
            string gemType     = this.Data[3].Split()[1];

            IWeapon weapon = this.Repository.Weapons.Find(x => x.Name == weaponName);
            IGem    gem    = GemFactory.CreateGem(clarity, gemType);

            weapon.AddGem(gem, socketIndex);
        }
コード例 #6
0
        public void ExecuteCommand(IList <string> tokens)
        {
            IWeapon  currentWeapon = null;
            IBaseGem currentGem    = null;

            var commandName = tokens[0];

            switch (commandName)
            {
            case "Create":
                var weaponInfo = this.inHandler.SplitInput(tokens[1], " ");
                weaponInfo.Add(tokens[2]);
                this.weapons.Add(this.weaponFactory.Create(weaponInfo));
                break;

            case "Add":
                currentWeapon = GetWeapon(tokens[1]);
                currentGem    = this.gemFactory.Create(this.inHandler.SplitInput(tokens[3], " "));

                currentWeapon.AddGem(int.Parse(tokens[2]), currentGem);
                break;

            case "Remove":
                currentWeapon = GetWeapon(tokens[1]);
                currentWeapon.RemoveGem(int.Parse(tokens[2]));
                break;

            case "Print":
                currentWeapon = GetWeapon(tokens[1]);
                this.outHandler.PrintLine(currentWeapon.ToString());
                break;

            case "Author":
                this.outHandler.PrintLine(this.weaponAttribute.PrintInfo("Author"));
                break;

            case "Revision":
                this.outHandler.PrintLine(this.weaponAttribute.PrintInfo("Revision"));
                break;

            case "Description":
                this.outHandler.PrintLine(this.weaponAttribute.PrintInfo("Description"));
                break;

            case "Reviewers":
                this.outHandler.PrintLine(this.weaponAttribute.PrintInfo("Reviewers"));
                break;

            default:
                throw new InvalidOperationException($"Command not available: {commandName}");
            }
        }
コード例 #7
0
    public void Execute(string[] commandParameters, IDictionary <string, IWeapon> weapons, IWeaponFactory weaponFactory, IInputOutputManager inputOutputManager, IGemFactory gemFactory)
    {
        string targetAxeName = commandParameters[0];
        int    socketIndex   = int.Parse(commandParameters[1]);

        string[] tokens  = commandParameters[2].Split(' ');
        string   clarity = tokens[0];
        string   type    = tokens[1];
        IGem     gem     = gemFactory.CreateGem(type, clarity);

        IWeapon targetAxe = weapons[targetAxeName];

        targetAxe.AddGem(gem, socketIndex);
    }
コード例 #8
0
        public void Run()
        {
            string input;

            while ((input = Console.ReadLine()) != "END")
            {
                string[] inputArgs = input.Split(';');

                string command = inputArgs[0];

                switch (command)
                {
                case "Create":
                    string[] weaponArgs = inputArgs[1].Split();
                    string   weaponType = weaponArgs[1];
                    string   quality    = weaponArgs[0];
                    string   name       = inputArgs[2];
                    IWeapon  weapon     = this.weaponFactory.CreateWeapon(weaponType, quality, name);
                    this.weapons.Add(weapon);
                    break;

                case "Add":
                    string[] addGemArgs    = inputArgs[3].Split();
                    string   addGemClarity = addGemArgs[0];
                    string   addGemType    = addGemArgs[1];

                    IGem gem = this.gemFactory.CreateGem(addGemType, addGemClarity);

                    IWeapon addGemWeapon = this.weapons.First(w => w.Name == inputArgs[1]);

                    addGemWeapon.AddGem(int.Parse(inputArgs[2]), gem);
                    break;

                case "Remove":
                    IWeapon removeGemWeapon = this.weapons.First(w => w.Name == inputArgs[1]);

                    removeGemWeapon.RemoveGem(int.Parse(inputArgs[2]));

                    break;

                case "Print":

                    IWeapon printWeapon = this.weapons.First(w => w.Name == inputArgs[1]);


                    Console.WriteLine(printWeapon.ToString());
                    break;
                }
            }
        }
コード例 #9
0
        public override void Execute()
        {
            List <IWeapon> weapons = this.Repository.GetWeapons();
            IWeapon        weapon  = weapons.FirstOrDefault(w => w.Name == base.Data[1]);

            if (weapon != null)
            {
                string[] gemInfo = base.Data[3]
                                   .Split(" ", StringSplitOptions.RemoveEmptyEntries)
                                   .ToArray();
                IGem gem = this.GemFactory.CreateGem(gemInfo[0], gemInfo[1]);
                weapon.AddGem(int.Parse(base.Data[2]), gem);
            }
        }
コード例 #10
0
        public void Add(string[] data)
        {
            string name  = data[0];
            int    index = int.Parse(data[1]);

            string[] gemInfo = data[2].Split();
            string   clarity = gemInfo[0];
            string   type    = gemInfo[1];

            IGem gem = gemFactory.CreateGem(clarity, type);

            IWeapon weapon = this.weapons.FirstOrDefault(w => w.Name == name);

            weapon.AddGem(gem, index);
        }
コード例 #11
0
    public override void Execute()
    {
        var gemClass    = this.Data[3].Split()[1];
        var clarityName = this.Data[3].Split()[0];

        IGem gem = this.GemFactory.CreateGem(gemClass, clarityName);

        var weaponName = this.Data[1];
        int index      = int.Parse(this.Data[2]);

        IWeapon weapon = this.Repository.GetWeapon(weaponName);

        if (weapon != null)
        {
            weapon.AddGem(index, gem);
        }
    }
コード例 #12
0
        public override void Execute()
        {
            string weaponName  = this.Data[1];
            int    socketIndex = int.Parse(this.Data[2]);

            string[] gemInfo    = this.Data[3].Split(' ');
            string   gemQuality = gemInfo[0];
            string   gemType    = gemInfo[1];

            IGem gem = this.gemFactory.CreateGem(gemType, gemQuality);

            IWeapon weapon = this.createdWeapons.FirstOrDefault(w => w.Name == weaponName);

            weapon.AddGem(gem, socketIndex);

            this.weaponStorage.Add(weapon);
        }
コード例 #13
0
        public override void Ecexute()
        {
            // Input tokens
            string name              = this.Tokens[0];
            int    targetSocket      = int.Parse(this.Tokens[1]);
            string gemLevelOfQuality = this.Tokens[2].Split().ToArray()[0];
            string gemType           = this.Tokens[2].Split().ToArray()[1];

            IGem    gem    = GemFactory.GetGem(gemType, gemLevelOfQuality);             // Get new gem
            IWeapon weapon = this.Database.Weapons.FirstOrDefault(n => n.Name == name); // Search for weapon

            if (gem != null && weapon != null)
            {
                // Both gem and weapon are not null
                weapon.AddGem(targetSocket, gem);
            }
        }
コード例 #14
0
        public static void Main()
        {
            List <IWeapon> weapons = new List <IWeapon>();
            string         input;

            while ((input = Console.ReadLine()) != "END")
            {
                string[] args    = input.Split(';');
                string   command = args[0];
                switch (command)
                {
                case "Create":
                    string rarity                 = args[1].Split()[0];
                    string typeOfWeapon           = args[1].Split()[1];
                    string name                   = args[2];
                    string fullNameOfTypeOfWeapon = $"P07_InfernoInfinity.Models.Weapons.{typeOfWeapon}";
                    weapons.Add((IWeapon)Activator.CreateInstance(Type.GetType(fullNameOfTypeOfWeapon), name, rarity));
                    break;

                case "Add":
                    string  weaponName    = args[1];
                    int     index         = int.Parse(args[2]);
                    string  clarityOfGem  = args[3].Split()[0];
                    string  typeOfGem     = args[3].Split()[1];
                    string  fullTypeOfGem = $"P07_InfernoInfinity.Models.Gems.{typeOfGem}";
                    IWeapon weapon        = weapons.Single(w => w.Name == weaponName);                // check for duplic or unexistance !!!
                    weapon.AddGem(index, (IGem)Activator.CreateInstance(Type.GetType(fullTypeOfGem), clarityOfGem));
                    break;

                case "Remove":
                    string  weapon_name           = args[1];
                    int     socketIndex           = int.Parse(args[2]);
                    IWeapon weaponToRemoveGemFrom = weapons.Single(w => w.Name == weapon_name);      // check for duplic or unexistance !!!
                    weaponToRemoveGemFrom.RemoveGem(socketIndex);
                    break;

                case "Print":
                    string  weapon_name_forPrint = args[1];
                    IWeapon weaponForPrint       = weapons.Single(w => w.Name == weapon_name_forPrint); // check for duplic or unexistance !!!
                    Console.WriteLine(weaponForPrint.ToString());
                    break;
                }
            }
        }
コード例 #15
0
ファイル: Add.cs プロジェクト: vesy53/SoftUni
        public override void Execute()
        {
            string name  = this.Data[0];
            int    index = int.Parse(this.Data[1]);

            string[] split = this.Data[2]
                             .Split(" ",
                                    StringSplitOptions
                                    .RemoveEmptyEntries);

            string levelClarityStr = split[0];
            string typeGem         = split[1];

            LevelClarity clarity = (LevelClarity)Enum
                                   .Parse(typeof(LevelClarity), levelClarityStr);

            IGem    gem    = this.GemFactory.CreateGem(typeGem, clarity);
            IWeapon weapon = this.Repository.GetWeapon(name);

            weapon.AddGem(gem, index);
        }
コード例 #16
0
        public void AddGemToSocket(string weaponName, int gemSlot, IGem gem)
        {
            IWeapon weapon = weaponStorage[weaponName];

            weapon.AddGem(gemSlot, gem);
        }
コード例 #17
0
        public void AddGem(string weapon, int index, IGem gem)
        {
            IWeapon searchedWeapon = weapons.First(w => w.Name == weapon);

            searchedWeapon.AddGem(index, gem);
        }