示例#1
0
        public static void CreatesBoats()
        {
            CounterForDayInTheDockProp();

            // Switch-method for making boats.
            for (int i = 0; i < 5; i++)
            {
                switch (rnd.Next(1, 6))
                {
                case 1:     // Rowingboat
                    boatID = string.Empty;

                    boatID += (char)rnd.Next('A', 'Z');
                    boatID += (char)rnd.Next('A', 'Z');
                    boatID += (char)rnd.Next('A', 'Z');

                    int m = 0;
                    for (; m < boatArray.Length; m++)
                    {
                        if (boatArray[m] is RowingBoat && rowingBoatArray[m] == null)
                        {
                            rowingBoatArray[m] = new RowingBoat(rnd.Next(1, 6), $"R-{boatID}", rnd.Next(100, 301), rnd.Next(1, 4), "Rowing boat", "Max amount of pers:", 1, m);
                            dismissed          = false;
                            break;
                        }
                        else if (boatArray[m] == null)
                        {
                            boatArray[m] = new RowingBoat(rnd.Next(1, 6), $"R-{boatID}", rnd.Next(100, 301), rnd.Next(1, 4), "Rowing boat", "Max amount of pers:", 1, m);
                            dismissed    = false;
                            break;
                        }
                    }
                    if (dismissed)
                    {
                        rejectedBoats++;
                    }
                    dismissed = true;
                    break;

                case 2:     // Sailorboat
                    boatID  = string.Empty;
                    boatID += (char)rnd.Next('A', 'Z');
                    boatID += (char)rnd.Next('A', 'Z');
                    boatID += (char)rnd.Next('A', 'Z');

                    int l = 0;
                    for (; l < boatArray.Length; l++)
                    {
                        if (l < 62)
                        {
                            if (boatArray[l] == null && boatArray[l + 1] == null)
                            {
                                boatArray[l]     = new Sailboat(rnd.Next(10, 61), $"S-{boatID}", rnd.Next(800, 6001), rnd.Next(1, 13), "Sailboat", "Length:", 4, l);
                                boatArray[l + 1] = new Sailboat(0, $"S-{boatID}", 0, 0, "Sailboat", "Length:", 4, l + 1);

                                dismissed = false;
                                break;
                            }
                        }
                    }
                    if (dismissed)
                    {
                        rejectedBoats++;
                    }
                    dismissed = true;
                    break;

                case 3:     // Powerboat
                    boatID = string.Empty;

                    boatID += (char)rnd.Next('A', 'Z');
                    boatID += (char)rnd.Next('A', 'Z');
                    boatID += (char)rnd.Next('A', 'Z');

                    int j = 0;
                    for (; j < boatArray.Length; j++)
                    {
                        if (boatArray[j] == null)
                        {
                            boatArray[j] = new PowerBoat(rnd.Next(10, 1000), $"P-{boatID}", rnd.Next(200, 3001), rnd.Next(1, 61), "Power Boat", "Horsepowers:", 3, j);
                            dismissed    = false;
                            break;
                        }
                    }
                    if (dismissed)
                    {
                        rejectedBoats++;
                    }
                    dismissed = true;
                    break;

                case 4:     // Cargoship
                    boatID = string.Empty;

                    boatID += (char)rnd.Next('A', 'Z');
                    boatID += (char)rnd.Next('A', 'Z');
                    boatID += (char)rnd.Next('A', 'Z');

                    int k = 0;
                    for (; k < boatArray.Length; k++)
                    {
                        if (k < 61)
                        {
                            if (boatArray[k] == null && boatArray[k + 1] == null && boatArray[k + 2] == null && boatArray[k + 3] == null)
                            {
                                boatArray[k]     = new CargoShip(rnd.Next(0, 501), $"C-{boatID}", rnd.Next(3000, 20001), rnd.Next(1, 21), "Cargo Ship", "Containers:", 6, k);
                                boatArray[k + 1] = new CargoShip(0, $"C-{boatID}", 0, 0, "Cargo Ship", "Containers:", 6, k + 1);
                                boatArray[k + 2] = new CargoShip(0, $"C-{boatID}", 0, 0, "Cargo Ship", "Containers:", 6, k + 2);
                                boatArray[k + 3] = new CargoShip(0, $"C-{boatID}", 0, 0, "Cargo Ship", "Containers:", 6, k + 3);
                                dismissed        = false;
                                break;
                            }
                        }
                    }
                    if (dismissed)
                    {
                        rejectedBoats++;
                    }
                    dismissed = true;
                    break;

                case 5:     // Catamaran
                    boatID = string.Empty;

                    boatID += (char)rnd.Next('A', 'Z');
                    boatID += (char)rnd.Next('A', 'Z');
                    boatID += (char)rnd.Next('A', 'Z');

                    int x = 0;
                    for (; x < boatArray.Length; x++)
                    {
                        if (x < 61)
                        {
                            if (boatArray[x] == null && boatArray[x + 1] == null && boatArray[x + 2] == null && boatArray[x + 3] == null)
                            {
                                boatArray[x]     = new Catamaran(rnd.Next(1, 5), $"K-{boatID}", rnd.Next(1200, 8001), rnd.Next(1, 13), "Catamaran", "Amount of beds:", 3, x);
                                boatArray[x + 1] = new Catamaran(0, $"K-{boatID}", 0, 0, "Catamaran", "Amount of beds:", 3, x + 1);
                                boatArray[x + 2] = new Catamaran(0, $"K-{boatID}", 0, 0, "Catamaran", "Amount of beds:", 3, x + 2);
                                dismissed        = false;
                                break;
                            }
                        }
                    }
                    if (dismissed)
                    {
                        rejectedBoats++;
                    }
                    dismissed = true;
                    break;
                }
            }
        }
示例#2
0
        public static void ReadFileMemory()
        {
            foreach (var stat in File.ReadAllLines("Statistics.txt", Encoding.UTF8))
            {
                string[] statistics = stat.Split(";");
                days          = int.Parse(statistics[0]);
                rejectedBoats = int.Parse(statistics[1]);
            }

            for (int z1 = 0; z1 < boatArray.Length; z1++)
            {
                foreach (string item in File.ReadAllLines("TheDock.txt", Encoding.UTF8))
                {
                    string[] boatData = item.Split(";");

                    for (int z = 0; z < boatData.Length; z++)
                    {
                        switch (boatData[1].First())
                        {
                        case 'R':
                            RowingBoat r = new RowingBoat(int.Parse(boatData[0]), boatData[1], int.Parse(boatData[2]), int.Parse(boatData[3]),
                                                          boatData[4], boatData[5], int.Parse(boatData[6]), int.Parse(boatData[7]));
                            addBoat(r, boatArray);
                            break;

                        case 'P':
                            PowerBoat p = new PowerBoat(int.Parse(boatData[0]), boatData[1], int.Parse(boatData[2]), int.Parse(boatData[3]),
                                                        boatData[4], boatData[5], int.Parse(boatData[6]), int.Parse(boatData[7]));
                            addBoat(p, boatArray);
                            break;

                        case 'S':
                            Sailboat s = new Sailboat(int.Parse(boatData[0]), boatData[1], int.Parse(boatData[2]), int.Parse(boatData[3]),
                                                      boatData[4], boatData[5], int.Parse(boatData[6]), int.Parse(boatData[7]));
                            addBoat(s, boatArray);
                            break;

                        case 'C':
                            CargoShip c = new CargoShip(int.Parse(boatData[0]), boatData[1], int.Parse(boatData[2]), int.Parse(boatData[3]),
                                                        boatData[4], boatData[5], int.Parse(boatData[6]), int.Parse(boatData[7]));
                            addBoat(c, boatArray);
                            break;

                        case 'K':
                            CargoShip k = new CargoShip(int.Parse(boatData[0]), boatData[1], int.Parse(boatData[2]), int.Parse(boatData[3]),
                                                        boatData[4], boatData[5], int.Parse(boatData[6]), int.Parse(boatData[7]));
                            addBoat(k, boatArray);
                            break;

                        default:
                            break;
                        }
                    }
                }
            }

            for (int z3 = 0; z3 < rowingBoatArray.Length; z3++)
            {
                foreach (string item in File.ReadAllLines("TheDock2.txt", Encoding.UTF8))
                {
                    string[] boatData2 = item.Split(";");

                    for (int z4 = 0; z4 < boatData2.Length; z4++)
                    {
                        switch (boatData2[1].First())
                        {
                        case 'R':
                            RowingBoat r = new RowingBoat(int.Parse(boatData2[0]), boatData2[1], int.Parse(boatData2[2]), int.Parse(boatData2[3]),
                                                          boatData2[4], boatData2[5], int.Parse(boatData2[6]), int.Parse(boatData2[7]));
                            addRowingBoat(r, rowingBoatArray);

                            break;

                        default:
                            break;
                        }
                    }
                }
            }
        }