Thread: Hangman Game

  1. #1
    Registered User Mcdom34's Avatar
    Join Date
    Jun 2012
    Location
    North Royalton, Ohio, United States
    Posts
    22

    Hangman Game

    Hello! I'm programming a GUI version of hangman, using Windows Forms. Each button (letter) is directed to the same method, clickLetter. If a letter was clicked, I want that letter to become invisible, then preform appropriate instructions. Is there any way that I can wait for a button to be clicked, rather than a specific button (i.e.

    if button clicked...
    code

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    I'm not sure what you're asking. doesn't your button event handler fire for any of the buttons clicked? Then you could just use (sender as Button).Text to find out which letter it was.
    If you understand what you're doing, you're not learning anything.

  3. #3
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    You can wire up all of the buttons to the same click event. However this requires some type of switch or event args to indicate which button sent the message. If the sender is not important then this approach will work just fine.

    Alternatively you can override the WndProc of your window and receive the button click event there. But this is messier and means that every time any button on the window is clicked you will execute some logic. It is better to wire up a specific set of buttons to see if they have been clicked as opposed to every single button on the form.

  4. #4
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Building on VirtualAce's suggestion, you could read the text of each button to determine the letter that was clicked, if you have the Text set appropriately:
    Code:
    char letter = ((Button)sender).Text[0];
    Then to turn that letter invisible you can just:
    Code:
    ((Button)sender).Visible = false;
    If you understand what you're doing, you're not learning anything.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Hangman game
    By Dontgiveup in forum C++ Programming
    Replies: 1
    Last Post: 05-09-2011, 04:44 PM
  2. Help with hangman game.
    By astarialexi in forum C Programming
    Replies: 8
    Last Post: 03-13-2011, 04:04 AM
  3. !Help! Similar to hangman game
    By xxdevillxx in forum C Programming
    Replies: 2
    Last Post: 03-02-2011, 07:14 PM
  4. Hangman Game - Need Help!!
    By krobort in forum C++ Programming
    Replies: 3
    Last Post: 10-12-2006, 04:15 PM
  5. New game: Hangman!
    By abrege in forum Game Programming
    Replies: 6
    Last Post: 12-05-2002, 02:05 PM