473,898 Members | 3,120 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Hangman Game newbie

23 New Member
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 RandomWordManag er, 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 RandomWordManag er 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 RandomWordManag er 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 1696

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

Similar topics

5
15809
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> int hangman()
18
9217
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? Type y or n ') word = sample(('soccer', 'robbery', 'antibiotics'), 1) word = str(word) spaces = len(word) - 4 def hangman(): print '-------- '
4
2603
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: interactive with the user, menu based(like Menu: 1. Play hangman 2. Exit program), have a dictionaryand use a random method(create arrays of Strings or ListArray of Strings. e.g. : String dictionary = “apple”, “ball”, “cat”, “dog”, …..} minimum words...
3
2956
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
4042
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 online resources to help me. I have added alot of comments for what should be happening however is not happening. I also have a teacher that teaches us one way but then asks us to do things he has not taught. I am trying my very best. Any...
5
4195
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 the hang of how python works but to put my thoughts into the program to make it run is the confusing part for me. The task is to implement a Hangman game and the Program Specifications are: 1) Output a brief description of the game of hangman...
8
3747
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
2585
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 letter is correct they system will appear out good job u clear the game. I had done up the game and it work however i find mine is rather impractical, looking for better solution for it. please enlighten me in it. public static void...
0
9993
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9840
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11259
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10948
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10483
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9661
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5880
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
4295
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3305
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.