I'm trying to exclude old results from a random number generator but I can't seem to get the variables to remember past two. I'm new to C# so there's probably some really simple solution I'm overlooking. It'd be super helpful if you guys could enlighten me.
I've already tried the code shown below, and I'm fairly sure I'm being stupid but I can't figure out why it's not working.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Timers;
using System.Threading.Tasks;
using System.IO;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void label_click(object sender, EventArgs e)
{
Close();
}
int mouseX = 0, mouseY = 0;
bool mouseDown;
private void panel1_MouseDown(object sender, MouseEventArgs e)
{
mouseDown = true;
}
private void panel1_MouseUp(object sender, MouseEventArgs e)
{
mouseDown = false;
}
private void GOBUTN_Paint(object sender, PaintEventArgs e)
{
}
//Sharing is caring: Communism goes here
private System.Windows.Forms.Timer timtim;
PictureBox Rooskie = new PictureBox();
int duplicheck = 0;
int duplicheck2 = 0;
int duplicheck3 = 0;
Label test = new Label();
private void boopthesnoot(object sender, EventArgs e)
{
dinging:
//yeah, random numbers here
Random rando = new Random();
int rand0 = rando.Next(1, 25);
test.Text = duplicheck + ", " + duplicheck2 + ", " + duplicheck3;
test.Font = new Font("Calibri", 20);
Controls.Add(test);
test.Location = new Point(0, 200);
test.Height = 1000;
test.Width = 1000;
if(duplicheck != rand0 && duplicheck2 != rand0 && duplicheck3 != rand0)
{
GOBUTTON.Hide();
pictureBox1.Hide();
pictureBox2.Hide();
//image code goes here
string filepath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\" + "resources" + "\\" + rand0 + ".jpg";
Rooskie.Width = 1160;
Rooskie.Height = 620;
Bitmap image = new Bitmap(filepath);
Rooskie.Dock = DockStyle.Fill;
Rooskie.Image = (Image)image;
Controls.Add(Rooskie);
Rooskie.SizeMode = PictureBoxSizeMode.CenterImage;
//Aww, it's that timer time
timtim = new System.Windows.Forms.Timer();
timtim.Tick += new EventHandler(clockfinish);
timtim.Interval = 5000;
timtim.Start();
}
else
{
goto dinging;
}
if (duplicheck != rand0)
{
duplicheck2 = duplicheck;
}
if(duplicheck != rand0)
{
duplicheck2 = duplicheck;
}
if (duplicheck2 != duplicheck)
{
duplicheck3 = duplicheck2;
}
duplicheck = rand0;
}
private void clockfinish(object sender, EventArgs e)
{
//CEASE THE TIMER AND GIVE ME BACK MY BUTTON
Rooskie.Image = null;
timtim.Stop();
GOBUTTON.Show();
pictureBox1.Show();
pictureBox2.Show();
}
The idea is that a random number generator picks an image and displays it. But I don't want the same image to show up multiple times in a row so this is supposed to give it a buffer i.e. If image 2 was displayed on the first button press, image 1 was displayed on the second, and image 3 was displayed on the third, the results should look like: duplicheck = 2 duplicheck2 = 1 duplicheck3 = 3