Beispiel #1
0
        private static Motorboat CreateMotorboat()
        {
            string    identification = RandomID("M-");
            int       weight         = random.Next(200, 3000);
            int       maxSpeed       = random.Next(0, 60);
            int       horsePower     = random.Next(10, 1000);
            Motorboat boat           = new Motorboat(identification, weight, maxSpeed, horsePower);

            return(boat);
        }
Beispiel #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);
        }