Esempio n. 1
0
        public void ReadDockData()
        {
            if (File.Exists(DataPath))
            {
                Data = File.ReadAllText(DataPath);
            }
            else
            {
                File.Create(DataPath);
            }

            if (Data == "")
            {
                Console.WriteLine("Harbour hasn't been opened yet...");
            }
            else
            {
                string[] split = Data.Split('\n');

                foreach (var item in split)
                {
                    if (item == split[0])
                    {
                        string[] counters = item.Split('-');
                        Day           = int.Parse(counters[0]);
                        RejectedBoats = int.Parse(counters[1]);
                        AddedBoats    = int.Parse(counters[2]);
                    }
                    else
                    {
                        string[] boats = item.Split(',');

                        if (boats[0].ToLower() == "sailboat" && !Array.Exists(Docks, b => b != null && b.ID == boats[1]))
                        {
                            SailBoat sail = new SailBoat()
                            {
                                ID           = boats[1],
                                Weight       = int.Parse(boats[2]),
                                MaxSpeed     = int.Parse(boats[3]),
                                LengthInFeet = int.Parse(boats[4]),
                                DaysDocked   = int.Parse(boats[5])
                            };
                            sail.Docked = true;
                            Array.Fill(Docks, sail, Counter, sail.Slots);
                            Boats.Add(sail);
                        }
                        if (boats[0].ToLower() == "rowingboat" && !Array.Exists(Docks, b => b != null && b.ID == boats[1]))
                        {
                            RowingBoat row = new RowingBoat()
                            {
                                ID           = boats[1],
                                Weight       = int.Parse(boats[2]),
                                MaxSpeed     = int.Parse(boats[3]),
                                MaxPassenger = int.Parse(boats[4]),
                                DaysDocked   = int.Parse(boats[5])
                            };
                            row.Docked = true;

                            Array.Fill(Docks, row, Counter, row.Slots);
                            Boats.Add(row);
                        }
                        if (boats[0].ToLower() == "powerboat" && !Array.Exists(Docks, b => b != null && b.ID == boats[1]))
                        {
                            PowerBoat power = new PowerBoat()
                            {
                                ID                 = boats[1],
                                Weight             = int.Parse(boats[2]),
                                MaxSpeed           = int.Parse(boats[3]),
                                NumberOfHorsepower = int.Parse(boats[4]),
                                DaysDocked         = int.Parse(boats[5])
                            };
                            power.Docked = true;

                            Array.Fill(Docks, power, Counter, power.Slots);
                            Boats.Add(power);
                        }
                        if (boats[0].ToLower() == "catamaran" && !Array.Exists(Docks, b => b != null && b.ID == boats[1]))
                        {
                            Catamaran catamaran = new Catamaran()
                            {
                                ID         = boats[1],
                                Weight     = int.Parse(boats[2]),
                                MaxSpeed   = int.Parse(boats[3]),
                                Beds       = int.Parse(boats[4]),
                                DaysDocked = int.Parse(boats[5])
                            };
                            catamaran.Docked = true;

                            Array.Fill(Docks, catamaran, Counter, catamaran.Slots);
                            Boats.Add(catamaran);
                        }
                        if (boats[0].ToLower() == "cargoship" && !Array.Exists(Docks, b => b != null && b.ID == boats[1]))
                        {
                            CargoShip cargo = new CargoShip()
                            {
                                ID              = boats[1],
                                Weight          = int.Parse(boats[2]),
                                MaxSpeed        = int.Parse(boats[3]),
                                CargoContainers = int.Parse(boats[4]),
                                DaysDocked      = int.Parse(boats[5])
                            };
                            cargo.Docked = true;

                            Array.Fill(Docks, cargo, Counter, cargo.Slots);
                            Boats.Add(cargo);
                        }

                        Counter++;
                    }
                }
                Counter = 0;
            }
        }
Esempio n. 2
0
        public void GenerateBoat(int amount)
        {
            for (int boat = 0; boat < amount; boat++)
            {
                int avaliableSpace = 0;

                switch (Rand.Next(1, 5 + 1))
                {
                case 1:
                    SailBoat s = new SailBoat();


                    for (int i = 0; i < Docks.Length; i += 2)
                    {
                        if (Docks[i] == null)
                        {
                            avaliableSpace += 2;
                            if (avaliableSpace > s.Slots)
                            {
                                TempInterval = i - s.Slots;
                                Array.Fill(Docks, s, TempInterval, s.Slots);
                                Boats.Add(s);
                                s.Docked = true;

                                break;
                            }
                        }
                        else
                        {
                            avaliableSpace = 0;
                        }
                    }
                    _ = Boats.Contains(s) ? AddedBoats++ : RejectedBoats++;


                    break;

                case 2:
                    RowingBoat r = new RowingBoat();


                    for (int i = 0; i < Docks.Length; i++)
                    {
                        if (Docks[i] == null)
                        {
                            Array.Fill(Docks, r, i, r.Slots);
                            Boats.Add(r);
                            r.Docked = true;
                            break;
                        }
                        else
                        {
                            avaliableSpace = 0;
                        }
                    }
                    _ = Boats.Contains(r) ? AddedBoats++ : RejectedBoats++;


                    break;

                case 3:
                    PowerBoat p = new PowerBoat();


                    for (int i = 0; i < Docks.Length; i += 2)
                    {
                        if (Docks[i] == null)
                        {
                            avaliableSpace += 2;
                            if (avaliableSpace > p.Slots)
                            {
                                TempInterval = i - p.Slots;
                                Array.Fill(Docks, p, TempInterval, p.Slots);
                                Boats.Add(p);
                                p.Docked = true;
                                break;
                            }
                        }
                        else
                        {
                            avaliableSpace = 0;
                        }
                    }
                    _ = Boats.Contains(p) ? AddedBoats++ : RejectedBoats++;


                    break;

                case 4:
                    Catamaran k = new Catamaran();


                    for (int i = 0; i < Docks.Length; i += 2)
                    {
                        if (Docks[i] == null)
                        {
                            avaliableSpace += 2;
                            if (avaliableSpace > k.Slots)
                            {
                                TempInterval = i - k.Slots;
                                Array.Fill(Docks, k, TempInterval, k.Slots);
                                Boats.Add(k);
                                k.Docked = true;
                                break;
                            }
                        }
                        else
                        {
                            avaliableSpace = 0;
                        }
                    }
                    _ = Boats.Contains(k) ? AddedBoats++ : RejectedBoats++;


                    break;

                case 5:
                    CargoShip c = new CargoShip();

                    for (int i = Docks.Length - 1; i > 0; i -= 2)
                    {
                        if (Docks[i] == null)
                        {
                            avaliableSpace += 2;
                            if (avaliableSpace > c.Slots)
                            {
                                TempInterval = i + 1;
                                Array.Fill(Docks, c, TempInterval, c.Slots);
                                Boats.Add(c);
                                c.Docked = true;

                                break;
                            }
                        }
                        else
                        {
                            avaliableSpace = 0;
                        }
                    }
                    _ = Boats.Contains(c) ? AddedBoats++ : RejectedBoats++;

                    break;
                }
            }
        }