예제 #1
0
        public int Kolizja()
        {
            Baza bax = new Baza();

            for (int i = 0; i < s.Count; i++)         // kolejne statki
            {
                for (int j = i + 1; j < s.Count; j++) // z kazdymi statkami
                {
                    int git = 0;
                    if (s[i].h == s[j].h)     // sprawdzenie wysokosci
                    {
                        for (int a = 0; a < s[i].tr.Count; a++)
                        {
                            for (int b = 0; b < s[j].tr.Count; b++)
                            {
                                if (s[i].tr[a].x == s[j].tr[b].x && s[i].tr[a].y == s[j].tr[b].y)
                                {
                                    if (Odleglosc(i, a) / s[i].v / 3.6 - Odleglosc(j, b) / s[j].v / 3.6 < 0.2 &&
                                        Odleglosc(i, a) / s[i].v / 3.6 - Odleglosc(j, b) / s[j].v / 3.6 > -0.2)
                                    {
                                        s[i].stanLotu = "Koliz";
                                        s[j].stanLotu = "Koliz";
                                        git++; break;
                                    }
                                    else
                                    {
                                        s[i].stanLotu = "Spoko";
                                        s[j].stanLotu = "Spoko";
                                    }
                                }
                            }
                            if (git > 0)
                            {
                                break;
                            }
                        }
                    }
                }
                if (skala > 1)
                {
                    KolizjaBudynek(s[i]);
                }
            }
            return(0);
        }
예제 #2
0
        public void pokaSkale()
        {
            Baza baz = new Baza();

            for (int i = 1; i < 25; i++)
            {
                baz.insert(9 + i * 4, 17, Convert.ToString(100 + i * 2));
                baz.insert(9 + i * 4, 17, ":");
            }
            for (int i = 0; i < mapa.Length - 1; i++)
            {
                if (i % 2 == 0 && i != 0)
                {
                    baz.insert(6, 18 + i, Convert.ToString(100 + i));
                    baz.insert(6, 18 + i, ":");
                }
            }
        }
예제 #3
0
        public void pokaTrajektorie()
        {
            Baza b = new Baza();

            for (int i = 1; i < tr.Count; i++)
            {
                if (tr[i].x > 0 && tr[i].y > 0 && tr[i].x < 97 && tr[i].y < 33)
                {
                    if (tr[i].d % 4 == 0 && tr[i].x % 2 == 0)
                    {
                        b.insert(11 + tr[i].x, 18 + tr[i].y, " ");
                    }
                    else
                    {
                        b.insert(11 + tr[i].x, 18 + tr[i].y, "^");
                    }
                }
            }
        }
예제 #4
0
        public void zmienMape(int czy)
        {
            Baza baz = new Baza();

            Console.ForegroundColor = ConsoleColor.DarkGray;
            baz.pokaKonsole(skala, 0);
            if (czy > 0)
            {
                baz.pokaListeLotow(this, 1);
            }
            Console.ResetColor();
            baz.insert(139, 42, "Wybierz mape, ktora chcesz wczytac:");
            baz.insert(141, 44, "[1] Mapa SanAndreas (48 x 32 km)");
            baz.insert(141, 46, "[2] Mapa NewYourk (2,4 x 1,6 km)");
            switch (Console.ReadKey().KeyChar)
            {
            case '1': mapa = System.IO.File.ReadAllLines("mapa1.txt"); skala = int.Parse(mapa[mapa.Length - 1]); break;

            case '2': mapa = System.IO.File.ReadAllLines("mapa2.txt"); skala = int.Parse(mapa[mapa.Length - 1]); break;
            }
            baz.czyscKonsole();
        }
예제 #5
0
        public void pokaTrajektorie()
        {
            Baza b = new Baza();

            Console.ForegroundColor = ConsoleColor.Yellow;
            for (int i = 1; i < tr.Count; i++)
            {
                if (tr[i].x > 0 && tr[i].y > 0 && tr[i].x < 97 && tr[i].y < 33)
                {
                    if (tr[i].d % 4 == 0 && tr[i].x % 2 == 0)
                    {
                        b.insert(11 + tr[i].x, 18 + tr[i].y, " ");
                    }
                    else
                    {
                        b.insert(11 + tr[i].x, 18 + tr[i].y, "^");
                    }
                    //else b.insert(11 + tr[i].x, 18 + tr[i].y, Convert.ToString(tr[i].d));
                }
            }
            Console.ResetColor();
        }
예제 #6
0
        static void Main(string[] args)
        {
            Console.SetWindowSize(213, 52);
            Console.SetBufferSize(213, 52);
            Console.Title = "Kontrola Lotow";

            Radar radar         = new Radar();
            Baza  b             = new Baza(radar);
            Trasa losowySamolot = new Trasa(0, 0, 0, 0, 0);

            b.pokaInterfejs();
            int ms   = 0;
            int lot  = -1;
            int time = 100;

            int[] x = new int[1];
            x[0] = 0;
            for (; ;)
            {
                if (radar.run < 0)
                {
                    b.pokaInterfejs();
                }
                else
                {
                    radar.pokaRadar();                               // aktualizuje i wyswietla radar
                }
                b.pokaListeLotow(radar, x[0]);                       // wypisuje liste lotow do podgledu/edycji
                b.insert(200, 26, Convert.ToString(ms / 10 + " s")); // wypisuje czas trwania programu
                b.insert(212, 51, Convert.ToString("."));            // wypisuje nic na koncu okna
                b.pokaLot(radar, lot);

                if (Console.KeyAvailable)                           // pobiera wybrany przycisk
                {
                    char wybor = Console.ReadKey().KeyChar;
                    if (lot >= 0)
                    {
                        switch (wybor)
                        {
                        case '0': b.czyscKonsole(); lot = -1; break;

                        case '1': if (radar.s[lot].trajektoria < 1)
                            {
                                radar.s[lot].trajektoria++;
                            }
                            else
                            {
                                radar.s[lot].trajektoria--;
                            } break;

                        case '2': radar.s[lot].zmienTrajektorie(); break;
                        }
                    }                                          // zarzadzanie lotem
                    else if (wybor - 49 >= 0 && wybor - 49 < 10 && wybor - 49 <= radar.s.Count)
                    {
                        lot = wybor - 49;
                    }   // wypisuje info o danym locie
                    else if (wybor == 'q')
                    {
                        System.Diagnostics.Process.GetCurrentProcess().Kill();
                    }   // zabija aplikacje
                    else if (wybor == 'e')
                    {
                    }   // info o wlascicielach
                    else if (wybor == 'w')
                    {
                        losowySamolot = new Trasa(1, 2, 0, 0, 200);
                    }   // pusc samolot
                    else if (wybor == 'r')
                    {
                        radar.run *= -1;
                    }   // wlaczy/wylacz radar
                    else if (wybor == ']')
                    {
                        if (time > 15)
                        {
                            time -= 15;
                        }
                    }   // przyspiesz czas
                    else if (wybor == '[')
                    {
                        time += 15;
                    }   // przyspiesz czas
                }
                Thread.Sleep(time);
                ms++;
                if (losowySamolot.v != 0)
                {
                    b.pokaSamolot(ref losowySamolot);                       // ladujacy samolot
                }
            }
        }
예제 #7
0
        public int Losowanko()
        {
            Baza b = new Baza();

            if (s.Count == 9)
            {
                return(0);
            }

            Random rand = new Random();
            int    eloy, bencx, w = 0, k = 0, p = 0, czy;
            string typ = "";

            eloy  = rand.Next(-12, 44);
            bencx = rand.Next(-24, 120);
            //bencx = rand.Next(1, 95);
            czy = rand.Next(0, 30);

            if ((eloy > 32 || eloy < 0 || bencx > 96 || bencx < 0) && czy == 13)
            {
                int los;
                switch (skala)
                {
                case 1:         // y = -12 44 x = -24 120  x 0 96 y 0 32 , 770 830
                {
                    los = rand.Next(1, 3);
                    if (los == 1)
                    {
                        p = rand.Next(770, 830); w = rand.Next(10, 12) * 1000; typ = "S";
                    }
                    if (los == 2)
                    {
                        p = rand.Next(250, 350); w = rand.Next(3, 4) * 1000; typ = "Z";
                    }
                    if (los == 3)
                    {
                        p = rand.Next(150, 300); w = rand.Next(2, 4) * 1000; typ = "H";
                    }
                }
                break;

                case 20:         // 150 300
                {
                    los = rand.Next(1, 3);
                    if (los == 1)
                    {
                        p = rand.Next(20, 40); w = rand.Next(2, 6) * 100; typ = "B";
                    }
                    if (los == 2)
                    {
                        p = rand.Next(90, 120); w = rand.Next(4, 8) * 100; typ = "Z";
                    }
                    if (los == 3)
                    {
                        p = rand.Next(100, 200); w = rand.Next(5, 10) * 100; typ = "H";
                    }
                }
                break;
                }
                los = rand.Next(100, 999);
                typ = typ + Convert.ToString(los);


                if (eloy > 32)     // statek zrespil sie na dolnej polowie mapy
                {
                    if (bencx < 0)
                    {
                        k = 7;
                    }
                    else if (bencx >= 0 && bencx < 18)
                    {
                        k = rand.Next(6, 7);
                    }
                    else if (bencx >= 18 && bencx <= 78)
                    {
                        k = rand.Next(5, 7);
                    }
                    else if (bencx > 78 && bencx <= 96)
                    {
                        k = rand.Next(5, 6);
                    }
                    else if (bencx > 96)
                    {
                        k = 5;
                    }
                }
                else if (eloy < 0)     // statek zrespil sie na gornej polowie mapy
                {
                    if (bencx < 0)
                    {
                        k = 1;
                    }
                    else if (bencx >= 0 && bencx < 18)
                    {
                        k = rand.Next(1, 2);
                    }
                    else if (bencx >= 18 && bencx <= 78)
                    {
                        k = rand.Next(1, 3);
                    }
                    else if (bencx > 78 && bencx <= 96)
                    {
                        k = rand.Next(2, 3);
                    }
                    else if (bencx > 96)
                    {
                        k = 3;
                    }
                }
                else if (bencx < 0)     // statek zrespil sie po lewej stronie mapy
                {
                    if (eloy >= 0 && eloy < 8)
                    {
                        k = rand.Next(6, 7);
                    }
                    else if (eloy >= 8 && eloy <= 24)
                    {
                        k = rand.Next(5, 7);
                    }
                    else if (eloy > 24 && eloy <= 32)
                    {
                        k = rand.Next(5, 6);
                    }
                }
                else if (bencx > 32)     // statek zrespil sie po prawej stronie mapy
                {
                    if (eloy >= 0 && eloy < 8)
                    {
                        k = rand.Next(6, 7);
                    }
                    else if (eloy >= 8 && eloy <= 24)
                    {
                        k = rand.Next(5, 7);
                    }
                    else if (eloy > 24 && eloy <= 32)
                    {
                        k = rand.Next(5, 6);
                    }
                }
                s.Add(new Statek(typ, bencx, eloy, w, k, p));
            }
            return(0);
        }
예제 #8
0
        public void pokaRadar(ref int lot)
        {
            Baza baz = new Baza();

            for (int j = 0; j < mapa.Length - 1; j++)
            {
                baz.insert(10, 18 + j, mapa[j]);
            }
            for (int i = 0; i < s.Count; i++)
            {
                s[i].d = s[i].getDTrajektorii();
                if (s[i].d < 0)
                {
                    s.RemoveAt(s.IndexOf(s[i]));
                    lot = -1;
                    baz.czyscKonsole();
                }
                else
                {
                    s[i].szybkosc += 1;
                    if ((32000 / s[i].v) / skala <= s[i].szybkosc && s[i].d % 2 == 1)        // 560km/h - 1k/2.23s      (skos)
                    {
                        switch (s[i].d)
                        {
                        case 1: s[i].x = s[i].x + 2; s[i].y++; break;

                        case 3: s[i].x = s[i].x - 2; s[i].y++; break;

                        case 5: s[i].x = s[i].x - 2; s[i].y--; break;

                        case 7: s[i].x = s[i].x + 2; s[i].y--; break;
                        }
                        s[i].szybkosc = 0;
                        s[i].aktualizujTrajektorie();
                    }
                    else if ((22400 / s[i].v) / skala <= s[i].szybkosc && s[i].d % 4 == 2)   // 560km/h - 1k/2s         (pion)
                    {
                        switch (s[i].d)
                        {
                        case 2: s[i].y++; break;

                        case 6: s[i].y--; break;
                        }
                        s[i].szybkosc = 0;
                        s[i].aktualizujTrajektorie();
                    }
                    else if ((11200 / s[i].v) / skala <= s[i].szybkosc && s[i].d % 4 == 0)    // 560km/h - 1k/1s         (poziom)
                    {
                        switch (s[i].d)
                        {
                        case 0: s[i].x++; break;

                        case 4: s[i].x--; break;
                        }
                        s[i].szybkosc = 0;
                        s[i].aktualizujTrajektorie();
                    }
                    if (s[i].trajektoria == 1)
                    {
                        s[i].pokaTrajektorie();
                    }

                    Console.ForegroundColor = ConsoleColor.Yellow;
                    if (s[i].x > 0 && s[i].x <= 96 && s[i].y > 0 && s[i].y <= 32)
                    {
                        baz.insert(11 + s[i].x, 18 + s[i].y, s[i].typ);
                    }
                    Console.ResetColor();
                }
            }
        }
예제 #9
0
        public void ustalTrajektorie(int x_cel, int y_cel, int direct, int skala)
        {
            tr = new List <Trasa>();
            //plusTrajektorie(ref tr, d);
            double bok = v * v * 0.00000670162031 * skala; // dlugosc boku osmiokata

            if (x_cel != x || y_cel != y)                  // znajdz trase do podanego celu
            {
                Statek[] s      = new Statek[5];           // tworzy trzon tr s[0], bok okregu s[1], prosta s[2], prostopadla s[3]
                Baza     b      = new Baza();
                int      git    = 0;
                double[] dl_bok = new double[8];
                for (int jj = 0; jj < 8; jj++)             // dlugosci odpowiednich bokow
                {
                    if (jj % 4 == 0)
                    {
                        dl_bok[jj] = Math.Round(bok * 2);                      // poziom
                    }
                    else if (jj % 4 == 2)
                    {
                        dl_bok[jj] = Math.Round(bok * 1);                      // pion
                    }
                    else if (jj % 2 == 1)
                    {
                        dl_bok[jj] = Math.Round(bok * 0.71);                   // skos
                    }
                }
                int xd = -1, x1, y1, x0, y0;

                s[0]   = new Statek(x, y, h, d, v);
                s[0].d = d;
                s[0].tr.Add(new Trasa(x, y, h, d, v));        // trzon trajektorii s[0]

                s[4]   = new Statek(x, y, h, (d + 4) % 8, v); // prosta linia - trasa za samolotem s[4]
                s[4].d = (d + 4) % 8;
                s[4].tr.Add(new Trasa(x, y, h, (d + 4) % 8, v));

                int i4 = 0;
                while (s[4].tr[i4].x <120 && s[4].tr[i4].y <44 && s[4].tr[i4].x> -24 && s[4].tr[i4].y> -12) // wyznacz linie za samolotem
                {
                    plusTrajektorie(ref s[4].tr, s[4].tr[i4].d);                                            // dodaje nastepna kratke
                    i4 = s[4].tr.Count - 1;
                }

                int ile = 0;
                while (ile < 8 && git < 1) // szuka mozliwosci poki co w lewo
                {
                    int dd = s[0].d;       // ostatni kierunek na trzonie s[0]
                    x0 = s[0].tr[s[0].tr.Count - 1].x;
                    y0 = s[0].tr[s[0].tr.Count - 1].y;

                    s[1] = new Statek(x0, y0, h, dd, v);
                    s[1].tr.Add(new Trasa(x0, y0, h, dd, v));           // bok okregu s[1]

                    for (int ii = 0; ii < dl_bok[dd] - 1; ii++)         // dodaje do trajektorii bok
                    {
                        plusTrajektorie(ref s[1].tr, s[1].d);
                    }

                    x1 = s[1].tr[s[1].tr.Count - 1].x;                  // ostatni x s[1]
                    y1 = s[1].tr[s[1].tr.Count - 1].y;                  // ostatni y s[1]

                    s[2] = new Statek(x1, y1, h, dd, v);
                    s[2].tr.Add(new Trasa(x1, y1, h, dd, v));                                                  // tworzy prosta s[2]
                    int i2 = 0, i3 = 0;
                    while (s[2].tr[i2].x < 96 && s[2].tr[i2].y < 32 && s[2].tr[i2].x > 0 && s[2].tr[i2].y > 0) // tworzy trajektorie s[2]
                    {
                        plusTrajektorie(ref s[2].tr, s[2].tr[i2].d);                                           // buduje prosta s[2]
                        i2   = s[2].tr.Count - 1;
                        i3   = 0;
                        s[3] = new Statek(s[2].tr[i2].x, s[2].tr[i2].y, h, d, v);
                        s[3].tr.Add(new Trasa(s[2].tr[i2].x, s[2].tr[i2].y, h, (8 + dd + xd) % 8, v));             // tworzy prosta s[3]
                        while (s[3].tr[i3].x < 96 && s[3].tr[i3].y < 32 && s[3].tr[i3].x > 0 && s[3].tr[i3].y > 0) //tworzy tr s[3]
                        {
                            plusTrajektorie(ref s[3].tr, s[3].tr[i3].d);                                           // buduje prosta s[3]
                            i3 = s[3].tr.Count - 1;
                            if (s[3].tr[i3].x == x_cel && s[3].tr[i3].y == y_cel)
                            {
                                git = 1;
                                s[2].tr.RemoveAt(s[2].tr.Count - 1);
                                s[2].tr.AddRange(s[3].tr);
                                s[1].tr.AddRange(s[2].tr);
                            }
                            if (git == 1)
                            {
                                break;
                            }
                        }
                        if (git == 1)
                        {
                            break;
                        }
                    }
                    if (git == 0)
                    {
                        s[0].d = (s[1].d + xd + 8) % 8;
                    }
                    s[1].tr.RemoveAt(0);
                    s[0].tr.AddRange(s[1].tr);
                    ile++;
                }

                if (git == 1)
                {
                    tr.AddRange(s[0].tr);             // dodanie tajektorii s[0] do trajektorii samolotu
                }
                else
                {
                    tr.Add(new Trasa(x, y, h, d, v));
                }
            }
            else
            {
                tr.Add(new Trasa(x, y, h, d, v));
            }
            int i = tr.Count - 1;

            while (tr[i].x <120 && tr[i].y <44 && tr[i].x> -24 && tr[i].y> -12) // kontynuluj lot prosto
            {
                plusTrajektorie(ref tr, tr[i].d);                               // dodaje nastepna kratke
                i = tr.Count - 1;
            }
        }
예제 #10
0
        static void Main(string[] args)
        {
            Console.SetWindowSize(213, 52);
            Console.SetBufferSize(213, 52);
            Console.Title = "Kontrola Lotow";

            Radar radar         = new Radar();
            Baza  b             = new Baza(radar);
            Trasa losowySamolot = new Trasa(0, 0, 0, 0, 0);

            b.pokaInterfejs();
            int ms    = 0;
            int lot   = -1;
            int time  = 100;
            int gener = 0;

            for (; ;)
            {
                if (radar.run < 0)
                {
                    b.pokaInterfejs();
                }
                else
                {
                    radar.pokaRadar(ref lot);                           // aktualizuje i wyswietla radar
                    b.pokaListeLotow(radar, lot);                       // wypisuje liste lotow do podgledu/edycji
                    if (radar.skala > 1)
                    {
                        radar.naniesBudynki();                          // nanosi budynki na mape
                    }
                }
                radar.umieranie();
                if (gener == 1)
                {
                    radar.Losowanko();                                  // generuje samoloty na mapie przez losowanie
                }
                if (lot >= 0)
                {
                    b.pokaLot(radar, lot);                              // wyswietla informacje o locie
                }
                else
                {
                    b.pokaKonsole(radar.skala, gener);                  // czysci konsole
                }
                b.insert(200, 26, Convert.ToString(ms / 10 + " s"));    // wypisuje czas trwania programu
                b.insert(212, 51, Convert.ToString("."));               // wypisuje nic na koncu okna

                if (Console.KeyAvailable)                               // pobiera wybrany przycisk
                {
                    char wybor = Console.ReadKey().KeyChar;
                    if (lot >= 0)
                    {
                        switch (wybor)
                        {
                        case '0': b.czyscKonsole(); lot = -1; break;

                        case '1': if (radar.s[lot].trajektoria < 1)
                            {
                                radar.s[lot].trajektoria++;
                            }
                            else
                            {
                                radar.s[lot].trajektoria--;
                            } break;

                        case '2': radar.s[lot].zmienTrajektorie(radar.skala); break;
                        }                                        // zarzadzanie lotem
                    }
                    else if (wybor - 49 >= 0 && wybor - 49 < 10 && wybor - 49 <= radar.s.Count && radar.run > 0)
                    {
                        b.czyscKonsole();
                        lot = wybor - 49;
                        if (radar.s.Count < lot + 1)
                        {
                            lot = -1;
                        }
                    }   // wypisuje info o danym locie
                    else
                    {
                        switch (wybor)
                        {
                        case 'q': System.Diagnostics.Process.GetCurrentProcess().Kill(); break;         // zabija aplikacje

                        case 'e': b.pokaFax(); break;                                                   // info o wlascicielach

                        case 'w': losowySamolot = new Trasa(1, 2, 0, 0, 200); break;                    // pusc samolot

                        case 'r': radar.run *= -1; radar.pokaSkale(); break;                            // wlaczy/wylacz radar

                        case '.': if (time > 15)
                            {
                                time -= 15;
                            }
                            break;                                                                      // przyspiesz czas

                        case ',': time += 15; break;                                                    // spowolnij czas

                        case '/': time = 100; break;                                                    // ustaw domyslny czas

                        case 'm': radar.zmienMape(radar.run); break;                                    // zmienia mape

                        case 'g': if (gener == 0)
                            {
                                gener = 1;
                            }
                            else
                            {
                                gener = 0;
                            } break;                                                                    // generuje lot

                        case 'b': if (radar.skala > 1)
                            {
                                b.pokaListeBudynkow(radar);
                            }
                            break;                                                                      // generuje lot

                        case 's': b.zapis(radar); break;                                                // zapis do pliku

                        case 'k': radar.Kolizja(); break;                                               // kurs kolizyjny

                        case 'n': radar.NiebezpieczneZblizenia(); break;                                // niebezpieczne zblizenie

                        case 'x': radar.zderzonko(); break;

                        case 'c': radar.trajektorki(); break;
                        }
                    }
                }
                Thread.Sleep(time);
                ms++;
                if (losowySamolot.v != 0)
                {
                    b.pokaSamolot(ref losowySamolot);                       // ladujacy samolot
                }
            }
        }