I have a class called Game.cs and in the class I have the following code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Simon
{
class Game
{
public int[] TheArray = new int[1000];
private bool m_Play;
public bool Play
{
set { m_Play = value; }
get { return m_Play; }
}
public Game()
{
Random rnd = new Random();
for (int i = 0; i < 8; i++)
{
TheArray[i] = rnd.Next(0, 4); // between 0 and 3
}
}
}
}
I want to be able to call TheArray from my form. I want the loop to iterate based on the times I click button5 and then I want to click my buttons programmatically based on what my array returns. On my form I have 4 buttons called, button1,button2,button3 and button4.
Once I click on button5 my code needs to click the button based on the array each time it loops through TheArray
So far I have this:
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 Simon
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private Game m_game;
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("box1");
}
private void button2_Click(object sender, EventArgs e)
{
MessageBox.Show("box2");
}
private void button3_Click(object sender, EventArgs e)
{
MessageBox.Show("box3");
}
private void button4_Click(object sender, EventArgs e)
{
MessageBox.Show("box4");
}
private void button5_Click(object sender, EventArgs e)
{
// Determine which button to click based on TheArray
}
}
}
button5and then i want to click my buttons programmatically based on what my array returns..button5can stop collecting clicks?forloop can be rewritten in proper C#:TheArray = Enumerable.Range(0,8).Select(x => random.Next(0,4).ToArray();- and I strongly suggest using aList<int>instead.