944,029 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 12101
  • C# RSS
Oct 2nd, 2004
0

Building an array for dice program

Expand Post »
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

}
Similar Threads
Reputation Points: 10
Solved Threads: 1
Newbie Poster
Bill T is offline Offline
14 posts
since Jul 2004
Oct 3rd, 2004
0

Re: Building an array for dice program

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

How can you be on the right track with no code? lol
Moderator
Reputation Points: 322
Solved Threads: 28
The C# Man, Myth, Legend
Tekmaven is offline Offline
914 posts
since Feb 2002
Oct 14th, 2004
0

Re: Building an array for dice program

Umm...what are you tryng to do? To use an array (for example and array of int's) you just do this
C# Syntax (Toggle Plain Text)
  1. int[] dieSides = new int[6];
  2. dieSides[0] = 1;
  3. dieSides[1] = 2;
  4. etc..

and please use the [*code] and [/code] tags (without the *)
Reputation Points: 46
Solved Threads: 2
Junior Poster
Iron_Cross is offline Offline
117 posts
since Jul 2003

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: GetSelectedIndex Datagrid? Dropdownlist
Next Thread in C# Forum Timeline: Enabling Step Into (#c)





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC