示例#1
0
        private static Rowboat CreateRowboat()
        {
            string  identification = RandomID("R-");
            int     weight         = random.Next(100, 300);
            int     maxSpeed       = random.Next(0, 3);
            int     maxPassengers  = random.Next(1, 6);
            Rowboat boat           = new Rowboat(identification, weight, maxSpeed, maxPassengers);

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