Пример #1
0
        static public void CreateRandomBoats(int num)
        {
            List <Boat> bl = new List <Boat>();

            for (int i = 0; i < num; i++)
            {
                int      bn = Utils.Rnd.Next(1, 5 + 1);
                BoatType bt = (BoatType)bn;
                switch (bt)
                {
                case BoatType.RowingBoat:
                    var rb = new RowingBoat();
                    bl.Add(rb);
                    break;

                case BoatType.PowerBoat:
                    var pb = new PowerBoat();
                    bl.Add(pb);

                    break;

                case BoatType.SailBoat:
                    var sb = new SailBoat();
                    bl.Add(sb);

                    break;

                case BoatType.Catamaran:
                    var ca = new Catamaran();
                    bl.Add(ca);

                    break;

                case BoatType.CargoBoat:
                    var cb = new CargoBoat();
                    bl.Add(cb);

                    break;

                default:
                    break;
                }
            }
            foreach (var boat in bl)
            {
                boat.Arrive();
            }
        }
Пример #2
0
        static public bool LoadBoats()
        {
            if (!File.Exists(dataFileName))
            {
                return(false);
            }
            int count = 0;
            var lines = File.ReadAllLines(dataFileName);

            foreach (string line in lines)
            {
                if (string.IsNullOrEmpty(line))
                {
                    continue;
                }
                var      chunks = line.Split(';');
                BoatType t      = (BoatType)int.Parse(chunks[0]);
                switch (t)
                {
                case BoatType.RowingBoat:
                    var rb = new RowingBoat(chunks[2], int.Parse(chunks[3]), int.Parse(chunks[4]), int.Parse(chunks[5]), int.Parse(chunks[6]));
                    rb.WharfNumber = int.Parse(chunks[1]);
                    RegisterBoat(rb, true);
                    count++;
                    break;

                case BoatType.PowerBoat:
                    var pb = new PowerBoat(chunks[2], int.Parse(chunks[3]), int.Parse(chunks[4]), int.Parse(chunks[5]), int.Parse(chunks[6]));
                    pb.WharfNumber = int.Parse(chunks[1]);
                    RegisterBoat(pb, true);
                    count++;

                    break;

                case BoatType.SailBoat:
                    var sb = new SailBoat(chunks[2], int.Parse(chunks[3]), int.Parse(chunks[4]), int.Parse(chunks[5]), int.Parse(chunks[6]));
                    sb.WharfNumber = int.Parse(chunks[1]);
                    RegisterBoat(sb, true);
                    count++;

                    break;

                case BoatType.Catamaran:
                    var cb = new Catamaran(chunks[2], int.Parse(chunks[3]), int.Parse(chunks[4]), int.Parse(chunks[5]), int.Parse(chunks[6]));
                    cb.WharfNumber = int.Parse(chunks[1]);
                    RegisterBoat(cb, true);
                    count++;

                    break;

                case BoatType.CargoBoat:
                    var cab = new CargoBoat(chunks[2], int.Parse(chunks[3]), int.Parse(chunks[4]), int.Parse(chunks[5]), int.Parse(chunks[6]));
                    cab.WharfNumber = int.Parse(chunks[1]);
                    RegisterBoat(cab, true);
                    count++;

                    break;

                default:
                    break;
                }
            }
            if (count == 0)
            {
                return(false);
            }
            LogEvent($"Loaded {count} boats from file");
            return(true);
        }