示例#1
0
        int count     = 0;            // Pocitadlo jidel

        public Form1()
        {
            InitializeComponent();
            progressBar1.Visible = false;
            canvas.Width         = 762;
            canvas.Height        = 502;
            int x = (canvas.Width / 20) / 2;
            int y = (canvas.Height / 20) / 2;

            had = new Had(x, y, canvas.Width / 20, canvas.Height / 20);
        }
示例#2
0
        private void StartGame()
        {
            int x = (canvas.Width / 20) / 2;
            int y = (canvas.Height / 20) / 2;

            had = new Had(x, y, canvas.Width / 20, canvas.Height / 20);
            PremistiJidlo();
            lb_skore.Text      = "0";
            count              = 0;
            had.HadSnedlJidlo += OnHadSnedlJidlo;
            had.HadUmrel      += OnHadUmrel;

            herniTimer.Start();
            canvas.Refresh();
        }
示例#3
0
 public Hra()
 {
     had = new Had();
     HraciPole.VytvorHraciPole();
 }
示例#4
0
文件: Program.cs 项目: mojmik/Had
        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;
                    }
                }
            }
        }