예제 #1
0
    public override string ToString()
    {
        var builder = new StringBuilder();

        if (Gold.Any())
        {
            builder.AppendLine($"<Gold> ${GoldAmount}");
            builder.AppendLine($"##Gold - {GoldAmount}");
        }
        if (Gems.Any())
        {
            builder.AppendLine($"<Gem> ${GemsAmount}");
            foreach (var gem in Gems.OrderByDescending(g => g.Value.Name).ThenBy(g => g.Value.Amount))
            {
                builder.AppendLine($"##{gem.Value.Name} - {gem.Value.Amount}");
            }
        }
        if (AllCash.Any())
        {
            builder.AppendLine($"<Cash> ${CashAmount}");
            foreach (var cash in AllCash.OrderByDescending(c => c.Value.Name).ThenBy(c => c.Value.Amount))
            {
                builder.AppendLine($"##{cash.Value.Name} - {cash.Value.Amount}");
            }
        }

        return(builder.ToString());
    }
예제 #2
0
    public void AddGold(string name, long value)
    {
        if (Capacity + value <= MaxCapacity)
        {
            if (!Gold.Any(g => g.Name == name))
            {
                Gold.Add(new Gold(name));
            }

            var current = Gold.FirstOrDefault(g => g.Name == name);
            current.Value += value;
            Capacity      += value;
        }
    }