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 DiceSimulator
{
    public partial class Form1 : Form
    {
        StandardDie die1, die2, die3, die4, die5;
        Random rand;

        public Form1()
        {
            InitializeComponent();
            rand = new Random();
        }

        /// <summary>
        /// This is the Event Handler for the Form's Load event.
        /// </summary>
        /// <param name="sender">The object that triggered the event (not used in this application)</param>
        /// <param name="e">The arguments associated with this event (not used in this application)</param>
        private void Form1_Load(object sender, EventArgs e)
        {
            die1 = new StandardDie(rand);
            die2 = new StandardDie(rand);
            die3 = new StandardDie(rand);
            die4 = new StandardDie(rand);
            die5 = new StandardDie(rand);
        }

        /// <summary>
        /// This is the Event Handler for the Roll Dice button's Click event.
        /// </summary>
        /// <param name="sender">The object that triggered the event (not used in this application)</param>
        /// <param name="e">The arguments associated with this event (not used in this application)</param>
        private void btnRollDice_Click(object sender, EventArgs e)
        {
            pictureBox1.Image = die1.Roll;
            pictureBox2.Image = die2.Roll;
            pictureBox3.Image = die3.Roll;
            pictureBox4.Image = die4.Roll;
            pictureBox5.Image = die5.Roll;
        }

        private void pictureBox3_Click(object sender, EventArgs e)
        {

        }
    }
}

Recommended Answers

All 3 Replies

I doubt anyone is going to spoon-feed you with line-by-line explanation. If you know enough of c++ then you will recognize most of that code.

You would like to know whats about this code you pasted in here?
There is actually missing some part - the StandardDie class, but its not so important (mabye for you to understand it is).
Ok,
- 1st you declare 5 new variables of a custom class StandardDie.
- and declate a random class.
- in constructor of a form you instanitate the random variable (so now its ready to be used)
- in form Load event you instantiate 5 new variables of a custom class (and pass an argument of each).
- on a button click you assign to each pictureBox`s (to all 5) property "Image" some parameter - the one from the custom class (cound be an actual image, cant tell you now, because I dont see the actual StandardDie class declaration).

Hope it helps a bit.

Don't dictionaries usually call them "di's"?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.