Exemplo n.º 1
0
        public bool Zer(int x, int y, Zradlo z)
        {
            int pocetDilku = z.Dilky.Count();

            for (int n = 0; n < pocetDilku - 1; n++)
            {
                int curX = z.Dilky[n].x;
                int curY = z.Dilky[n].y;
                if ((curX == x) && (curY == y))
                {
                    z.Dilky.Remove(z.Dilky[n]);
                    Console.Beep(900, 50);
                    Skore += 50;
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 2
0
        public void Lez(Zradlo z)
        {
            int newX = 0, newY = 0;

            newX = Dilky.Last().x;
            newY = Dilky.Last().y;
            if (Smer == 0)
            {
                newX = newX + 1;
            }
            if (Smer == 180)
            {
                newX = newX - 1;
            }
            if (Smer == 270)
            {
                newY = newY + 1;
            }
            if (Smer == 90)
            {
                newY = newY - 1;
            }
            if (Kolize(newX, newY))
            {
                Chcipni();
                return;
            }
            //posledni dilek je hlava
            if (!Zer(newX, newY, z))
            {
                Console.CursorLeft      = Dilky.First().x *2;
                Console.CursorTop       = Dilky.First().y;
                Console.ForegroundColor = ConsoleColor.Green;
                Console.Write("██");
                Dilky.Remove(Dilky.First());
            }
            PridejDilek(newX, newY);
        }
Exemplo n.º 3
0
        static void runGame()
        {
            int tick = 0;

            Console.WindowWidth  = 80;
            Console.WindowHeight = 40;
            Had    had    = new Had();    // Instance hada
            Zradlo zradlo = new Zradlo(); // Instance hada

            Console.CursorVisible   = false;
            Console.BackgroundColor = ConsoleColor.Green; // Nastavení zeleného pozadí
            Console.Clear();
            Console.CursorLeft = 0;
            Console.CursorTop  = 0;
            for (int n = 0; n < Console.WindowWidth; n++)
            {
                Console.ForegroundColor = ConsoleColor.White;
                Console.Write("█");
            }
            while (had.Zivy) // Herní smyčka
            {
                tick++;



                if (tick % 5 == 0)
                {
                    zradlo.PridejDilek();
                }
                zradlo.Vykresli();

                had.Vykresli();  // Vykreslení hada
                had.Lez(zradlo); // Posun hada
                had.PrintInfo(); //kde jsme atd.


                Thread.Sleep(30); // Čekáme 30 milisekund
                                  // Pokud je stisknuta nějaká klávesa
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo klavesa = Console.ReadKey(); // Načtení klávesy
                    if (klavesa.Key == ConsoleKey.Escape)
                    {
                        had.Zivy = false;
                    }
                    if (klavesa.Key == ConsoleKey.RightArrow)
                    {
                        had.Smer = 0;
                    }
                    if (klavesa.Key == ConsoleKey.LeftArrow)
                    {
                        had.Smer = 180;
                    }
                    if (klavesa.Key == ConsoleKey.DownArrow)
                    {
                        had.Smer = 270;
                    }
                    if (klavesa.Key == ConsoleKey.UpArrow)
                    {
                        had.Smer = 90;
                    }
                }
            }
        }