Example #1
0
        // na zacatku hry plni matici pole, ktera odpovida hraci plose jako prvek pole je pouzito tlacitko,
        // ktere si nese vsechny atributy o hraci plose k nasledne dalsi manipulaci
        private void GenerujPlochu()
        {
            for (int i = 0; i < 8; i++)
            {
                for (int z = 0; z < 8; z++)
                {
                    var policko = new Policko();
                    policko.Oznacena = false;
                    policko.Radek    = i;
                    policko.Sloupec  = z;
                    policko.Barva    = ((i + z) % 2); // 0-bily , 1-Cerny
                    if (policko.Barva == 1 & i < 3)
                    {
                        policko.JeKamen = true;
                    }
                    if (policko.Barva == 1 & i > 4)
                    {
                        policko.JeKamen = true;
                    }
                    //policko.Obraz = GenerujObraz(i, z, policko.Barva);
                    var picture = new PictureBox();
                    if (policko.Barva == 0)
                    {
                        picture.Image = global::ProgramDama2.Properties.Resources.svetly;
                    }
                    else
                    {
                        picture.Image = global::ProgramDama2.Properties.Resources.tmavy;
                    }

                    if (policko.Barva == 1 & i < 3)
                    {
                        picture.Image = global::ProgramDama2.Properties.Resources.tmavykamen;
                    }
                    if (policko.Barva == 1 & i > 4)
                    {
                        picture.Image = global::ProgramDama2.Properties.Resources.bilykamen;
                    }
                    picture.Location = new System.Drawing.Point(z * 75, i * 75);
                    picture.Size     = new System.Drawing.Size(75, 75);
                    picture.TabStop  = false;
                    picture.Click   += policko_Click;
                    HraciPlocha.Controls.Add(picture);
                    picture.Tag     = policko;
                    policko.Obraz   = picture;
                    HraciPole[i, z] = policko;
                }
            }
            this.LabelHrac.Text = "Hraje hrac Bílý";
            this.LabelHrac.Tag  = 0;
        }
Example #2
0
        private void policko_Click(object sender, EventArgs e)
        {
            PictureBox picture = (PictureBox)sender;
            Policko    pole    = (Policko)picture.Tag;

            if (pole.Barva == 1 & pole.JeKamen == true)
            {
                pole.Oznacena = true;
            }

            string s = "Radek je " + Convert.ToString(pole.Radek) + " Sloupec je " + Convert.ToString(pole.Sloupec);

            MessageBox.Show(this, s, "Oznameni", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }