TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Jonathan Crispe
NA
46
48.7k
C# dice game (imagelist)
Oct 9 2011 11:34 PM
i don't know how to do this:
After the Roll button is pressed, a timer will be enabled to generate random die rolls every 1/10 of a second. The images shown for each die will change with the random numbers generated, so the dice will appear to be rolling randomly.After about 10 random rolls, the timer will be stopped and the final roll and current score displayed.
public partial class Form1 : Form
{
Random m_rnd = new Random();
List<int> diceResults = new List<int>();
List<PictureBox> dice = new List<PictureBox>();
int diceTotal;
private int[] i_Array = new int[5] { 0, 1, 2, 3, 4 };
public Form1()
{
InitializeComponent();
pictureBox1.Image = imageList1.Images[i_Array[0]];
pictureBox2.Image = imageList1.Images[i_Array[1]];
pictureBox3.Image = imageList1.Images[i_Array[2]];
pictureBox4.Image = imageList1.Images[i_Array[3]];
pictureBox5.Image = imageList1.Images[i_Array[4]];
dice.Add(pictureBox1);
dice.Add(pictureBox2);
dice.Add(pictureBox3);
dice.Add(pictureBox4);
dice.Add(pictureBox5);
}
private void btn_roll_Click(object sender, EventArgs e)
{
pictureBox1.Image = imageList1.Images[m_rnd.Next(0, 6)];
pictureBox2.Image = imageList1.Images[m_rnd.Next(0, 6)];
pictureBox3.Image = imageList1.Images[m_rnd.Next(0, 6)];
pictureBox4.Image = imageList1.Images[m_rnd.Next(0, 6)];
pictureBox5.Image = imageList1.Images[m_rnd.Next(0, 6)];
diceTotal = 0;
diceResults.Clear();
for (int i = 0; i <= 4; i++)
{
diceResults.Add(m_rnd.Next(1, 6));
int imageNumber = diceResults[i] - 1;
dice[i].Image = this.imageList1.Images[imageNumber];
diceTotal += diceResults[i];
}
lbl_totalscore.Text = diceTotal.ToString();
}
private void timer1_Tick(object sender, EventArgs e)
{
}
private void btn_playagain_Click(object sender, EventArgs e)
{
pictureBox1.Image = imageList1.Images[i_Array[0]];
pictureBox2.Image = imageList1.Images[i_Array[1]];
pictureBox3.Image = imageList1.Images[i_Array[2]];
pictureBox4.Image = imageList1.Images[i_Array[3]];
pictureBox5.Image = imageList1.Images[i_Array[4]];
lbl_totalscore.Text = "0";
lbl_rollscore.Text = "0";
}
}
Reply
Answers (
3
)
Extraction From EXE
Vertical menu creation for web application