Hangman is a classic word-guessing game where players try to uncover a hidden word by guessing letters one at a time. Each incorrect guess adds a part to the hangman's gallows. The player wins if they guess the word before the hangman is fully drawn.
This enhanced version features a modern interface, responsive design, and interactive gameplay. Below the game, you'll find the VB.NET equivalent code for educational purposes.
Click on the letter buttons to guess which letters are in the hidden word
Each incorrect guess adds a part to the hangman drawing
Guess the word before the hangman is completed to win
Click "New Game" to start over with a new word
Public Class HangmanGame Private wordList As String() = {"PROGRAM", "VISUAL", "BASIC", "COMPUTER", "DEVELOPER", "APPLICATION"} Private secretWord As String Private guessedLetters As New List(Of Char)() Private maxAttempts As Integer = 6 Private attemptsLeft As Integer Public Sub New() StartNewGame() End Sub Public Sub StartNewGame() ' Select a random word Dim random As New Random() secretWord = wordList(random.Next(wordList.Length)) ' Reset game state guessedLetters.Clear() attemptsLeft = maxAttempts End Sub Public Function GuessLetter(letter As Char) As Boolean letter = Char.ToUpper(letter) ' Check if letter was already guessed If guessedLetters.Contains(letter) Then Return True ' Already guessed, no penalty End If ' Add to guessed letters guessedLetters.Add(letter) ' Check if letter is in the word If secretWord.Contains(letter) Then Return True Else attemptsLeft -= 1 Return False End If End Function Public Function GetDisplayWord() As String Dim display As New StringBuilder() For Each c As Char In secretWord If guessedLetters.Contains(c) Then display.Append(c & " ") Else display.Append("_ ") End If Next Return display.ToString().Trim() End Function Public Function IsWordGuessed() As Boolean For Each c As Char In secretWord If Not guessedLetters.Contains(c) Then Return False End If Next Return True End Function Public Function IsGameOver() As Boolean Return attemptsLeft <= 0 OrElse IsWordGuessed() End Function Public Function GetHangmanImageIndex() As Integer Return maxAttempts - attemptsLeft End Function End Class
This VB.NET implementation demonstrates the core logic of the Hangman game:
This backend logic can be connected to a Windows Forms UI to create a complete application.