コード例 #1
0
    public string Check(List <string> arguments)
    {
        string currentId = arguments[0];

        if (providers.Any(p => p.id == currentId))
        {
            Provider provider = providers.Single(p => p.id == currentId);

            string        className = (provider.GetType().Name);
            StringBuilder sb        = new StringBuilder();
            sb.AppendLine($"{className.Substring(0, className.Length - 8)} Provider - {currentId}");
            sb.AppendLine($"Energy Output: {provider.EnergyOutput}");

            return(sb.ToString().TrimEnd());
        }
        else if (harvesters.Any(p => p.id == currentId))
        {
            Harvester harvester = harvesters.Single(p => p.id == currentId);

            string        className = (harvester.GetType().Name);
            StringBuilder sb        = new StringBuilder();
            sb.AppendLine($"{className.Substring(0, className.Length - 9)} Harvester - {currentId}");
            sb.AppendLine($"Ore Output: {harvester.OreOutput}");
            sb.AppendLine($"Energy Requirement: {harvester.EnergyRequirement}");

            return(sb.ToString().TrimEnd());
        }

        return($"No element found with id - {currentId}");
    }
コード例 #2
0
    public string RegisterHarvester(List <string> arguments)
    {
        Harvester harvester = HarvesterFactory.CreateHarvester(arguments);

        this.harvesters.Add(harvester);
        return($"Successfully registered {harvester.GetType().Name.Replace("Harvester", "")} Harvester - {harvester.Id}");
    }
コード例 #3
0
    public string RegisterHarvester(List <string> arguments)
    {
        try
        {
            Harvester harvester = HarvesterFactory.CreateHarvester(arguments);

            this.Harvesters[harvester.Id] = harvester;

            string fullType = harvester.GetType().Name;
            string type     = fullType.Substring(0, fullType.LastIndexOf('H'));

            return($"Successfully registered {type} Harvester - {harvester.Id}");
        }
        catch (ArgumentException argumentException)
        {
            return(argumentException.Message);
        }
    }
コード例 #4
0
    public string Check(List <string> arguments)
    {
        var       id        = arguments[0];
        Harvester harvester = this.harvesters.FirstOrDefault(x => x.Id == id);
        Provider  provider  = this.providers.FirstOrDefault(x => x.Id == id);
        var       sb        = new StringBuilder();

        if (harvester != null)
        {
            switch (harvester.GetType().Name)
            {
            case "HammerHarvester":
                sb.Append($"Hammer Harvester - {id}" + Environment.NewLine);
                break;

            case "SonicHarvester":
                sb.Append($"Sonic Harvester - {id}" + Environment.NewLine);
                break;
            }
            sb.Append($"Ore Output: {harvester.OreOutput}" + Environment.NewLine +
                      $"Energy Requirement: {harvester.EnergyRequirement}");
            return(sb.ToString());
        }

        if (provider != null)
        {
            switch (provider.GetType().Name)
            {
            case "PressureProvider":
                sb.Append($"Pressure Provider - {id}" + Environment.NewLine);
                break;

            case "SolarProvider":
                sb.Append($"Solar Provider - {id}" + Environment.NewLine);
                break;
            }
            sb.Append($"Energy Output: {provider.EnergyOutput}");
            return(sb.ToString());
        }
        return($"No element found with id - {id}");
    }
コード例 #5
0
ファイル: DraftManager.cs プロジェクト: nikolayvutov/CSharp
    public string Check(List <string> arguments)
    {
        var hasProvider = providers.Any(p => p.Id == arguments[0]);
        var hasHarvest  = harvesters.Any(p => p.Id == arguments[0]);

        if (hasHarvest)
        {
            Harvester harvester = harvesters.First(h => h.Id == arguments[0]);
            var       type      = harvester.GetType().Name;
            return($"{type.Substring(0, type.Length - 9)} Harvester - {harvester.Id}" + Environment.NewLine +
                   $"Ore Output: {harvester.OreOutput}" + Environment.NewLine +
                   $"Energy Requirement: {harvester.EnergyRequirement}");
        }
        else if (hasProvider)
        {
            Provider provider = providers.First(p => p.Id == arguments[0]);
            var      type     = provider.GetType().Name;
            return($"{type.Substring(0, type.Length - 8)} Provider - {provider.Id}" +
                   Environment.NewLine +
                   $"Energy Output: {provider.EnergyOutput}");
        }

        return($"No element found with id - {arguments[0]}");
    }
コード例 #6
0
    public string RegisterHarvester(List <string> arguments)
    {
        string type              = arguments[0];
        string id                = arguments[1];
        double oreOutput         = double.Parse(arguments[2]);
        double energyRequirement = double.Parse(arguments[3]);
        int    sonicFactor       = arguments.Count > 4 ? int.Parse(arguments[4]) : 0;

        Harvester newHarvester = null;

        try
        {
            newHarvester = this.harvesterFactory.ProduceHarvester(type, id, oreOutput, energyRequirement, sonicFactor);
        }
        catch (ArgumentException e)
        {
            string origin = e.TargetSite.Name.Replace("set_", "");
            return(string.Format(Constants.RegisterHarvesterFailureMessage, origin));
        }

        this.harvestersById.Add(newHarvester.Id, newHarvester);
        this.AddModel(newHarvester);
        return(string.Format(Constants.RegisterHarvesterSuccessMessage, newHarvester.GetType().Name.Replace("Harvester", ""), newHarvester.Id));
    }