Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- class Town
- {
- public string Name { get; set; }
- public int People { get; set; }
- public int Gold { get; set; }
- public Town(string name, int people, int gold)
- {
- this.Name = name;
- this.People = people;
- this.Gold = gold;
- }
- }
- class Program
- {
- public static List<Town> towns = new List<Town>();
- static void Main()
- {
- ReadInputTownInfo();
- string input;
- while ((input = Console.ReadLine()) != "End")
- {
- string[] cmd = input.Split("=>");
- if (cmd[0] == "Plunder") Plunder(cmd);
- else if (cmd[0] == "Prosper") Prosper(cmd);
- }
- if (towns.Count > 0)
- {
- Console.WriteLine($"Ahoy, Captain! There are {towns.Count} wealthy settlements to go to:");
- Console.WriteLine(String.Join("\n", towns
- .Select(x => $"{x.Name} -> Population: {x.People} citizens, Gold: {x.Gold} kg")));
- }
- else
- Console.WriteLine("Ahoy, Captain! All targets have been plundered and destroyed!");
- }
- private static void ReadInputTownInfo()
- {
- string input;
- while ((input = Console.ReadLine()) != "Sail")
- {
- string[] tokens = input.Split("||");
- string name = tokens[0];
- int people = int.Parse(tokens[1]);
- int gold = int.Parse(tokens[2]);
- if (!towns.Any(x => x.Name == name))
- towns.Add(new Town(name, people, gold));
- else
- {
- Town town = towns.Find(x => x.Name == name);
- town.People += people;
- town.Gold += gold;
- }
- }
- }
- private static void Plunder(string[] cmd)
- {
- Town town = towns.Find(x => x.Name == cmd[1]);
- int plunderPeople = int.Parse(cmd[2]);
- int plunderGold = int.Parse(cmd[3]);
- town.People -= plunderPeople;
- town.Gold -= plunderGold;
- Console.WriteLine($"{town.Name} plundered! {plunderGold} gold stolen, {plunderPeople} citizens killed.");
- if (town.People <= 0 || town.Gold <= 0)
- {
- Console.WriteLine($"{town.Name} has been wiped off the map!");
- towns.Remove(town);
- }
- }
- private static void Prosper(string[] cmd)
- {
- Town town = towns.Find(x => x.Name == cmd[1]);
- int goldIncrease = int.Parse(cmd[2]);
- if (goldIncrease < 0)
- Console.WriteLine("Gold added cannot be a negative number!");
- else
- {
- town.Gold += goldIncrease;
- Console.WriteLine($"{goldIncrease} gold added to the city treasury. {town.Name} now has {town.Gold} gold.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement