Example #1
0
        //Assumption made that string input will always be in same format, comma seperated string
        public Monster CreateFromString(string input)
        {
            var arguments = input.Split(',');

            if (arguments.Length == 4)
            {
                var position = positionFactory.CreateFromString(arguments[1], arguments[2], arguments[3]);

                return(new Monster(position));
            }
            throw new ArgumentException("Input is not a valid argument");
        }
Example #2
0
        //Assumption made that string input will always be in same format, comma seperated string
        public Planet CreateFromString(string input)
        {
            var arguments = input.Split(',');

            if (arguments.Length == 6)
            {
                var valid = true;

                var    position = positionFactory.CreateFromString(arguments[1], arguments[2], arguments[3]);
                bool   isHabitable;
                double area;

                valid &= bool.TryParse(arguments[4], out isHabitable);
                valid &= double.TryParse(arguments[5], out area);
                if (valid)
                {
                    return(new Planet(position, isHabitable, area));
                }
            }
            throw new ArgumentException("Input is not a valid argument");
        }