10 Replies - 1166 Views - Last Post: 07 October 2013 - 01:22 PM Rate Topic: -----

#1 st0mp3r  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 06-October 13

How can I create a game similar to hangman named GuessAWord

Posted 06 October 2013 - 09:50 PM

Hello everyone. I know how to create a GUI / Form but need help coding the following to make it work PLEASE PLEASE PLEASE help me think of the necessary code to solve this. Below are the instructions:

Create a game similar to Hangman named GuessAWord in which a player guesses letters to try to replicate a hidden word. Store at least eight words in an array, and randomly select select one to be the hidden word. Initially, display the hidden word using asterisks to represent each letter. Allow the user to guess letters to replace the asterisks in the hidden word until the user completes the entire word. If the user guesses a letter that is not in the hidden word, display the appropriate message. If the user guesses a letter that appears multiple times in the hidden word, make sure that each correct letter is placed.

THOSE ARE SOME COMPLICATED INSTRUCTIONS!!! PLEASE HELP ME. Thank you.

Is This A Good Question/Topic? 0
  • +

Replies To: How can I create a game similar to hangman named GuessAWord

#2 MrShoes  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 312
  • View blog
  • Posts: 488
  • Joined: 13-June 12

Re: How can I create a game similar to hangman named GuessAWord

Posted 06 October 2013 - 10:57 PM

Sorry, but we won't do your homework for you.

If you have any code that isn't quite working, we'll help with that. However, you're asking for somebody to do work for which you're going to be assessed. I suggest talking to your teacher for help if you're paying for an education.
Was This Post Helpful? 1
  • +
  • -

#3 st0mp3r  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 06-October 13

Re: How can I create a game similar to hangman named GuessAWord

Posted 06 October 2013 - 11:17 PM

I understand what you mean, but I'm not trying to have you do my homework for me. I just need to know how I would make the code work with a button... I will post the console code I have and see if you guys can help me figure out how I can make it work with a button. This class is a course substitution from adobe flash animation so I can graduate and be a web developer, not a c# programmer. I hope you understand. I will be back with my code and hopefully someone can help me figure out how to make it work with a button
Was This Post Helpful? 0
  • +
  • -

#4 st0mp3r  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 06-October 13

Re: How can I create a game similar to hangman named GuessAWord

Posted 06 October 2013 - 11:41 PM

Alrighty, I finally finished typing up my code for my GUI. But here's my problem, I'm having trouble completing this program. I need to check the users letter guess when they hit the guess button. And it's not doing that.

Here's what I have so far:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;


namespace GuessAWord
{
    public partial class Form1 : Form
    {
        int randomNumber;
        Random ranNumberGenerator;
        string ranWord;
        string[] words;
        const int MAXWORDS = 10;
       




        public Form1()
        {
            words = new string[MAXWORDS];


            ranNumberGenerator = new Random();


            words[0] = "dog";
            words[1] = "cat";
            words[2] = "fish";
            words[3] = "bird";
            words[4] = "elephant";
            words[5] = "tiger";
            words[6] = "lion";
            words[7] = "snake";
            words[8] = "walrus";
            words[9] = "owl";


            InitializeComponent();
        }


        private void startButton_Click(object sender, EventArgs e)
        {


            randomNumber = ranNumberGenerator.Next(0, 10);


            ranWord = words[randomNumber];


            mysteryLabel.Text = "";


            for (int i = 0; i < ranWord.Length; i++)
            {
                mysteryLabel.Text += "*";
            }


            feedbackLabel.Text = "";
            guessButton.Enabled = true;
            userTextbox.Select();


        }


        private void guessButton_Click(object sender, EventArgs e)
        {
           
           
                    }
                }
            }
         

Was This Post Helpful? 0
  • +
  • -

#5 MrShoes  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 312
  • View blog
  • Posts: 488
  • Joined: 13-June 12

Re: How can I create a game similar to hangman named GuessAWord

Posted 07 October 2013 - 12:39 AM

Well, in your event handler method "guessButton_Click", you'll just need to:
  • Check that a single character is in userTextBox.Text
  • Extract that character.
  • Enumerate through the characters in the word, and check if it matches (case agnostic) at each index.
  • If it does, uncover the character at that index.
  • If not, whatever penalty you want to apply.

You might want to use MessageBox.Show at the end of each check too, to feed back to the user.

This post has been edited by MrShoes: 07 October 2013 - 12:40 AM

Was This Post Helpful? 1
  • +
  • -

#6 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3569
  • View blog
  • Posts: 11,089
  • Joined: 05-May 12

Re: How can I create a game similar to hangman named GuessAWord

Posted 07 October 2013 - 05:34 AM

View Postst0mp3r, on 07 October 2013 - 02:17 AM, said:

This class is a course substitution from adobe flash animation so I can graduate and be a web developer, not a c# programmer. I hope you understand.

If that is the case, then write the code in Flash, and within your C# program, host a web browser control that will load up your .swf.

Seriously, though, the same set of problems you have to tackle to implement this in Flash is the same issues you'll need to cover when writing code in C#. If you could breakdown the problem to make it work in Flash, the same concepts will apply for a C# GUI. You can then comeback and be able to post questions specific to how to implement something rather than your original post that came across as "gimme the design".
Was This Post Helpful? 0
  • +
  • -

#7 AdamSpeight2008  Icon User is online

  • MrCupOfT
  • member icon


Reputation: 2262
  • View blog
  • Posts: 9,462
  • Joined: 29-May 08

Re: How can I create a game similar to hangman named GuessAWord

Posted 07 October 2013 - 07:36 AM

View Postst0mp3r, on 07 October 2013 - 05:50 AM, said:

THOSE ARE SOME COMPLICATED INSTRUCTIONS!!! PLEASE HELP ME. Thank you.

Not if you break it down. It to little chunks. Forget about a GUI for now, use a console application (like what you said you had written)
  • Create a game similar to Hangman named GuessAWord in which a player guesses letters to try to replicate a hidden word.
  • Store at least eight words in an array
  • Randomly select select one to be the hidden word.


  • Allow the user to guess letters to replace the asterisks in the hidden word
    User Input
  • .. until the user completes the entire word.
    So this suggests I would need some form of looping construct
  • If the user guesses a letter that is not in the hidden word, display the appropriate message.
  • If the user guesses a letter that appears multiple times in the hidden word, make sure that each correct letter is placed.
  • Initially, display the hidden word using asterisks to represent each letter.
    I could combine these last two as they are concerned with displaying the word to guess, based on the current guessed letters. So define a function to do that.


Now assemble to little piece together.
Was This Post Helpful? 0
  • +
  • -

#8 st0mp3r  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 06-October 13

Re: How can I create a game similar to hangman named GuessAWord

Posted 07 October 2013 - 11:40 AM

View PostSkydiver, on 07 October 2013 - 05:34 AM, said:

View Postst0mp3r, on 07 October 2013 - 02:17 AM, said:

This class is a course substitution from adobe flash animation so I can graduate and be a web developer, not a c# programmer. I hope you understand.

If that is the case, then write the code in Flash, and within your C# program, host a web browser control that will load up your .swf.

Seriously, though, the same set of problems you have to tackle to implement this in Flash is the same issues you'll need to cover when writing code in C#. If you could breakdown the problem to make it work in Flash, the same concepts will apply for a C# GUI. You can then comeback and be able to post questions specific to how to implement something rather than your original post that came across as "gimme the design".


I appreciate you're advice, but I can't do it that way because this is a c#.net class. Trust me, as much as I want to submit it in alternative format, it won't count. But thank you for you're advice and you're reply.

View PostMrShoes, on 07 October 2013 - 12:39 AM, said:

Well, in your event handler method "guessButton_Click", you'll just need to:
  • Check that a single character is in userTextBox.Text
  • Extract that character.
  • Enumerate through the characters in the word, and check if it matches (case agnostic) at each index.
  • If it does, uncover the character at that index.
  • If not, whatever penalty you want to apply.

You might want to use MessageBox.Show at the end of each check too, to feed back to the user.


Hello MrShoes,

I went to bed early last night so sorry about not getting back to you. Thanks for you're advice, I will try implementing what you're saying.

View PostAdamSpeight2008, on 07 October 2013 - 07:36 AM, said:

View Postst0mp3r, on 07 October 2013 - 05:50 AM, said:

THOSE ARE SOME COMPLICATED INSTRUCTIONS!!! PLEASE HELP ME. Thank you.

Not if you break it down. It to little chunks. Forget about a GUI for now, use a console application (like what you said you had written)
  • Create a game similar to Hangman named GuessAWord in which a player guesses letters to try to replicate a hidden word.
  • Store at least eight words in an array
  • Randomly select select one to be the hidden word.


  • Allow the user to guess letters to replace the asterisks in the hidden word
    User Input
  • .. until the user completes the entire word.
    So this suggests I would need some form of looping construct
  • If the user guesses a letter that is not in the hidden word, display the appropriate message.
  • If the user guesses a letter that appears multiple times in the hidden word, make sure that each correct letter is placed.
  • Initially, display the hidden word using asterisks to represent each letter.
    I could combine these last two as they are concerned with displaying the word to guess, based on the current guessed letters. So define a function to do that.


Now assemble to little piece together.


I hear you. Thanks for you're reply. Believe me, I'm trying. :wheelchair:
Was This Post Helpful? 0
  • +
  • -

#9 st0mp3r  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 06-October 13

Re: How can I create a game similar to hangman named GuessAWord

Posted 07 October 2013 - 12:04 PM

I havn't got this to work yet but I want to thank All of you guys for taking the time to help me. I tried the stack overflow community yesterday and was met with nothing but insults and hostility. The place gave me a very bad first impression, and left a bad taste in my mouth. Thank you for you're patience, advice, and kindness fellas.
Was This Post Helpful? 0
  • +
  • -

#10 AdamSpeight2008  Icon User is online

  • MrCupOfT
  • member icon


Reputation: 2262
  • View blog
  • Posts: 9,462
  • Joined: 29-May 08

Re: How can I create a game similar to hangman named GuessAWord

Posted 07 October 2013 - 12:45 PM

Typing in the code isn't the first step, it's thinking (no offence)

Imagine you are telling someone (like your granny) by voice how to workout which letters need to be an asterix in the output.
You would think about how to explain it won't you. Write out the basic instructions you would tell them, use simple English sentences and not code.
Was This Post Helpful? 0
  • +
  • -

#11 synlight  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 89
  • View blog
  • Posts: 582
  • Joined: 14-September 11

Re: How can I create a game similar to hangman named GuessAWord

Posted 07 October 2013 - 01:22 PM

It seems like you are hung up on what the program should do when the user clicks the guess button. So, like adam said, chop that down into baby steps.

Step 1. See what letter they entered..

Step 2. See if that letter is in the secret word..

And so on.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1