473,396 Members | 1,916 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Hangman Game newbie

Hi

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
  1. using System;
  2. using System.Drawing;
  3. using System.Windows.Forms;
  4. using System.ComponentModel;
  5.  
  6. namespace MyHangMan
  7. {
  8.     /// <summary>
  9.     /// Description of MainForm.
  10.     /// </summary>
  11.     public class MainForm : System.Windows.Forms.Form
  12.     {
  13.         private System.Windows.Forms.Button NewGame;
  14.         private System.Windows.Forms.Button Quit;
  15.  
  16.  
  17.  
  18.         public MainForm()
  19.         {
  20.  
  21.             //
  22.             // The InitializeComponent() call is required for Windows Forms designer support.
  23.             //
  24.             InitializeComponent();
  25.  
  26.             //
  27.             // TODO: Add constructor code after the InitializeComponent() call.
  28.             //
  29.         }
  30.  
  31.         [STAThread]
  32.         public static void Main(string[] args)
  33.         {
  34.             Application.Run(new MainForm());
  35.         }
  36.  
  37.         #region Windows Forms Designer generated code
  38.         /// <summary>
  39.         /// This method is required for Windows Forms designer support.
  40.         /// Do not change the method contents inside the source code editor. The Forms designer might
  41.         /// not be able to load this method if it was changed manually.
  42.         /// </summary>
  43.         private void InitializeComponent() {
  44.             this.Quit = new System.Windows.Forms.Button();
  45.             this.NewGame = new System.Windows.Forms.Button();
  46.             this.SuspendLayout();
  47.             // 
  48.             // Quit
  49.             // 
  50.             this.Quit.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
  51.                         | System.Windows.Forms.AnchorStyles.Right)));
  52.             this.Quit.Location = new System.Drawing.Point(152, 128);
  53.             this.Quit.Name = "Quit";
  54.             this.Quit.Size = new System.Drawing.Size(152, 48);
  55.             this.Quit.TabIndex = 1;
  56.             this.Quit.Text = "Quit";
  57.             this.Quit.Click += new System.EventHandler(this.Button2Click);
  58.             // 
  59.             // NewGame
  60.             // 
  61.             this.NewGame.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
  62.                         | System.Windows.Forms.AnchorStyles.Right)));
  63.             this.NewGame.Location = new System.Drawing.Point(152, 48);
  64.             this.NewGame.Name = "NewGame";
  65.             this.NewGame.Size = new System.Drawing.Size(152, 48);
  66.             this.NewGame.TabIndex = 0;
  67.             this.NewGame.Text = "New Game";
  68.             this.NewGame.Click += new System.EventHandler(this.Button1Click);
  69.             // 
  70.             // MainForm
  71.             // 
  72.             this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  73.             this.ClientSize = new System.Drawing.Size(472, 573);
  74.             this.Controls.Add(this.Quit);
  75.             this.Controls.Add(this.NewGame);
  76.             this.Name = "MainForm";
  77.             this.Text = "MainForm";
  78.             this.ResumeLayout(false);
  79.         }
  80.         #endregion
  81.         void Button2Click(object sender, System.EventArgs e)
  82.         {
  83.             Application.Exit();
  84.         }
  85.  
  86.         void Button1Click(object sender, System.EventArgs e)
  87.         {
  88.             StickMan sm = new StickMan();
  89.             sm.Show();
  90.         }
  91.  
  92.  
  93.     }
  94. }
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Drawing;
  3. using System.Windows.Forms;
  4.  
  5. namespace MyHangMan
  6. {
  7.     /// <summary>
  8.     /// Description of Form1.
  9.     /// </summary>
  10.     public class StickMan : System.Windows.Forms.Form
  11.     {
  12.         private System.Windows.Forms.TextBox textBox1;
  13.                                 private System.Windows.Forms.TextBox textBox2;
  14.         private System.Windows.Forms.PictureBox pictureBox1;
  15.         private RandomWordManager TheWordManager;
  16.  
  17.         public StickMan()
  18.         {
  19.             //
  20.             // The InitializeComponent() call is required for Windows Forms designer support.
  21.             //
  22.             InitializeComponent();
  23.             TheWordManager = new RandomWordManager();
  24.             //
  25.             // TODO: Add constructor code after the InitializeComponent() call.
  26.             //
  27.         }
  28.  
  29.         #region Windows Forms Designer generated code
  30.         /// <summary>
  31.         /// This method is required for Windows Forms designer support.
  32.         /// Do not change the method contents inside the source code editor. The Forms designer might
  33.         /// not be able to load this method if it was changed manually.
  34.         /// </summary>
  35.         private void InitializeComponent() {
  36.             this.pictureBox1 = new System.Windows.Forms.PictureBox();
  37.                                                 this.textBox2 = new 
  38. System.Windows.Forms.TextBox();
  39.             this.textBox1 = new System.Windows.Forms.TextBox();
  40.             this.SuspendLayout();
  41.             // 
  42.             // pictureBox1
  43.             // 
  44.             this.pictureBox1.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(128)), ((System.Byte)(128)), ((System.Byte)(255)));
  45.             this.pictureBox1.Location = new System.Drawing.Point(152, 64);
  46.             this.pictureBox1.Name = "pictureBox1";
  47.             this.pictureBox1.Size = new System.Drawing.Size(360, 496);
  48.             this.pictureBox1.TabIndex = 0;
  49.             this.pictureBox1.TabStop = false;
  50.                         // 
  51.             // textBox2
  52.             // 
  53.             this.textBox2.Location = new System.Drawing.Point(208, 656);
  54.             this.textBox2.Name = "textBox2";
  55.             this.textBox2.Size = new System.Drawing.Size(248, 20);
  56.             this.textBox2.TabIndex = 2;
  57.             this.textBox2.Text = "";
  58.                                                 // 
  59.             // textBox1
  60.             // 
  61.             this.textBox1.Location = new System.Drawing.Point(208, 608);
  62.             this.textBox1.Name = "textBox1";
  63.             this.textBox1.PasswordChar = '*';
  64.             this.textBox1.ReadOnly = true;
  65.             this.textBox1.Size = new System.Drawing.Size(248, 20);
  66.             this.textBox1.TabIndex = 1;
  67.             this.textBox1.Tag = "";
  68.             this.textBox1.Text = "";
  69.  
  70.             // 
  71.             // StickMan
  72.             // 
  73.             this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  74.             this.ClientSize = new System.Drawing.Size(664, 749);
  75.             this.Controls.Add(this.textBox1);
  76.             this.Controls.Add(this.pictureBox1);
  77.             this.Name = "StickMan";
  78.             this.Tag = "";
  79.             this.Text = "Form1";
  80.             this.ResumeLayout(false);
  81.         }
  82.         #endregion
  83.  
  84.     }
  85. }


Expand|Select|Wrap|Line Numbers
  1. namespace MyHangMan
  2. {
  3.     using System;
  4.  
  5.     /// <summary>
  6.     /// Manages choosing a random word for playing hangman
  7.     /// </summary>
  8.     public class RandomWordManager
  9.     {
  10.         private Random RandomPick;
  11.         private string[] words = new string[] 
  12.     {
  13.         "zenith",
  14.         "zephyr",
  15.         "tennis",
  16.         "information",
  17.         "courier",
  18.         "basketball",
  19.         "distinction",
  20.         "telephone",
  21.         "hardship",
  22.         "congressional",
  23.         "fulfillment",
  24.         "courtesy",
  25.         "banana",
  26.         "programmer",
  27.         "canopy",
  28.         "friendship",
  29.         "heaven",
  30.         "chocolate",
  31.         "helicopter",
  32.         "financial",
  33.         "integration",
  34.         "lightheaded",
  35.         "mountainside",
  36.         "snowflake",
  37.         "socialism",
  38.         "monarchy",
  39.         "lucrative",
  40.         "bibliography",
  41.         "television",
  42.         "radiology",
  43.         "peppermint",
  44.         "parakeet",
  45.         "circulation",
  46.         "anatomical",
  47.         "zeppelin",
  48.         "xylophone",
  49.         "sequester",
  50.         "cantaloupe",
  51.         "bonanza",
  52.         "beekeeper",
  53.         "volleyball",
  54.         "massage",
  55.         "cheetah",
  56.         "environmental",
  57.         "horsdoeuvre",
  58.         "flashlight",
  59.         "butterfly",
  60.         "lightweight",
  61.         "extraordinary",
  62.         "hardship",
  63.         "salamander",
  64.         "salesmanship",
  65.         "gigantic",
  66.         "metamorphosis",
  67.         "popularity",
  68.         "punctuation",
  69.         "masquerade",
  70.         "footloose",
  71.         "fellowship",
  72.         "immigration",
  73.         "knowledge"
  74.     };
  75.  
  76.         public RandomWordManager()
  77.         {
  78.           DateTime aTime = new DateTime(1000);
  79.           aTime = DateTime.Now;
  80.           int nSeed = (int)(aTime.Millisecond);
  81.           RandomPick = new Random(nSeed);
  82.             // 
  83.             // TODO: Add Constructor Logic here
  84.             //
  85.         }
  86.  
  87.         public string Pick()
  88.         {
  89.           string newword = "";
  90.           int index = (int)(RandomPick.NextDouble() * words.GetUpperBound(0));
  91.           newword = words[index];
  92.           newword = newword.ToUpper();
  93.           return newword;
  94.         }
  95.     }
  96. }
Mar 21 '08 #1
0 1678

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: tigrfire | last post by:
So I'm trying to write a hangman game and the output is coming out a little strange. Here's my code thus far: #include <stdio.h> #include <string.h> #include <stdlib.h> #include <time.h> ...
18
ilikepython
by: ilikepython | last post by:
Hi I'm new to Python(3 to 4 days) and I'm working on a hangman game and have been having some problems that really annoy me. Here is part of my script: c = input('Would you like to play hangman?...
4
by: princessfrost | last post by:
Hi! I was wondering if someone could please help me with a hangman program that I have to do. I have some ideas, but really don't know what to do or where to start. My program needs to be:...
3
by: kaka_hunter | last post by:
#include <iostream> #include <fstream> using namespace std; const int max_tries=7; int earnings=0; int wordnum; void getword () { ifstream fin;
2
by: tesa | last post by:
I am not able to figure out how to make this work. I am trying to create a hangman game. I am in a basic javascripting class. I am to only use very basic code as you can see. I am able to use any...
5
by: av3rage | last post by:
I have never done any programming in my life but I have decided to go into engineering and in doing so we have to take this intro to programming course and I am pretty clueless. I am starting to get...
8
by: tidiz | last post by:
Hi, I'm trying to make a hangman game that should look like this: Welcome to Hangman ______ Your guess: c Success! __cc__ Your guess: b
1
by: AlexSc | last post by:
Hi to All, I am doing on a hangman project, Where this is a very simple one, where player would guess the word and if it is correct the letter would be from "-" to the correct letter once all...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.