I'm a newbie to C# and have been instructed to create a Hangman game in SharpDevelop. I don't want the answer to the full code, just some help along the way.
I have included my code thus far and at this stage would like to know how I can get the RandomWordManager, which I found on another site, to display a newly generated word as the textBox1 text when the user enters a new game.
I have enclosed tags around the two forms I have created(one for launch and another for entry into a new game) and then lastly the RandomWordManager class for creating random words for the hangman game.
I'm really not sure if this is on track so far but my idea is to have the correct guesses made by the user in textBox2 replace the special characters in textBox1 if they're correct. Can someone please give me some idea whether this is possible and how to get the RandomWordManager to occupy the textBox1 text on entry into the game?
Thanks a mil.
Expand|Select|Wrap|Line Numbers
- using System;
- using System.Drawing;
- using System.Windows.Forms;
- using System.ComponentModel;
- namespace MyHangMan
- {
- /// <summary>
- /// Description of MainForm.
- /// </summary>
- public class MainForm : System.Windows.Forms.Form
- {
- private System.Windows.Forms.Button NewGame;
- private System.Windows.Forms.Button Quit;
- public MainForm()
- {
- //
- // The InitializeComponent() call is required for Windows Forms designer support.
- //
- InitializeComponent();
- //
- // TODO: Add constructor code after the InitializeComponent() call.
- //
- }
- [STAThread]
- public static void Main(string[] args)
- {
- Application.Run(new MainForm());
- }
- #region Windows Forms Designer generated code
- /// <summary>
- /// This method is required for Windows Forms designer support.
- /// Do not change the method contents inside the source code editor. The Forms designer might
- /// not be able to load this method if it was changed manually.
- /// </summary>
- private void InitializeComponent() {
- this.Quit = new System.Windows.Forms.Button();
- this.NewGame = new System.Windows.Forms.Button();
- this.SuspendLayout();
- //
- // Quit
- //
- this.Quit.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.Quit.Location = new System.Drawing.Point(152, 128);
- this.Quit.Name = "Quit";
- this.Quit.Size = new System.Drawing.Size(152, 48);
- this.Quit.TabIndex = 1;
- this.Quit.Text = "Quit";
- this.Quit.Click += new System.EventHandler(this.Button2Click);
- //
- // NewGame
- //
- this.NewGame.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.NewGame.Location = new System.Drawing.Point(152, 48);
- this.NewGame.Name = "NewGame";
- this.NewGame.Size = new System.Drawing.Size(152, 48);
- this.NewGame.TabIndex = 0;
- this.NewGame.Text = "New Game";
- this.NewGame.Click += new System.EventHandler(this.Button1Click);
- //
- // MainForm
- //
- this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
- this.ClientSize = new System.Drawing.Size(472, 573);
- this.Controls.Add(this.Quit);
- this.Controls.Add(this.NewGame);
- this.Name = "MainForm";
- this.Text = "MainForm";
- this.ResumeLayout(false);
- }
- #endregion
- void Button2Click(object sender, System.EventArgs e)
- {
- Application.Exit();
- }
- void Button1Click(object sender, System.EventArgs e)
- {
- StickMan sm = new StickMan();
- sm.Show();
- }
- }
- }
Expand|Select|Wrap|Line Numbers
- using System;
- using System.Drawing;
- using System.Windows.Forms;
- namespace MyHangMan
- {
- /// <summary>
- /// Description of Form1.
- /// </summary>
- public class StickMan : System.Windows.Forms.Form
- {
- private System.Windows.Forms.TextBox textBox1;
- private System.Windows.Forms.TextBox textBox2;
- private System.Windows.Forms.PictureBox pictureBox1;
- private RandomWordManager TheWordManager;
- public StickMan()
- {
- //
- // The InitializeComponent() call is required for Windows Forms designer support.
- //
- InitializeComponent();
- TheWordManager = new RandomWordManager();
- //
- // TODO: Add constructor code after the InitializeComponent() call.
- //
- }
- #region Windows Forms Designer generated code
- /// <summary>
- /// This method is required for Windows Forms designer support.
- /// Do not change the method contents inside the source code editor. The Forms designer might
- /// not be able to load this method if it was changed manually.
- /// </summary>
- private void InitializeComponent() {
- this.pictureBox1 = new System.Windows.Forms.PictureBox();
- this.textBox2 = new
- System.Windows.Forms.TextBox();
- this.textBox1 = new System.Windows.Forms.TextBox();
- this.SuspendLayout();
- //
- // pictureBox1
- //
- this.pictureBox1.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(128)), ((System.Byte)(128)), ((System.Byte)(255)));
- this.pictureBox1.Location = new System.Drawing.Point(152, 64);
- this.pictureBox1.Name = "pictureBox1";
- this.pictureBox1.Size = new System.Drawing.Size(360, 496);
- this.pictureBox1.TabIndex = 0;
- this.pictureBox1.TabStop = false;
- //
- // textBox2
- //
- this.textBox2.Location = new System.Drawing.Point(208, 656);
- this.textBox2.Name = "textBox2";
- this.textBox2.Size = new System.Drawing.Size(248, 20);
- this.textBox2.TabIndex = 2;
- this.textBox2.Text = "";
- //
- // textBox1
- //
- this.textBox1.Location = new System.Drawing.Point(208, 608);
- this.textBox1.Name = "textBox1";
- this.textBox1.PasswordChar = '*';
- this.textBox1.ReadOnly = true;
- this.textBox1.Size = new System.Drawing.Size(248, 20);
- this.textBox1.TabIndex = 1;
- this.textBox1.Tag = "";
- this.textBox1.Text = "";
- //
- // StickMan
- //
- this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
- this.ClientSize = new System.Drawing.Size(664, 749);
- this.Controls.Add(this.textBox1);
- this.Controls.Add(this.pictureBox1);
- this.Name = "StickMan";
- this.Tag = "";
- this.Text = "Form1";
- this.ResumeLayout(false);
- }
- #endregion
- }
- }
Expand|Select|Wrap|Line Numbers
- namespace MyHangMan
- {
- using System;
- /// <summary>
- /// Manages choosing a random word for playing hangman
- /// </summary>
- public class RandomWordManager
- {
- private Random RandomPick;
- private string[] words = new string[]
- {
- "zenith",
- "zephyr",
- "tennis",
- "information",
- "courier",
- "basketball",
- "distinction",
- "telephone",
- "hardship",
- "congressional",
- "fulfillment",
- "courtesy",
- "banana",
- "programmer",
- "canopy",
- "friendship",
- "heaven",
- "chocolate",
- "helicopter",
- "financial",
- "integration",
- "lightheaded",
- "mountainside",
- "snowflake",
- "socialism",
- "monarchy",
- "lucrative",
- "bibliography",
- "television",
- "radiology",
- "peppermint",
- "parakeet",
- "circulation",
- "anatomical",
- "zeppelin",
- "xylophone",
- "sequester",
- "cantaloupe",
- "bonanza",
- "beekeeper",
- "volleyball",
- "massage",
- "cheetah",
- "environmental",
- "horsdoeuvre",
- "flashlight",
- "butterfly",
- "lightweight",
- "extraordinary",
- "hardship",
- "salamander",
- "salesmanship",
- "gigantic",
- "metamorphosis",
- "popularity",
- "punctuation",
- "masquerade",
- "footloose",
- "fellowship",
- "immigration",
- "knowledge"
- };
- public RandomWordManager()
- {
- DateTime aTime = new DateTime(1000);
- aTime = DateTime.Now;
- int nSeed = (int)(aTime.Millisecond);
- RandomPick = new Random(nSeed);
- //
- // TODO: Add Constructor Logic here
- //
- }
- public string Pick()
- {
- string newword = "";
- int index = (int)(RandomPick.NextDouble() * words.GetUpperBound(0));
- newword = words[index];
- newword = newword.ToUpper();
- return newword;
- }
- }
- }