Ejemplo n.º 1
0
        private static Cargoship CreateCargoship()
        {
            string    identification = RandomID("C-");
            int       weight         = random.Next(3000, 20000);
            int       maxSpeed       = random.Next(0, 20);
            int       containers     = random.Next(0, 500);
            Cargoship boat           = new Cargoship(identification, weight, maxSpeed, containers);

            return(boat);
        }
Ejemplo n.º 2
0
        private static bool ReadFromFile()
        {
            string filePath = "Hamnen.txt";

            if (File.Exists(filePath))
            {
                List <Boat> boat = new List <Boat>();

                List <string> lines = File.ReadAllLines(filePath).ToList();
                foreach (string line in lines)
                {
                    string[] entries = line.Split(',');

                    if (entries[2] == "Rowboat")
                    {
                        Boat b = new Rowboat(entries[3], int.Parse(entries[4]), int.Parse(entries[5]), int.Parse(entries[6]), int.Parse(entries[7]));
                        harbor[int.Parse(entries[0]), int.Parse(entries[1])] = b;
                    }
                    else if (entries[2] == "Motorboat")
                    {
                        Boat b = new Motorboat(entries[3], int.Parse(entries[4]), int.Parse(entries[5]), int.Parse(entries[6]), int.Parse(entries[7]));
                        harbor[int.Parse(entries[0]), int.Parse(entries[1])] = b;
                    }
                    else if (entries[2] == "Sailboat")
                    {
                        Boat b = new Sailboat(entries[3], int.Parse(entries[4]), int.Parse(entries[5]), int.Parse(entries[6]), int.Parse(entries[7]));
                        harbor[int.Parse(entries[0]), int.Parse(entries[1])] = b;
                    }
                    else if (entries[2] == "Cargoship")
                    {
                        Boat b = new Cargoship(entries[3], int.Parse(entries[4]), int.Parse(entries[5]), int.Parse(entries[6]), int.Parse(entries[7]));
                        harbor[int.Parse(entries[0]), int.Parse(entries[1])] = b;
                    }
                }
                return(true);
            }
            return(false);
        }