Пример #1
0
        /// <summary>
        /// Nacte z editu potrebne hodnoty, zkontroluje je a vygeneruje bludiste zadanych rozmeru.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void bGenerujBludiste_Click(object sender, EventArgs e)
        {
            if (tbSirka.Text.Length == 0 || tbVyska.Text.Length == 0)
            {
                return;
            }

            int w = Convert.ToInt32(tbSirka.Text);
            int h = Convert.ToInt32(tbVyska.Text);

            //omezeni rozmeru
            if (w < 0 || h < 0 || w > 500 || h > 500)
            {
                return;
            }

            //generovani bludiste
            this.bludiste = gb.generujPerfektniBludiste(w, h);

            Random r = new Random();

            //vygeneruje cilovou bunku
            int cx = r.Next(w);
            int cy = r.Next(h);

            bludiste[cx, cy].cil = true;

            //pozice hrace
            int hx = r.Next(w);
            int hy = r.Next(h);

            while (hx == cx && hy == cy)
            {
                hx = r.Next(w);
                hy = r.Next(h);
            }
            hrac  = new Hrac(hx, hy);
            origX = hx;
            origY = hy;

            //neni v cili
            vCili = false;

            vykresliBludiste();
            vykresliHrace();

            this.Focus();
        }
Пример #2
0
        private void resetBludiste(object sender, EventArgs e)
        {
            if (bludiste == null)
            {
                return;
            }
            hrac  = new Hrac(origX, origY);
            vCili = false;

            //vsechny bunky bludiste jsou neobjevene
            for (int i = 0; i < bludiste.GetLength(0); i++)
            {
                for (int j = 0; j < bludiste.GetLength(1); j++)
                {
                    bludiste[i, j].stav = Bunka.OTEVRENO;
                }
            }

            vykresliBludiste();
            vykresliHrace();
        }