Exemplo n.º 1
0
        public override void Translate()
        {
            var value = GetValue();
            var parts = value.Split(' ');

            var roman      = String.Empty;
            var thingValue = 1m;
            var lastRoman  = parts.Length;

            for (var p = 0; p < parts.Length; p++)
            {
                var part = parts[p];

                if (Interpreter.ConversionDictionary.ContainsKey(part))
                {
                    roman += Interpreter.ConversionDictionary[part];
                }
                else
                {
                    lastRoman = p;
                    break;
                }
            }

            parts = parts.Skip(lastRoman).ToArray();

            if (parts.Any())
            {
                var thingName = String.Join(" ", parts);

                if (Interpreter.ThingValueDictionary.ContainsKey(thingName))
                {
                    thingValue *= Interpreter.ThingValueDictionary[thingName];
                }
                else
                {
                    var message = String.Format(Messages.UnknownAlienNumberOrThing, thingName);
                    Interpreter.AddError(message, Order);
                    return;
                }
            }

            var arabic          = RomanConversor.Convert(roman);
            var thingToBeValued = GetThing();

            var finalValue = getFinalValue(arabic, thingValue, thingToBeValued);

            if (finalValue.HasValue)
            {
                var message = String.Format(rightAnswer, value, finalValue, thingToBeValued);
                Interpreter.AddInfo(message, Order);
            }
            else
            {
                var message = String.Format(Messages.UnknownRomanNumber, roman);
                Interpreter.AddError(message, Order);
            }
        }