Click here to Skip to main content
15,888,124 members
Home / Discussions / C#
   

C#

 
QuestionC# PictureBox remove image Pin
Pavlex420-Dec-16 11:21
Pavlex420-Dec-16 11:21 
AnswerRe: C# PictureBox remove image Pin
Pavlex420-Dec-16 11:39
Pavlex420-Dec-16 11:39 
GeneralRe: C# PictureBox remove image Pin
Mohan Baro20-Dec-16 18:10
Mohan Baro20-Dec-16 18:10 
GeneralRe: C# PictureBox remove image Pin
Pavlex420-Dec-16 20:11
Pavlex420-Dec-16 20:11 
SuggestionRe: C# PictureBox remove image Pin
Ralf Meier20-Dec-16 21:19
mveRalf Meier20-Dec-16 21:19 
GeneralRe: C# PictureBox remove image Pin
Pavlex420-Dec-16 21:24
Pavlex420-Dec-16 21:24 
GeneralRe: C# PictureBox remove image Pin
Ralf Meier21-Dec-16 1:18
mveRalf Meier21-Dec-16 1:18 
GeneralRe: C# PictureBox remove image Pin
Pavlex421-Dec-16 8:21
Pavlex421-Dec-16 8:21 
C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
 
namespace Slagalica
{
    public partial class Skocko : MetroFramework.Forms.MetroForm
    {
        public Skocko()
        {
            InitializeComponent();
        }
        private SkockoClass objSkocko;
 
        private void Skocko_Load(object sender, EventArgs e)
        {
            this.objSkocko = new SkockoClass();
 
            //imageList1.ImageSize = new Size(60, 60);
            //imageList1.ColorDepth = ColorDepth.Depth32Bit;
        }
        private void pictureBox14_Click(object sender, EventArgs e)
        {
        }
        private void pictureBox38_Click(object sender, EventArgs e)
        {
        }
 
        private PictureBox findMyPictureBox(string parPrefix, int parRed, int parKolona)
        {
            return (PictureBox)base.Controls[string.Format("{2}{0}{1}", parRed, parKolona, parPrefix)];
        }
 
        private PictureBox findMyPictureBoxDobitna(int parBroj)
        {
            return (PictureBox)base.Controls[string.Format("pBoxDobitna{0}", parBroj)];
        }
 
        private void OsvezipBoxIgra()
        {
            for (int i = 0; i < 6; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    if (this.objSkocko.glavnaMatrica[i, j] != 100)
                    {
                        PictureBox pictureBox = this.findMyPictureBox("pBoxIgra", i, j);
                        pictureBox.Image = this.imageList1.Images[this.objSkocko.glavnaMatrica[i, j]];                        
                    }
                }
            }
        }
 
        private void OsvezipBoxRezultat()
        {
            for (int i = 0; i < 6; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    if (this.objSkocko.rezultatMatrica[i, j] != 100)
                    {
                        PictureBox pictureBox = this.findMyPictureBox("pBoxRezultat", i, j);
                        if (this.objSkocko.rezultatMatrica[i, j] == 1)
                        {
                            pictureBox.BackColor = Color.Yellow;
                        }
                        else
                        {
                            pictureBox.BackColor = Color.Red;
                        }
                    }
                }
            }
        }
 
        private void OsvezipBoxDobitna()
        {
            for (int i = 0; i < 4; i++)
            {
                PictureBox pictureBox = this.findMyPictureBoxDobitna(i);
                pictureBox.Image = this.imageList1.Images[this.objSkocko.dobitnaKombinacija[i]];
            }
        }
 
        private void Igraj(int parZnak)
        {
            this.objSkocko.Igraj(parZnak);
            this.OsvezipBoxIgra();
            this.OsvezipBoxRezultat();
            if (this.objSkocko.Pobeda)
            {
                this.OsvezipBoxDobitna();
                if (MessageBox.Show("POBEDILI STE!!!\nNova igra?", "POBEDA", MessageBoxButtons.OKCancel) == DialogResult.OK)
                {
                    Application.Restart();
                }
                else
                {
                    Application.Exit();
                }
            }
            if (this.objSkocko.trenutniPotez == 23)
            {
                this.OsvezipBoxDobitna();
                if (MessageBox.Show("IZGUBILI STE!!!\nNova igra?", "PORAZ", MessageBoxButtons.OKCancel) == DialogResult.OK)
                {
                    Application.Restart();
                }
                else
                {
                    Application.Exit();
                }
            }
        }
 
        private void btnIgrajSkocko_Click(object sender, EventArgs e)
        {
            this.Igraj(0);
        }
 
        private void btnIgrajZvezda_Click(object sender, EventArgs e)
        {
            this.Igraj(1);
        }
 
        private void btnIgrajPik_Click(object sender, EventArgs e)
        {
            this.Igraj(2);
        }
 
        private void btnIgrajKaro_Click(object sender, EventArgs e)
        {
            this.Igraj(3);
        }
 
        private void btnIgrajHerc_Click(object sender, EventArgs e)
        {
            this.Igraj(4);
        }
 
        private void btnIgrajTref_Click(object sender, EventArgs e)
        {
            this.Igraj(5);
        }
    }
}


Other class with code:

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Slagalica
{
    class SkockoClass
    {
        public int trenutniPotez;

        public int[,] glavnaMatrica;

        public int[,] rezultatMatrica;

        public int[] dobitnaKombinacija;

        public bool Pobeda;

        public SkockoClass()
        {
            this.Pobeda = false;
            this.trenutniPotez = -1;
            this.InicijalizacijaMatrice();
            this.GenerisiDobitnuKombinaciju();
        }

        public void Igraj(int parIzabrano)
        {
            this.trenutniPotez++;
            int num = Convert.ToInt32(Math.Floor((double)this.trenutniPotez / 4.0));
            int num2 = this.trenutniPotez % 4;
            this.glavnaMatrica[num, num2] = parIzabrano;
            if (this.trenutniPotez % 4 == 3)
            {
                this.Provera(num);
            }
        }

        public void Provera(int parRed)
        {
            int[] array = new int[4];
            int[] array2 = new int[4];
            for (int i = 0; i < 4; i++)
            {
                array[i] = this.glavnaMatrica[parRed, i];
                array2[i] = this.dobitnaKombinacija[i];
            }
            int num = 0;
            for (int i = 0; i < 4; i++)
            {
                if (array[i] == array2[i])
                {
                    num++;
                    array[i] = 100;
                    array2[i] = 100;
                }
            }
            int num2 = 0;
            for (int i = 0; i < 4; i++)
            {
                if (array[i] != 100)
                {
                    for (int j = 0; j < 4; j++)
                    {
                        if (array2[j] != 100 && array2[j] == array[i])
                        {
                            num2++;
                            array[i] = 100;
                            array2[j] = 100;
                        }
                    }
                }
            }
            if (num == 4)
            {
                this.Pobeda = true;
            }
            this.PuniZuteCrvene(parRed, num2, num);
        }

        public void PuniZuteCrvene(int parRed, int parZutih, int parCrvenih)
        {
            int num = -1;
            for (int i = 0; i <= parCrvenih - 1; i++)
            {
                this.rezultatMatrica[parRed, ++num] = 0;
            }
            for (int i = 0; i <= parZutih - 1; i++)
            {
                this.rezultatMatrica[parRed, ++num] = 1;
            }
        }

        public void GenerisiDobitnuKombinaciju()
        {
            this.dobitnaKombinacija = new int[4];
            Random random = new Random();
            for (int i = 0; i < 4; i++)
            {
                this.dobitnaKombinacija[i] = random.Next(0, 6);
            }
        }

        private void InicijalizacijaMatrice()
        {
            this.glavnaMatrica = new int[6, 4];
            for (int i = 0; i < 6; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    this.glavnaMatrica[i, j] = 100;
                }
            }
            this.rezultatMatrica = new int[6, 4];
            for (int i = 0; i < 6; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    this.rezultatMatrica[i, j] = 100;
                }
            }
        }
    }
}

GeneralRe: C# PictureBox remove image Pin
Ralf Meier21-Dec-16 22:58
mveRalf Meier21-Dec-16 22:58 
QuestionSpecified cast is not valid. i can't understand error Pin
Member 1289974620-Dec-16 2:07
Member 1289974620-Dec-16 2:07 
AnswerRe: Specified cast is not valid. i can't understand error Pin
OriginalGriff20-Dec-16 2:30
mveOriginalGriff20-Dec-16 2:30 
GeneralRe: Specified cast is not valid. i can't understand error Pin
Member 1289974620-Dec-16 2:34
Member 1289974620-Dec-16 2:34 
GeneralRe: Specified cast is not valid. i can't understand error Pin
Ralf Meier20-Dec-16 2:38
mveRalf Meier20-Dec-16 2:38 
AnswerRe: Specified cast is not valid. i can't understand error Pin
Ralf Meier20-Dec-16 2:36
mveRalf Meier20-Dec-16 2:36 
GeneralRe: Specified cast is not valid. i can't understand error Pin
Member 1289974620-Dec-16 2:44
Member 1289974620-Dec-16 2:44 
AnswerRe: Specified cast is not valid. i can't understand error Pin
Richard Deeming20-Dec-16 2:45
mveRichard Deeming20-Dec-16 2:45 
AnswerRe: Specified cast is not valid. i can't understand error Pin
Nelson Costa Inácio21-Dec-16 5:54
Nelson Costa Inácio21-Dec-16 5:54 
QuestionIs there anything wrong with passing state via argument? Pin
TheOnlyRealTodd20-Dec-16 0:12
professionalTheOnlyRealTodd20-Dec-16 0:12 
AnswerRe: Is there anything wrong with passing state via argument? Pin
Afzaal Ahmad Zeeshan20-Dec-16 0:39
professionalAfzaal Ahmad Zeeshan20-Dec-16 0:39 
GeneralRe: Is there anything wrong with passing state via argument? Pin
TheOnlyRealTodd20-Dec-16 17:56
professionalTheOnlyRealTodd20-Dec-16 17:56 
Questioni get an error (non-invocable member-- can't be used like a method) any help? Pin
Member 1289974619-Dec-16 23:21
Member 1289974619-Dec-16 23:21 
AnswerRe: i get an error (non-invocable member-- can't be used like a method) any help? Pin
Afzaal Ahmad Zeeshan19-Dec-16 23:32
professionalAfzaal Ahmad Zeeshan19-Dec-16 23:32 
GeneralRe: i get an error (non-invocable member-- can't be used like a method) any help? Pin
Member 1289974619-Dec-16 23:42
Member 1289974619-Dec-16 23:42 
GeneralRe: i get an error (non-invocable member-- can't be used like a method) any help? Pin
Afzaal Ahmad Zeeshan19-Dec-16 23:45
professionalAfzaal Ahmad Zeeshan19-Dec-16 23:45 
GeneralRe: i get an error (non-invocable member-- can't be used like a method) any help? Pin
OriginalGriff19-Dec-16 23:55
mveOriginalGriff19-Dec-16 23:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.