Exemplo n.º 1
0
        List <Boat> GenerateBoats(int numBoats)
        {
            Random      random   = new Random();
            List <Boat> boatList = new List <Boat>();

            for (int i = 0; i < numBoats; i++)
            {
                Boat boat = new Boat();
                int  rnd  = random.Next(1, 6);
                if (rnd == 1)
                {
                    boat = new RowBoat();
                }
                else if (rnd == 2)
                {
                    boat = new MotorBoat();
                }
                else if (rnd == 3)
                {
                    boat = new SailBoat();
                }
                else if (rnd == 4)
                {
                    boat = new CargoBoat();
                }
                else if (rnd == 5)
                {
                    boat = new CatamaranBoat();
                }

                boatList.Add(boat);
            }
            return(boatList);
        }
Exemplo n.º 2
0
        void LoadFromFile()
        {
            //Index:Name:Size:Weight:MaxSpeed:SpecialTrait:DockedDays

            try
            {
                string leftText = File.ReadAllText("LeftDock.txt");

                string[] textList = leftText.Split("\n");

                foreach (String text in textList)
                {
                    if (text == "")
                    {
                        break;
                    }
                    string[] boatInfo = text.Split(":");

                    int    index      = int.Parse(boatInfo[0]);
                    string name       = boatInfo[1];
                    double size       = double.Parse(boatInfo[2]);
                    int    weight     = int.Parse(boatInfo[3]);
                    int    maxSpeed   = int.Parse(boatInfo[4]);
                    int    special    = int.Parse(boatInfo[5]);
                    int    dockedDays = int.Parse(boatInfo[6]);

                    Boat boat = new Boat();

                    if (size == 0.5)
                    {
                        RowBoat rowBoat = new RowBoat();
                        rowBoat.Name         = name;
                        rowBoat.Weight       = weight;
                        rowBoat.MaxSpeed     = maxSpeed;
                        rowBoat.MaxPassenger = special;
                        rowBoat.DockedDays   = dockedDays;
                        boat = rowBoat;
                    }
                    else if (size == 1)
                    {
                        MotorBoat motorBoat = new MotorBoat();
                        motorBoat.Name       = name;
                        motorBoat.Weight     = weight;
                        motorBoat.MaxSpeed   = maxSpeed;
                        motorBoat.HorsePower = special;
                        motorBoat.DockedDays = dockedDays;
                        boat = motorBoat;
                    }
                    else if (size == 2)
                    {
                        SailBoat sailBoat = new SailBoat();
                        sailBoat.Name       = name;
                        sailBoat.Weight     = weight;
                        sailBoat.MaxSpeed   = maxSpeed;
                        sailBoat.Length     = special;
                        sailBoat.DockedDays = dockedDays;
                        boat = sailBoat;
                    }
                    else if (size == 3)
                    {
                        CatamaranBoat catBoat = new CatamaranBoat();
                        catBoat.Name       = name;
                        catBoat.Weight     = weight;
                        catBoat.MaxSpeed   = maxSpeed;
                        catBoat.Bedspaces  = special;
                        catBoat.DockedDays = dockedDays;
                        boat = catBoat;
                    }
                    else if (size == 4)
                    {
                        CargoBoat cargoBoat = new CargoBoat();
                        cargoBoat.Name       = name;
                        cargoBoat.Weight     = weight;
                        cargoBoat.MaxSpeed   = maxSpeed;
                        cargoBoat.Cargo      = special;
                        cargoBoat.DockedDays = dockedDays;
                        boat = cargoBoat;
                    }

                    UpdateLeftDockCheck(index, size);
                    LeftDockAdd(boat, index, size);
                    LeftDockList.Add(boat);
                }
            }
            catch (IOException e)
            {
                //File does not exist.
            }

            try
            {
                string rightText = File.ReadAllText("RightDock.txt");

                string[] textList = rightText.Split("\n");

                foreach (String text in textList)
                {
                    if (text == "")
                    {
                        break;
                    }
                    string[] boatInfo = text.Split(":");

                    int    index      = int.Parse(boatInfo[0]);
                    string name       = boatInfo[1];
                    double size       = double.Parse(boatInfo[2]);
                    int    weight     = int.Parse(boatInfo[3]);
                    int    maxSpeed   = int.Parse(boatInfo[4]);
                    int    special    = int.Parse(boatInfo[5]);
                    int    dockedDays = int.Parse(boatInfo[6]);

                    Boat boat = new Boat();

                    if (size == 0.5)
                    {
                        RowBoat rowBoat = new RowBoat();
                        rowBoat.Name         = name;
                        rowBoat.Weight       = weight;
                        rowBoat.MaxSpeed     = maxSpeed;
                        rowBoat.MaxPassenger = special;
                        rowBoat.DockedDays   = dockedDays;
                        boat = rowBoat;
                    }
                    else if (size == 1)
                    {
                        MotorBoat motorBoat = new MotorBoat();
                        motorBoat.Name       = name;
                        motorBoat.Weight     = weight;
                        motorBoat.MaxSpeed   = maxSpeed;
                        motorBoat.HorsePower = special;
                        motorBoat.DockedDays = dockedDays;
                        boat = motorBoat;
                    }
                    else if (size == 2)
                    {
                        SailBoat sailBoat = new SailBoat();
                        sailBoat.Name       = name;
                        sailBoat.Weight     = weight;
                        sailBoat.MaxSpeed   = maxSpeed;
                        sailBoat.Length     = special;
                        sailBoat.DockedDays = dockedDays;
                        boat = sailBoat;
                    }
                    else if (size == 3)
                    {
                        CatamaranBoat catBoat = new CatamaranBoat();
                        catBoat.Name       = name;
                        catBoat.Weight     = weight;
                        catBoat.MaxSpeed   = maxSpeed;
                        catBoat.Bedspaces  = special;
                        catBoat.DockedDays = dockedDays;
                        boat = catBoat;
                    }
                    else if (size == 4)
                    {
                        CargoBoat cargoBoat = new CargoBoat();
                        cargoBoat.Name       = name;
                        cargoBoat.Weight     = weight;
                        cargoBoat.MaxSpeed   = maxSpeed;
                        cargoBoat.Cargo      = special;
                        cargoBoat.DockedDays = dockedDays;
                        boat = cargoBoat;
                    }

                    UpdateRightDockCheck(index, size);
                    RightDockAdd(boat, index, size);
                    RightDockList.Add(boat);
                }
            }
            catch (IOException e)
            {
                //File does not exist.
            }
        }