示例#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 WriteOutHarbour()
        {
            int number = 1;

            for (int i = 0; i < x; i++)
            {
                Console.Write("|");
                if (number < 10)
                {
                    Console.Write($" {number}");
                }
                else
                {
                    Console.Write(number);
                }
                number++;
            }
            Console.WriteLine("|");

            Console.Write("|");
            for (int i = 0; i < x; i++)
            {
                if (harbour[i] is RowingBoat)
                {
                    Console.Write($"{harbour[i].TokenSign} |");
                }
                else if (harbour[i] is MotorBoat)
                {
                    Console.Write($"{harbour[i].TokenSign} |");
                }
                else if (harbour[i] is SailingBoat)
                {
                    Console.Write($"{harbour[i].TokenSign} |> |");
                    i++;
                }
                else if (harbour[i] is Catamaran)
                {
                    Console.Write($"{harbour[i].TokenSign} |- |> |");
                    i += 2;
                }
                else if (harbour[i] is CargoShip)
                {
                    Console.Write($"{harbour[i].TokenSign} |- |- |> |");
                    i += 3;
                }
                else
                {
                    Console.Write($"{harbour[i].TokenSign} |");
                }
            }
            Console.WriteLine();
            Console.Write("|");
            for (int i = 0; i < x; i++)
            {
                if (secondaryHarbour[i] is RowingBoat)
                {
                    Console.Write($"{secondaryHarbour[i].TokenSign}");
                }
                else
                {
                    Console.Write($"{secondaryHarbour[i].TokenSign}");
                }
                Console.Write(" |");
            }
            Console.WriteLine($"\n\nPasserade dagar: {daysPassed}\n");
            Console.Write($"Antal båtar i hamn: {NumberOfBoats('R') + NumberOfBoats('M') + NumberOfBoats('S') + NumberOfBoats('K') + NumberOfBoats('L')}" +
                          $"\t|Avvisade båtar: {Harbour.rejectedBoats}" +
                          $"\n\t\t\t|\nRoddbåtar:   {NumberOfBoats('R')}\t\t|Total vikt i hamnen: \t{GameAndMethods.WeightCheck()} kg" +
                          $"\nMotorbåtar:  {NumberOfBoats('M')}\t\t|Medeltal toppfart: \t{GameAndMethods.KnotToKMH(GameAndMethods.AvarageTopSpeed())} km/h" +
                          $"\nSegelbåtar:  {NumberOfBoats('S')}\t\t|Antal lediga platser: \t{EmptySlots()}, plus {EmptyRowBoatSlot()} extra roddbåtsplats" +
                          $"\nKatamaraner: {NumberOfBoats('K')}\t\t|" +
                          $"\nLastfartyg:  {NumberOfBoats('L')}\t\t|\n");
            Console.WriteLine($"\nPlats\tBåttyp\t\tID-nr\tVikt/KG\tMaxhastighet\tÖvrigt\t\t|");
            Console.WriteLine("-------------------------------------------------------------------------");
            int listNumber = 1;

            foreach (var item in harbour)
            {
                if (harbour[listNumber - 1] is RowingBoat)
                {
                    Console.WriteLine($"{listNumber}\t{item.Type}\t{item.IdentityNumber}\t{item.Weight}\t{GameAndMethods.KnotToKMH(item.TopSpeed)} km/h\t{item.SpecialProperty} passagerare\t|");
                }
                if (secondaryHarbour[listNumber - 1] is RowingBoat)
                {
                    RowingBoat extraRowingBoat = (RowingBoat)secondaryHarbour[listNumber - 1];
                    Console.WriteLine($"{listNumber}\t{extraRowingBoat.Type}\t{extraRowingBoat.IdentityNumber}\t{extraRowingBoat.Weight}\t{GameAndMethods.KnotToKMH(extraRowingBoat.TopSpeed)} km/h\t{extraRowingBoat.SpecialProperty} passagerare\t|");
                }
                if (harbour[listNumber - 1] is MotorBoat)
                {
                    Console.WriteLine($"{listNumber}\t{item.Type}\t{item.IdentityNumber}\t{item.Weight}\t{GameAndMethods.KnotToKMH(item.TopSpeed)} km/h  \t{item.SpecialProperty} hk\t\t|");
                }
                if (harbour[listNumber - 1] is SailingBoat)
                {
                    Console.WriteLine($"{listNumber}-{listNumber + 1}\t{item.Type}\t{item.IdentityNumber}\t{item.Weight}\t{GameAndMethods.KnotToKMH(item.TopSpeed)} km/h\t{GameAndMethods.FeetToMetres(item.SpecialProperty)} meter lång\t|");
                    harbour[listNumber].FreeSlot = false;
                }
                if (harbour[listNumber - 1] is Catamaran)
                {
                    Console.WriteLine($"{listNumber}-{listNumber + 2}\t{item.Type}\t{item.IdentityNumber}\t{item.Weight}\t{GameAndMethods.KnotToKMH(item.TopSpeed)} km/h\t{item.SpecialProperty} bäddplatser\t|");
                    harbour[listNumber].FreeSlot     = false;
                    harbour[listNumber + 1].FreeSlot = false;
                }
                if (harbour[listNumber - 1] is CargoShip)
                {
                    Console.WriteLine($"{listNumber}-{listNumber + 3}\t{item.Type}\t{item.IdentityNumber}\t{item.Weight}\t{GameAndMethods.KnotToKMH(item.TopSpeed)} km/h\t{item.SpecialProperty} containrar\t|");
                    harbour[listNumber].FreeSlot     = false;
                    harbour[listNumber + 1].FreeSlot = false;
                    harbour[listNumber + 2].FreeSlot = false;
                }
                listNumber++;
            }
            Console.WriteLine("-------------------------------------------------------------------------");
            Console.Write("\n[ENTER]:Nästa dag\n[1]:\tStarta om\n[2]:\tAvsluta\nVälj: ");
        }
示例#3
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();
            }
        }