| | |
Building an array for dice program
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jul 2004
Posts: 14
Reputation:
Solved Threads: 0
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
}
// 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
}
You have no code at all for an array there..
How can you be on the right track with no code? lol
How can you be on the right track with no code? lol
-Ryan Hoffman
.NET Specialist / Webmaster, Extended64.com.
Please do not email or PM me with support questions. Please direct them to the forums instead.
.NET Specialist / Webmaster, Extended64.com.
Please do not email or PM me with support questions. Please direct them to the forums instead.
Umm...what are you tryng to do? To use an array (for example and array of int's) you just do this
and please use the [*code] and [/code] tags (without the *)
C# Syntax (Toggle Plain Text)
int[] dieSides = new int[6]; dieSides[0] = 1; dieSides[1] = 2; etc..
and please use the [*code] and [/code] tags (without the *)
![]() |
Similar Threads
- Dice rolling program using graphic (C)
- Array in Dice Program (Java)
- Dice program (C)
Other Threads in the C# Forum
- Previous Thread: GetSelectedIndex Datagrid? Dropdownlist
- Next Thread: Enabling Step Into (#c)
| Thread Tools | Search this Thread |
.net access algorithm array asp barchart bitmap box broadcast buttons c# check checkbox client column combobox control conversion csharp custom database datagrid datagridview dataset datetime degrees development display draganddrop drawing encryption enum equation event excel file form format formbox forms formupdate function gdi+ httpwebrequest image index input install java label linux list listbox mandelbrot math mouseclick mysql networking operator packaging parse path photoshop picturebox pixelinversion post powerpacks programming radians regex remote remoting reporting richtextbox robot server sleep socket sql statistics stream string table text textbox thread time timer transform treeview update usercontrol validation visualstudio webbrowser wfa windows winforms wpf xml





