Exemple #1
0
        public static bool Parse(string str, ref Vehicle res)
        {
            string[] stam  = { "|" };
            string[] split = str.Split(stam, StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < split.Length; i++)
            {
                split[i] = split[i].Trim();
            }
            long splitCount = split.LongCount();


            if (splitCount < 2 || splitCount > 4)
            {
                res = null;
                return(false);
            }

            if (splitCount == 4)
            {
                if (split[0] == "-1")
                {
                    try
                    {
                        int     rishuy = int.Parse(split[0]);
                        GazType gt     = ParseGazType(split[1]);
                        string  name   = split[2];
                        int     lenght = int.Parse(split[3]);
                        res = new Boat(gt, lenght, name, rishuy);
                        return(true);
                    }
                    catch (Exception)
                    {
                        res = null;
                        return(false);
                    }
                }
            }

            if (splitCount == 3)
            {
                try
                {
                    int          rishuy = int.Parse(split[0]);
                    GazType      gt     = ParseGazType(split[1]);
                    ConsoleColor cc     = (ConsoleColor)Enum.Parse(typeof(ConsoleColor), split[2]);
                    res = new MotorCycle(rishuy, gt, cc);
                    return(true);
                }
                catch (Exception)
                {
                    res = null;
                    return(false);
                }
            }

            if (splitCount == 2)
            {
                try
                {
                    int     rishuy = int.Parse(split[0]);
                    GazType gt     = ParseGazType(split[1]);
                    res = new Vehicle(rishuy, gt);
                    return(true);
                }
                catch (Exception)
                {
                    res = null;
                    return(false);
                }
            }


            return(true);
        }
Exemple #2
0
 public Boat(GazType _gaz_type, int _length, string _name, int _rishuy) : base(-1, _gaz_type)
 {
     length = _length;
     name   = _name;
 }
Exemple #3
0
 public Vehicle(int _rishuy, GazType _gaz_type)
 {
     rishuy   = _rishuy;
     gaz_type = _gaz_type;
 }
Exemple #4
0
 public MotorCycle(int _rishuy, GazType _gaz_type, ConsoleColor _color)
     : base(_rishuy, _gaz_type)
 {
     color = _color;
 }