Click here to Skip to main content
15,909,030 members
Home / Discussions / C#
   

C#

 
AnswerRe: C# Specified cast is not valid Pin
Nelson Costa Inácio22-Dec-16 22:42
Nelson Costa Inácio22-Dec-16 22:42 
GeneralRe: C# Specified cast is not valid Pin
harold aptroot22-Dec-16 22:45
harold aptroot22-Dec-16 22:45 
GeneralRe: C# Specified cast is not valid Pin
OriginalGriff23-Dec-16 0:05
mveOriginalGriff23-Dec-16 0:05 
AnswerRe: C# Specified cast is not valid Pin
Pete O'Hanlon23-Dec-16 0:00
mvePete O'Hanlon23-Dec-16 0:00 
AnswerRe: C# Specified cast is not valid Pin
Gerry Schmitz23-Dec-16 6:50
mveGerry Schmitz23-Dec-16 6:50 
GeneralRe: C# Specified cast is not valid Pin
Richard MacCutchan23-Dec-16 6:59
mveRichard MacCutchan23-Dec-16 6:59 
QuestionWhat is this JWT Code Doing? Pin
TheOnlyRealTodd21-Dec-16 15:46
professionalTheOnlyRealTodd21-Dec-16 15:46 
GeneralRe: What is this JWT Code Doing? Pin
Richard MacCutchan21-Dec-16 21:54
mveRichard MacCutchan21-Dec-16 21:54 
GeneralRe: What is this JWT Code Doing? Pin
TheOnlyRealTodd21-Dec-16 22:35
professionalTheOnlyRealTodd21-Dec-16 22:35 
GeneralRe: What is this JWT Code Doing? Pin
OriginalGriff21-Dec-16 23:24
mveOriginalGriff21-Dec-16 23:24 
GeneralRe: What is this JWT Code Doing? Pin
Gerry Schmitz22-Dec-16 4:07
mveGerry Schmitz22-Dec-16 4:07 
AnswerRe: What is this JWT Code Doing? Pin
Richard Deeming22-Dec-16 2:35
mveRichard Deeming22-Dec-16 2:35 
QuestionNeed help on how to if record exists update else insert c# Pin
Bootzilla3321-Dec-16 7:56
Bootzilla3321-Dec-16 7:56 
AnswerRe: Need help on how to if record exists update else insert c# Pin
Michael_Davies21-Dec-16 8:04
Michael_Davies21-Dec-16 8:04 
AnswerRe: Need help on how to if record exists update else insert c# Pin
Richard Deeming21-Dec-16 8:06
mveRichard Deeming21-Dec-16 8:06 
AnswerRe: Need help on how to if record exists update else insert c# Pin
Nelson Costa Inácio21-Dec-16 23:34
Nelson Costa Inácio21-Dec-16 23:34 
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 

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.