this snippet below is my code.
It's supposed to be a memory game, but i have some problems making it work, I've made a button_1 that generates 6 random numbers in random order, those 6 numbers are supposed to tell the "p1 - p6" (pictures (2 of each to make pairs)) what picture boxes, they're getting in to, I'd really like it to be random what pictures, goes into the picture boxes.
problems i have:
1. random numbers cant get into the array "R[6]" and then i cant use it down in the "pictureboxes" to get assigned to a picture.
2. when 2 pictures are flipped with the same picture, i need them to disappear, (after a timer)
its supposed to give point for every pair of match,
in this code, there's only 6 picture boxes, i need like 25-30
i only got 3 different pictures in this code, again i need like 6 so that there's 5 pairs of each picture if you got any solutions, or questions regarding what i need in my game, please e-mail me on <<snip>>
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Memory_try_1
{
public partial class Form1 : Form
{
System.Random randi = new System.Random();
Image b1 = Properties.Resources.bagside;
Image[] pic = new Image[6];
Bitmap[] imgArray = new Bitmap[6];
PictureBox[] boxArray = new PictureBox[6];
Image p1 = Properties.Resources.Creek;
Image p2 = Properties.Resources.Creek;
Image p3 = Properties.Resources.Toco_Toucan;
Image p4 = Properties.Resources.Toco_Toucan;
Image p5 = Properties.Resources.Green_Sea_Turtle;
Image p6 = Properties.Resources.Green_Sea_Turtle;
Image førstepic = Properties.Resources.bagside;
PictureBox førstepicturebox = new PictureBox();
bool forside1 = false;
bool forside2 = false; // bare over with me, there is alot of un-used varibels in this program
bool forside3 = false; // thats's cause i've tryed manny solutions, but when i tryed something else
bool forside4 = false; // all of them werent delleted
bool forside5 = false;
bool forside6 = false;
bool klik = true; // if klik is true, its's the first click of 2
int kortnummer = 0;
int i = 0;
int [] R = new int[6];
int R1 = 0;
int R2 = 0;
int R3 = 0;
int R4 = 0;
int R5 = 0;
int R6 = 0;
int førindex = 0;
int clicks = 0;
public Form1()
{
InitializeComponent();
pictureBox1.Image = b1;
pictureBox2.Image = b1;
pictureBox3.Image = b1;
pictureBox4.Image = b1;
pictureBox5.Image = b1;
pictureBox6.Image = b1;
}
private void button1_Click(object sender, EventArgs e) // the button that starts the game
{
R[1] = randi.Next(1, 7);
do
R[2] = randi.Next(1, 7); // here i make 6 random numbers in a random order
while (R[2] == R[1]); // and define them in an array "R" R[1 to 6]
do
R[3] = randi.Next(1, 7);
while (R[3] == R[1] || R[3] == R[2]);
do
R[4] = randi.Next(1, 7);
while (R[4] == R[1] || R[4] == R[2] || R[4] == R[3]);
do
R[5] = randi.Next(1, 7);
while (R[5] == R[1] || R[5] == R[2] || R[5] == R[3] || R[5] == R[4]);
do
R[6] = randi.Next(1, 7);
while (R[6] == R[1] || R[6] == R[2] || R[6] == R[3] || R[6] == R[4] || R[6] == R[5]);
pic[R1 - 1] = p1;
pic[R2 - 1] = p2;
pic[R3 - 1] = p3;
pic[R4 - 1] = p4;
pic[R5 - 1] = p5;
pic[R6 - 1] = p6;
pictureBox1.Image = b1;
pictureBox2.Image = b1;
pictureBox3.Image = b1;
pictureBox4.Image = b1;
pictureBox5.Image = b1;
pictureBox6.Image = b1;
pictureboxtest.Image = b1;
}
private void pictureBox1_Click(object sender, EventArgs e)
{
if (forside1)
pictureBox1.Image = b1;
else
{
pictureBox1.Image = pic[0];
}
forside1 = !forside1;
if (klik)
{
i = 0;
while (R[i++] != 1) ;
førindex = i - 1;
}
else
i = 0;
while (R[i++] != 1) ;
switch (i - 1)
{
case 0: if (førindex == 1)//bite
;
break;
case 1: if (førindex == 0)//bite
;
break;
case 2: if (førindex == 3)//bite
;
break;
case 3: if (førindex == 2)//bite
;
break;
case 4: if (førindex == 5)//bite
;
break;
case 5: if (førindex == 4)//bite
;
break;
// bite = they together make a match, and needs to be removed
}
klik = !klik;
}
private void pictureBox2_Click(object sender, EventArgs e)
{
if (forside2)
pictureBox2.Image = b1;
else
{
pictureBox2.Image = pic[1];
}
forside2 = !forside2;
if (klik)
{
i = 0;
while (R[i++] != 2) ;
førindex = i - 1;
}
else
i = 0;
while (R[i++] != 2) ;
switch (i - 1)
{
case 0: if (førindex == 1)//bite
;
break;
case 1: if (førindex == 0)//bite
;
break;
case 2: if (førindex == 3)//bite
;
break;
case 3: if (førindex == 2)//bite
;
break;
case 4: if (førindex == 5)//bite
;
break;
case 5: if (førindex == 4)//bite
;
break;
// bite = they together make a match, and needs to be removed
}
klik = !klik;
}
private void pictureBox3_Click(object sender, EventArgs e)
{
if (forside3)
pictureBox3.Image = b1;
else
{
pictureBox3.Image = pic[2];
}
forside3 = !forside3;
if (klik)
{
i = 0;
while (R[i++] != 3) ;
førindex = i - 1;
}
else
i = 0;
while (R[i++] != 3) ;
switch (i - 1)
{
case 0: if (førindex == 1)//bite
;
break;
case 1: if (førindex == 0)//bite
;
break;
case 2: if (førindex == 3)//bite
;
break;
case 3: if (førindex == 2)//bite
;
break;
case 4: if (førindex == 5)//bite
;
break;
case 5: if (førindex == 4)//bite
;
break;
// bite = they together make a match, and needs to be removed
}
klik = !klik;
}
private void pictureBox4_Click(object sender, EventArgs e)
{
if (forside4)
pictureBox4.Image = b1;
else
{
pictureBox4.Image = pic[3];
}
forside4 = !forside4;
if (klik)
{
i = 0;
while (R[i++] != 4) ;
førindex = i - 1;
}
else
i = 0;
while (R[i++] != 4) ;
switch (i - 1)
{
case 0: if (førindex == 1)//bite
;
break;
case 1: if (førindex == 0)//bite
;
break;
case 2: if (førindex == 3)//bite
;
break;
case 3: if (førindex == 2)//bite
;
break;
case 4: if (førindex == 5)//bite
;
break;
case 5: if (førindex == 4)//bite
;
break;
// bite = they together make a match, and needs to be removed
}
klik = !klik;
}
private void pictureBox5_Click(object sender, EventArgs e)
{
if (forside5)
pictureBox5.Image = b1;
else
{
pictureBox5.Image = pic[4];
}
forside5 = !forside5;
if (klik)
{
i = 0;
while (R[i++] != 5) ;
førindex = i - 1;
}
else
i = 0;
while (R[i++] != 5) ;
switch (i - 1)
{
case 0: if (førindex == 1)//bite
;
break;
case 1: if (førindex == 0)//bite
;
break;
case 2: if (førindex == 3)//bite
;
break;
case 3: if (førindex == 2)//bite
;
break;
case 4: if (førindex == 5)//bite
;
break;
case 5: if (førindex == 4)//bite
;
break;
// bite = they together make a match, and needs to be removed
}
klik = !klik;
}
private void pictureBox6_Click(object sender, EventArgs e)
{
if (forside6)
pictureBox6.Image = b1;
else
{
pictureBox6.Image = pic[5];
}
forside6 = !forside6;
if (klik)
{
i = 0;
while (R[i++] != 6) ;
førindex = i - 1;
}
else
i = 0;
while (R[i++] != 6) ;
switch (i-1)
{
case 0: if (førindex == 1)//bite
;
break;
case 1: if (førindex == 0)//bite
;
break;
case 2: if (førindex == 3)//bite
;
break;
case 3: if (førindex == 2)//bite
;
break;
case 4: if (førindex == 5)//bite
;
break;
case 5: if (førindex == 4)//bite
;
break;
// bite = they together make a match, and needs to be removed
}
klik = !klik;
}
}
}