public void Run() { string input = reader.ReadLine(); while (input != "End") { string[] firstSplit = input.Split(); Animal animal = animalFactory.CreateAnimal(firstSplit); animals.Add(animal); string[] secondSplit = reader.ReadLine().Split(); Food food = foodFactory.CreateFood(secondSplit); writer.WriteLine(animal.ProduceSound()); try { animal.Feed(food); } catch (Exception ae) { writer.WriteLine(ae.Message); } input = reader.ReadLine(); } foreach (var anim in animals) { writer.WriteLine(anim.ToString()); } }
public void Run() { string line; while ((line = reader.ReadLine()) != "End") { var animalInfo = line.Split(); var foodInfo = reader.ReadLine().Split(); Animal animal = animalFactory.CreateAnimal(animalInfo); Food food = foodFactory.CreateFood(foodInfo); writer.WriteLine(animal.ProduceSound()); try { animal.Feed(food); } catch (ArgumentException ae) { writer.WriteLine(ae.Message); } animals.Add(animal); } foreach (var animal in this.animals) { writer.WriteLine(animal.ToString()); } }
private void PurchaseFood() { var name = (string)null; while ((name = reader.ReadLine()) != "End") { var person = this.people .FirstOrDefault(p => p.Name == name); if (person != null) { person.BuyFood(); } } }
private void CallNumbers() { var numbers = reader .ReadLine() .Split(' ', StringSplitOptions.None) .ToArray(); foreach (var number in numbers) { try { if (number.Length == 7) { writer.WriteLine(this.stationaryPhone.Call(number)); } else if (number.Length == 10) { writer.WriteLine(this.smartphone.Call(number)); } else { throw new InvalidNumberExeption(); } } catch (InvalidNumberExeption msg) { Console.WriteLine(msg.Message); } } }
public void Run() { string line; while ((line = reader.ReadLine()) != "END") { var teamInfo = line.Split(';', StringSplitOptions.RemoveEmptyEntries); var command = teamInfo[0]; var teamName = teamInfo[1]; try { if (command == "Team") { Team team = new Team(teamName); teams.Add(team); } else if (command == "Add") { var teamtoAdd = teams.FirstOrDefault(t => t.Name == teamName); if (teamtoAdd == null) { throw new ArgumentException(String.Format(ExceptionMessages.InvalidTeamExc, teamName)); } var playerName = teamInfo[2]; var stats = teamInfo.Skip(3).Select(int.Parse).ToArray(); Player player = playerFactory.CreatePlayer(playerName, stats); teamtoAdd.Add(player); } else if (command == "Remove") { var currTeam = teams.FirstOrDefault(t => t.Name == teamName); if (currTeam == null) { throw new ArgumentException(String.Format(ExceptionMessages.InvalidTeamExc, teamName)); } var playerName = teamInfo[2]; currTeam.Remove(playerName); } else if (command == "Rating") { var currTeam = teams.FirstOrDefault(t => t.Name == teamName); if (currTeam == null) { throw new ArgumentException(String.Format(ExceptionMessages.InvalidTeamExc, teamName)); } writer.WriteLine($"{currTeam.Name} - {currTeam.Rating}"); } } catch (ArgumentException ae) { writer.WriteLine(ae.Message); } } }
public void Run() { int n = int.Parse(reader.ReadLine()); BaseHero hero = null; while (heroes.Count != n) { string name = reader.ReadLine(); string type = reader.ReadLine(); hero = factory.GetHero(name, type); if (hero == null) { writer.WriteLine("Invalid hero!"); } else { heroes.Add(hero); } } int bossPower = int.Parse(reader.ReadLine()); int totalSum = 0; foreach (var person in heroes) { writer.WriteLine(person.CastAbility()); totalSum += person.Power; } if (totalSum >= bossPower) { writer.WriteLine("Victory!"); } else { writer.WriteLine("Defeat..."); } }
private void FillCollection() { string commad; while ((commad = reader.ReadLine()) != "End") { try { CollectAllSoldiers(commad); } catch (Exception) { continue; } } }
private void CollectAllCitizen() { var command = (string)null; while ((command = reader.ReadLine()) != "End") { var cmdArg = command .Split(' ', StringSplitOptions.RemoveEmptyEntries) .ToArray(); var name = cmdArg[0]; var country = cmdArg[1]; var age = int.Parse(cmdArg[2]); var citizen = new Citizen(name, age, country); PrintResult(citizen); } }