예제 #1
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 < DockTwo.Length; i += 2)
                    {
                        if (DockTwo[i] == null)
                        {
                            avaliableSpace += 2;

                            if (avaliableSpace == s.Slots)
                            {
                                Array.Fill(DockTwo, s, i + 2 - s.Slots, s.Slots);
                                Boats.Add(s);
                                s.Docked = true;

                                break;
                            }
                        }
                        else
                        {
                            avaliableSpace = 0;
                        }
                    }
                    avaliableSpace = 0;
                    if (s.Docked == false)
                    {
                        for (int i = 0; i < DockOne.Length; i += 2)
                        {
                            if (DockOne[i] == null)
                            {
                                avaliableSpace += 2;
                                if (avaliableSpace == s.Slots)
                                {
                                    Array.Fill(DockOne, s, i + 2 - s.Slots, 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 < DockOne.Length; i++)
                    {
                        if (DockOne[i] == null)
                        {
                            Array.Fill(DockOne, r, i, r.Slots);
                            Boats.Add(r);
                            r.Docked = true;
                            break;
                        }
                        else
                        {
                            avaliableSpace = 0;
                        }
                    }
                    avaliableSpace = 0;
                    if (r.Docked == false)
                    {
                        for (int i = 0; i < DockTwo.Length; i++)
                        {
                            if (DockTwo[i] == null)
                            {
                                Array.Fill(DockTwo, 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 < DockOne.Length; i += 2)
                    {
                        if (DockOne[i] == null)
                        {
                            avaliableSpace += 2;
                            if (avaliableSpace > p.Slots)
                            {
                                Array.Fill(DockOne, p, i - p.Slots, p.Slots);
                                Boats.Add(p);
                                p.Docked = true;
                                break;
                            }
                        }
                        else
                        {
                            avaliableSpace = 0;
                        }
                    }
                    avaliableSpace = 0;
                    if (p.Docked == false)
                    {
                        for (int i = 0; i < DockTwo.Length; i += 2)
                        {
                            if (DockTwo[i] == null)
                            {
                                avaliableSpace += 2;
                                if (avaliableSpace > p.Slots)
                                {
                                    Array.Fill(DockTwo, p, i - p.Slots, 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 < DockOne.Length; i += 2)
                    {
                        if (DockOne[i] == null)
                        {
                            avaliableSpace += 2;
                            if (avaliableSpace == k.Slots)
                            {
                                Array.Fill(DockOne, k, i + 2 - k.Slots, k.Slots);
                                Boats.Add(k);
                                k.Docked = true;
                                break;
                            }
                        }
                        else
                        {
                            avaliableSpace = 0;
                        }
                    }
                    if (k.Docked == false)
                    {
                        avaliableSpace = 0;
                        for (int i = 0; i < DockTwo.Length; i += 2)
                        {
                            if (DockTwo[i] == null)
                            {
                                avaliableSpace += 2;
                                if (avaliableSpace == k.Slots)
                                {
                                    Array.Fill(DockTwo, k, i + 2 - k.Slots, 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 = DockTwo.Length - 1; i > 0; i -= 2)
                    {
                        if (DockTwo[i] == null)
                        {
                            avaliableSpace += 2;
                            if (avaliableSpace == c.Slots)
                            {
                                Array.Fill(DockTwo, c, i - 2 + 1, c.Slots);
                                Boats.Add(c);
                                c.Docked = true;

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

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

                    break;
                }
            }
        }
예제 #2
0
        public void ReadDockData()
        {
            string data = File.ReadAllText(DataPath);

            if (data == "")
            {
                //empty harbour
            }
            else
            {
                string[] dockSplit  = data.Split('_');
                string[] dockOne    = dockSplit[0].Split('\n', StringSplitOptions.RemoveEmptyEntries);
                string[] removeShit = dockSplit[1].Split('\n', StringSplitOptions.RemoveEmptyEntries);
                string[] dockTwo    = removeShit.Skip(1)
                                      .ToArray();

                foreach (var item in dockOne)
                {
                    if (item == dockOne[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(DockOne, 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(DockOne, sail, Counter, sail.Slots);
                            Boats.Add(sail);
                        }
                        if (boats[0].ToLower() == "rowingboat" && !Array.Exists(DockOne, 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(DockOne, row, Counter, row.Slots);
                            Boats.Add(row);
                        }
                        if (boats[0].ToLower() == "powerboat" && !Array.Exists(DockOne, 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(DockOne, power, Counter, power.Slots);
                            Boats.Add(power);
                        }
                        if (boats[0].ToLower() == "catamaran" && !Array.Exists(DockOne, 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(DockOne, catamaran, Counter, catamaran.Slots);
                            Boats.Add(catamaran);
                        }
                        if (boats[0].ToLower() == "cargoship" && !Array.Exists(DockOne, 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(DockOne, cargo, Counter, cargo.Slots);
                            Boats.Add(cargo);
                        }

                        Counter++;
                    }
                }
                Counter = 0;
                foreach (var item in dockTwo)
                {
                    string[] boats = item.Split(',');

                    if (boats[0].ToLower() == "sailboat" && !Array.Exists(DockTwo, 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(DockTwo, sail, Counter, sail.Slots);
                        Boats.Add(sail);
                    }
                    if (boats[0].ToLower() == "rowingboat" && !Array.Exists(DockTwo, 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(DockTwo, row, Counter, row.Slots);
                        Boats.Add(row);
                    }
                    if (boats[0].ToLower() == "powerboat" && !Array.Exists(DockTwo, 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(DockTwo, power, Counter, power.Slots);
                        Boats.Add(power);
                    }
                    if (boats[0].ToLower() == "catamaran" && !Array.Exists(DockTwo, 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(DockTwo, catamaran, Counter, catamaran.Slots);
                        Boats.Add(catamaran);
                    }
                    if (boats[0].ToLower() == "cargoship" && !Array.Exists(DockTwo, 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(DockTwo, cargo, Counter, cargo.Slots);
                        Boats.Add(cargo);
                    }

                    Counter++;
                }
            }
            Counter = 0;
        }