Image[] IMG;
private void buttonLOAD_Click(object sender, EventArgs e)
{
//THE METHOD LOADS ALL OF THE IMAGES FROMA FOLDER TO AN IMAGE ARRAY
int count = 0;
for(;;count++)
{
if (File.Exists(@"STAGE\" + count+".jpg")) ;
else break;
}
IMG = new Image[count];
for(int i = 0; i < IMG.Length; i++)
{
IMG[i] = Image.FromFile(@"STAGE\" + i + ".jpg");
}
labelSTATUS.Text = "Images Successfully Loaded!";
}
private void button1_Click(object sender, EventArgs e)//RANDOMIZE BUTTON
{
imageList1.Images.Clear();
imageList2.Images.Clear();
imageList3.Images.Clear();
imageList4.Images.Clear();
listView1.Clear();
listView2.Clear();
listView3.Clear();
listView4.Clear();
//CLEARING THE LIST AND CALLING THE METHOD
//DEPENDING ON THE AMOUNT OF PLAYERS (1st, 2nd, 3rd stage)
switch(IMG.Length)
{
case 24: CREATE24(); break;
case 12: CREATE12(); break;
case 4: CREATE4(); break;
}
}
public void CREATE24()
{
//BOOL FOR USED NUMBERS
bool[] CORRECT = new bool[24]; for(int i = 0; i < CORRECT.Length; i++) CORRECT[i] = false;
for (int NoP = 0; NoP < 24; NoP++)
{
int NUMBER = -1;
if (NoP < 18)//IF 18 IMAGES WERE ALREADY LOADED WE DON'T NEED TO RANDOMIZE LAST 6
{
while (true)
{
Random R = new Random();
NUMBER = R.Next(0, 24);
if (CORRECT[NUMBER]) continue;
else { CORRECT[NUMBER] = true; break; }
//IF THE NUMBERS IS ALREADY USED THEN RANDOMIZE AGAIN
}
//ADDING THE IMAGE TO THE LIST
if (NoP < 6)
{
imageList1.Images.Add(IMG[NUMBER]);
}
else if (NoP < 12)
{
imageList2.Images.Add(IMG[NUMBER]);
}
else if (NoP < 18)
{
imageList3.Images.Add(IMG[NUMBER]);
}
}
else
{
for (int i = 0; i < 24; i++ )
{
if (CORRECT[i] == false) imageList4.Images.Add(IMG[i]);
}
NoP = 23;
}
}
//DISPLAYING IMAGES
listView1.SmallImageList = imageList1;
listView2.SmallImageList = imageList2;
listView3.SmallImageList = imageList3;
listView4.SmallImageList = imageList4;
for (int j = 0; j < 6; j++)
{
listView1.Items.Add(new ListViewItem() { ImageIndex = j });
listView2.Items.Add(new ListViewItem() { ImageIndex = j });
listView3.Items.Add(new ListViewItem() { ImageIndex = j });
listView4.Items.Add(new ListViewItem() { ImageIndex = j });
}
}