public void InterpretCommand(string command) { string[] split = command.Split(';'); switch (split[0]) { case "Create": string[] weaponData = split[1].Split(); IWeapon weapon = weaponFactory.CreateWeapon(weaponData[1], weaponData[0]); weapons.Add(split[2], weapon); break; case "Add": string[] gemData = split[3].Split(); IGem gem = gemFactory.CreateGem(gemData[1], gemData[0]); weapons[split[1]].AddGem(gem, int.Parse(split[2])); break; case "Remove": weapons[split[1]].RemoveGem(int.Parse(split[2])); break; case "Print": Console.WriteLine($"{split[1]}: {weapons[split[1]]}"); break; } }
public void AddGemToWeapon(string weaponName, int socketIndex, string gemInfo) { GemFactory gemFactory = new GemFactory(); IGem newGem = gemFactory.CreateGem(gemInfo); weapons.First(x => x.Name.Equals(weaponName)).SocketWithGems.Insert(socketIndex, newGem); }
public static void Main(string[] args) { Axe axe = new Axe("BigFuckinAxe", RarityType.Epic); WeaponFactory weaponFactory = new WeaponFactory(); GemFactory gemFactory = new GemFactory(); List <Weapon> weapons = new List <Weapon>(); string command; while ((command = Console.ReadLine()) != "END") { string[] commTokens = command.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToArray(); string currentCommand = commTokens[0]; switch (currentCommand) { case "Create": string[] createItemTypeAndRarity = commTokens[1].Split(); string rarityType = createItemTypeAndRarity[0]; string weaponType = createItemTypeAndRarity[1]; string weaponName = commTokens[2]; Weapon weaponToAdd = weaponFactory.CreateWeapon(rarityType, weaponType, weaponName); weapons.Add(weaponToAdd); break; case "Add": string enhanceWeaponName = commTokens[1]; int enhanceSocketIndex = int.Parse(commTokens[2]); string[] gemArgs = commTokens[3].Split(); Gem currentGem = gemFactory.CreateGem(gemArgs); Weapon weaponToEnhance = weapons.FirstOrDefault(x => x.Name.Equals(enhanceWeaponName)); weaponToEnhance.EnhanceWithGem(enhanceSocketIndex, currentGem); break; case "Remove": string removeEnhanceWeaponName = commTokens[1]; int removeEnhanceSocketIndex = int.Parse(commTokens[2]); Weapon weaponToRemoveEnhance = weapons.FirstOrDefault(x => x.Name.Equals(removeEnhanceWeaponName)); weaponToRemoveEnhance.RemoveGem(removeEnhanceSocketIndex); break; case "Print": string printWeaponName = commTokens[1]; Weapon printWeapon = weapons.FirstOrDefault(x => x.Name.Equals(printWeaponName)); Console.WriteLine(printWeapon); break; default: break; } } }
private void CommandInterpreter(string command, string[] commandArgs) { switch (command) { case "Create": Weapon weapon = weaponFactory.CreateWeapon(commandArgs.Skip(1).ToArray()); weapons.Add(weapon); break; case "Add": Weapon weaponAdd = weapons.FirstOrDefault(w => w.Name == commandArgs[1]); Gem gem = gemFactory.CreateGem(commandArgs.Skip(3).ToArray()); weaponAdd.Add(int.Parse(commandArgs[2]), gem); break; case "Remove": Weapon weaponRemove = weapons.FirstOrDefault(w => w.Name == commandArgs[1]); weaponRemove.Remove(int.Parse(commandArgs[2])); break; case "Print": Weapon weaponPrint = weapons.FirstOrDefault(w => w.Name == commandArgs[1]); Console.WriteLine(weaponPrint); break; } }
public void Run() { while (this.IsRunning) { var input = Console.ReadLine().Split(";"); var command = input[0]; switch (command) { case "Create": string rarity = input[1].Split()[0]; string weaponType = input[1].Split()[1]; string weaponName = input[2]; IWeapon weapon = weaponFactory.CreateWeapon(rarity, weaponType, weaponName); weapons.Add(weapon); break; case "Add": string weaponToSocket = input[1]; int socketIndex = int.Parse(input[2]); string gemRarity = input[3].Split()[0]; string gemType = input[3].Split()[1]; IGem gem = gemFactory.CreateGem(gemRarity, gemType); weapons.Find(x => x.Name == weaponToSocket).AddGem(socketIndex, gem); break; case "Remove": string weaponToRemove = input[1]; int socketIndexToRemove = int.Parse(input[2]); weapons.Find(x => x.Name == weaponToRemove).RemoveGem(socketIndexToRemove); break; case "Print": string weaponToPrint = input[1]; Console.WriteLine(weapons.Find(x => x.Name == weaponToPrint)); break; case "END": IsRunning = false; break; case "Author": Console.WriteLine("Author: " + GetAttribute().Author); break; case "Revision": Console.WriteLine("Revision: " + GetAttribute().Revision); break; case "Description": Console.WriteLine("Class description: " + GetAttribute().Description); break; case "Reviewers": Console.WriteLine("Reviewers: " + string.Join(", ", GetAttribute().Reviewers)); break; } } }
public override string Execute() { string[] gemArgs = CommandArgs[3].Split(); IGem gem = GemFactory.CreateGem(gemArgs[0], gemArgs[1]); this.WeaponRepository.AddGem(CommandArgs[1], int.Parse(CommandArgs[2]), gem); return(null); }
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; } } }
public void AddGem(string[] args) { string weaponName = args[0]; int index = int.Parse(args[1]); var gem = GemFactory.CreateGem(args.Skip(2).ToArray()); if (this.weapons.Any(x => x.Name == weaponName)) { this.weapons.FirstOrDefault(x => x.Name == weaponName).AddGem(index, gem); } }
//Refactor this to a separate class Command??? //Also the attribute can be moved in some other class may be, but I will leave them here for now //The Attributes part was added latter from different exercise and was not implemented in the best possible way private void ProcessTheCommand(string input) { var inputSplit = input.Split(';'); string command = inputSplit[0]; string name = String.Empty; int index = 0; // can think of making enum if (command != "Author" && command != "Revision" && command != "Description" && command != "Reviewers") { name = inputSplit[1]; } var attributes = typeof(Weapon).GetCustomAttributes(); CustomAttribute typeAttribute = attributes.ToArray()[0] as CustomAttribute; switch (command) { case "Create": Repository.Repository.AddWeapon(WeaponFactory.CreateWeapon(input)); break; case "Add": index = int.Parse(inputSplit[2]); string gem = inputSplit[3]; Repository.Repository.Weapons[name].AddGemInSocket(index, GemFactory.CreateGem(gem)); break; case "Remove": index = int.Parse(inputSplit[2]); Repository.Repository.Weapons[name].RemoveGemFromSocket(index); break; case "Print": WriteLine.Write(Repository.Repository.Weapons[name].ToString()); break; case "Author": WriteLine.Write($"Author: {typeAttribute.Author}"); break; case "Revision": WriteLine.Write($"Revision: {typeAttribute.Revision}"); break; case "Description": WriteLine.Write($"Class description: {typeAttribute.Description}"); break; case "Reviewers": WriteLine.Write($"Reviewers: {typeAttribute.Reviewers}"); break; } }
public override void Execute() { string weaponName = Data[1]; int index = int.Parse(Data[2]); string[] gemInfo = Data[3].Split(); Gem gem = gemFactory.CreateGem(gemInfo); Weapon weapon = weaponRepository.GetWeapon(weaponName); weapon.AddGem(index, gem); }
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); }
public void AddGem(string weaponName, int socketIndex, string gemInput) { IWeapon weapon = FindWeapon(weaponName); var gemArgs = gemInput.Split(); var gemClarity = gemArgs[0]; var gemType = gemArgs[1]; var gem = gemFactory.CreateGem(gemType, gemClarity); weapon.Add(socketIndex, gem); }
public void AddGem(string gemParams, int socketIndex, string weaponName) { var weapon = this.database.Weapons[weaponName]; if (weapon.SocketCount <= socketIndex || socketIndex < 0) { return; } Gem gem = GemFactory.CreateGem(gemParams); weapon.Sockets[socketIndex] = gem; }
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); }
public static void Main() { string input = string.Empty; Dictionary <string, Weapon> weaponsByName = new Dictionary <string, Weapon>(); while ((input = Console.ReadLine()) != "END") { string[] inputs = input.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); string command = inputs[0]; GemFactory gemFactory = new GemFactory(); WeaponFactory weaponFactory = new WeaponFactory(); switch (command) { case "Create": string[] weaponParams = inputs[1].Split(); string weaponName = inputs[2]; string weaponRarity = weaponParams[0]; string weaponType = weaponParams[1]; Weapon newWeapon = weaponFactory.CreateWeapon(weaponType, weaponRarity, weaponName); weaponsByName[weaponName] = newWeapon; break; case "Add": string[] gemParams = inputs[3].Split(); string gemType = gemParams[1]; string gemClarity = gemParams[0]; IWeaponSocketInsertable newItem = gemFactory.CreateGem(gemType, gemClarity); string weaponToInsert = inputs[1]; int socketToInsertTo = int.Parse(inputs[2]); weaponsByName[weaponToInsert].InsertIntoSocket(socketToInsertTo, newItem); break; case "Remove": string itemToRemoveFrom = inputs[1]; int socketToRemoveFrom = int.Parse(inputs[2]); weaponsByName[itemToRemoveFrom].RemoveFromSocket(socketToRemoveFrom); break; case "Print": Console.WriteLine(weaponsByName[inputs[1]]); break; } } }
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); }
public void Execute(IWeapon weapon, string[] info) { int socketIndex = int.Parse(info[0]); if (socketIndex < 0 || socketIndex >= weapon.Sockets) { throw new ArgumentException("Invalid socketIndex"); } Type typeOfWeapon = weapon.GetType(); FieldInfo gemField = typeOfWeapon.BaseType.GetField("gems", BindingFlags.Instance | BindingFlags.NonPublic); var hiddenArray = (IGem[])gemField.GetValue(weapon); IGem newGem = gemFactory.CreateGem(info[1].Split()); hiddenArray[socketIndex] = newGem; }