954,514 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Building an array for dice program

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
{
///
/// form simulates the rolling of 5 dice,
/// and displays them
///
public class RollDie : System.Windows.Forms.Form
{
///
/// Required designer variable.
///
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
//
}

///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if ( disposing )
{
if ( components != null )
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
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" );
}

///
/// main entry point for application
///
[STAThread]
static void Main()
{
Application.Run( new RollDie() );
}

private void dieLabel5_Click(object sender, System.EventArgs e)
{

}

} // end class RollDie

}

Bill T
Newbie Poster
14 posts since Jul 2004
Reputation Points: 10
Solved Threads: 1
 

You have no code at all for an array there..

How can you be on the right track with no code? lol

Tekmaven
Software Architect
Moderator
1,274 posts since Feb 2002
Reputation Points: 322
Solved Threads: 28
 

Umm...what are you tryng to do? To use an array (for example and array of int's) you just do this

int[] dieSides = new int[6];
dieSides[0] = 1;
dieSides[1] = 2;
etc..


and please use the [*code] and[/code] tags (without the *)

Iron_Cross
Junior Poster
117 posts since Jul 2003
Reputation Points: 46
Solved Threads: 2
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You