im trying too build an array this is what i have so far am I on the right track?
// Fig. 6.10: RollDie.cs
// Using random number generation to simulate dice rolling.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO; // enables reading data from files
namespace Dice game
{
/// <summary>
/// form simulates the rolling of 5 dice,
/// and displays them
/// </summary>
public class RollDie : System.Windows.Forms.Form
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
private System.Windows.Forms.Button rollButton;
private System.Windows.Forms.Label dieLabel2;
private System.Windows.Forms.Label dieLabel1;
private System.Windows.Forms.Label dieLabel3;
private System.Windows.Forms.Label dieLabel4;
private System.Windows.Forms.Label dieLabel5;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Button button4;
private System.Windows.Forms.Button button5;
private Random randomNumber = new Random();
public RollDie()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if ( disposing )
{
if ( components != null )
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.dieLabel3 = new System.Windows.Forms.Label();
this.dieLabel4 = new System.Windows.Forms.Label();
this.dieLabel1 = new System.Windows.Forms.Label();
this.dieLabel2 = new System.Windows.Forms.Label();
this.rollButton = new System.Windows.Forms.Button();
this.dieLabel5 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.button4 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// dieLabel3
//
this.dieLabel3.Location = new System.Drawing.Point(15, 104);
this.dieLabel3.Name = "dieLabel3";
this.dieLabel3.Size = new System.Drawing.Size(72, 64);
this.dieLabel3.TabIndex = 4;
//
// dieLabel4
//
this.dieLabel4.Location = new System.Drawing.Point(111, 104);
this.dieLabel4.Name = "dieLabel4";
this.dieLabel4.Size = new System.Drawing.Size(72, 64);
this.dieLabel4.TabIndex = 5;
//
// dieLabel1
//
this.dieLabel1.Location = new System.Drawing.Point(15, 16);
this.dieLabel1.Name = "dieLabel1";
this.dieLabel1.Size = new System.Drawing.Size(72, 64);
this.dieLabel1.TabIndex = 0;
//
// dieLabel2
//
this.dieLabel2.Location = new System.Drawing.Point(111, 16);
this.dieLabel2.Name = "dieLabel2";
this.dieLabel2.Size = new System.Drawing.Size(72, 64);
this.dieLabel2.TabIndex = 1;
//
// rollButton
//
this.rollButton.Location = new System.Drawing.Point(8, 432);
this.rollButton.Name = "rollButton";
this.rollButton.Size = new System.Drawing.Size(96, 32);
this.rollButton.TabIndex = 12;
this.rollButton.Text = "Roll Die 1";
this.rollButton.Click += new System.EventHandler(this.rollButton_Click);
//
// dieLabel5
//
this.dieLabel5.Location = new System.Drawing.Point(224, 64);
this.dieLabel5.Name = "dieLabel5";
this.dieLabel5.Size = new System.Drawing.Size(72, 64);
this.dieLabel5.TabIndex = 13;
this.dieLabel5.Click += new System.EventHandler(this.dieLabel5_Click);
//
// button1
//
this.button1.Location = new System.Drawing.Point(8, 392);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(96, 32);
this.button1.TabIndex = 14;
this.button1.Text = "Roll Die2";
//
// button2
//
this.button2.Location = new System.Drawing.Point(8, 344);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(96, 32);
this.button2.TabIndex = 15;
this.button2.Text = "Roll Die 3";
//
// button3
//
this.button3.Location = new System.Drawing.Point(8, 256);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(96, 32);
this.button3.TabIndex = 16;
this.button3.Text = "Roll Die 5";
//
// button4
//
this.button4.Location = new System.Drawing.Point(8, 304);
this.button4.Name = "button4";
this.button4.Size = new System.Drawing.Size(96, 32);
this.button4.TabIndex = 17;
this.button4.Text = "Roll Die 4";
//
// RollDie
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(432, 478);
this.Controls.Add(this.button4);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.dieLabel5);
this.Controls.Add(this.rollButton);
this.Controls.Add(this.dieLabel4);
this.Controls.Add(this.dieLabel3);
this.Controls.Add(this.dieLabel2);
this.Controls.Add(this.dieLabel1);
this.Name = "RollDie";
this.Text = "RollDie";
this.ResumeLayout(false);
}
#endregion
// method called when rollButton clicked,
// passes labels to another method
protected void rollButton_Click(
object sender, System.EventArgs e )
{
// pass the labels to a method that will
// randomly assign a face to each die
DisplayDie( dieLabel1 );
DisplayDie( dieLabel2 );
DisplayDie( dieLabel3 );
DisplayDie( dieLabel4 );
} // end rollButton_Click
// determines image to be displayed by current die
public void DisplayDie( Label dieLabel )
{
int face = randomNumber.Next( 1, 7 );
// displays image specified by filename
dieLabel.Image = Image.FromFile(
Directory.GetCurrentDirectory() +
"\\images\\die" + face +".gif" );
}
/// <summary>
/// main entry point for application
/// </summary>
[STAThread]
static void Main()
{
Application.Run( new RollDie() );
}
private void dieLabel5_Click(object sender, System.EventArgs e)
{
}
} // end class RollDie
}