예제 #1
0
파일: Boat.cs 프로젝트: arkestal/Harbour
        public static void GeneratingNewBoats()
        {
            for (int i = 0; i < vesselsPerDay; i++)
            {
                approachingVessel = random.Next(1, 5 + 1);
                switch (approachingVessel)
                {
                case 1:
                    Boat rowingBoat = new RowingBoat($"Roddbåt\t", $"R-{GetID()}", GetValue(100, 300), GetValue(0, 3), tokenSign: "R", GetValue(1, 6), 1);
                    Harbour.PlaceVessel(1, rowingBoat);
                    break;

                case 2:
                    Boat motorBoat = new MotorBoat($"Motorbåt", $"M-{GetID()}", GetValue(200, 3000), GetValue(0, 60), tokenSign: "M", GetValue(10, 1000), 3);
                    Harbour.PlaceVessel(1, motorBoat);
                    break;

                case 3:
                    Boat sailingBoat = new SailingBoat($"Segelbåt", $"S-{GetID()}", GetValue(800, 6000), GetValue(0, 12), tokenSign: "S", GetValue(10, 60), 4);
                    Harbour.PlaceVessel(2, sailingBoat);
                    break;

                case 4:
                    Boat catamaran = new Catamaran($"Katamaran", $"K-{GetID()}", GetValue(1200, 8000), GetValue(0, 12), tokenSign: "K", GetValue(1, 4), 3);
                    Harbour.PlaceVessel(3, catamaran);
                    break;

                case 5:
                    Boat cargoShip = new CargoShip($"Lastfartyg", $"L-{GetID()}", GetValue(3000, 20000), GetValue(0, 20), tokenSign: "L", GetValue(0, 500), 6);
                    Harbour.PlaceVessel(4, cargoShip);
                    break;
                }
            }
        }
예제 #2
0
        public static void LoadData()
        {
            try
            {
                string dataFiles = File.ReadAllText("savedData.txt");
                if (new FileInfo("savedData.txt").Length == 0)
                {
                    Console.Clear();
                    Console.WriteLine("Vi börjar från dag 0, då det inte fanns något sparat!");
                    Thread.Sleep(2000);
                    Console.Clear();
                }
                else
                {
                    string[] splitHarbour = dataFiles.Split('$');
                    string[] harbour1     = splitHarbour[0].Split('\n', StringSplitOptions.RemoveEmptyEntries);
                    string[] harbour2     = splitHarbour[1].Split('\n', StringSplitOptions.RemoveEmptyEntries);
                    int      counter      = 0;
                    foreach (var item in harbour1)
                    {
                        if (item == harbour1[0])
                        {
                            string[] firstRow = item.Split(';');
                            daysPassed            = int.Parse(firstRow[0]);
                            Harbour.rejectedBoats = int.Parse(firstRow[1]);
                        }
                        else
                        {
                            string[] boatValue = item.Split(';');
                            switch (boatValue[0])
                            {
                            case "Roddbåt\t":
                                Boat rowingBoat = new RowingBoat(boatValue[0], boatValue[1], int.Parse(boatValue[2]), int.Parse(boatValue[3]), boatValue[4], int.Parse(boatValue[5]), int.Parse(boatValue[6]));
                                harbour[counter] = rowingBoat;
                                break;

                            case "Motorbåt":
                                Boat motorBoat = new MotorBoat(boatValue[0], boatValue[1], int.Parse(boatValue[2]), int.Parse(boatValue[3]), boatValue[4], int.Parse(boatValue[5]), int.Parse(boatValue[6]));
                                harbour[counter] = motorBoat;
                                break;

                            case "Segelbåt":
                                Boat sailingBoat = new SailingBoat(boatValue[0], boatValue[1], int.Parse(boatValue[2]), int.Parse(boatValue[3]), boatValue[4], int.Parse(boatValue[5]), int.Parse(boatValue[6]));
                                harbour[counter] = sailingBoat;
                                break;

                            case "Katamaran":
                                Boat catamaran = new Catamaran(boatValue[0], boatValue[1], int.Parse(boatValue[2]), int.Parse(boatValue[3]), boatValue[4], int.Parse(boatValue[5]), int.Parse(boatValue[6]));
                                harbour[counter] = catamaran;
                                break;

                            case "Lastfartyg":
                                Boat cargoShip = new CargoShip(boatValue[0], boatValue[1], int.Parse(boatValue[2]), int.Parse(boatValue[3]), boatValue[4], int.Parse(boatValue[5]), int.Parse(boatValue[6]));
                                harbour[counter] = cargoShip;
                                break;

                            default:
                                Boat dummy = new DummyBoat(boatValue[0], boatValue[1], int.Parse(boatValue[2]), int.Parse(boatValue[3]), boatValue[4], int.Parse(boatValue[5]), bool.Parse(boatValue[6]));
                                harbour[counter] = dummy;
                                break;
                            }
                            counter++;
                        }
                    }
                    counter = 0;
                    foreach (var item in harbour2)
                    {
                        string[] boatValue = item.Split(';');
                        if (boatValue[0] == "\r")
                        {
                        }
                        else
                        {
                            switch (boatValue[0])
                            {
                            case "Roddbåt\t":
                                Boat rowingBoat = new RowingBoat(boatValue[0], boatValue[1], int.Parse(boatValue[2]), int.Parse(boatValue[3]), boatValue[4], int.Parse(boatValue[5]), int.Parse(boatValue[6]));
                                secondaryHarbour[counter] = rowingBoat;
                                break;

                            default:
                                Boat dummy = new DummyBoat(boatValue[0], boatValue[1], int.Parse(boatValue[2]), int.Parse(boatValue[3]), boatValue[4], int.Parse(boatValue[5]), bool.Parse(boatValue[6]));
                                secondaryHarbour[counter] = dummy;
                                break;
                            }
                            counter++;
                        }
                    }
                    Console.Clear();
                    Console.WriteLine($"Laddar in sparad fil och börjar från dag {daysPassed}.");
                    Thread.Sleep(2000);
                    Console.Clear();
                }
            }
            catch (Exception)
            {
                Console.Clear();
                Console.WriteLine("Vi börjar från dag 0, då det inte fanns något sparat!");
                Thread.Sleep(2000);
                Console.Clear();
            }
        }