Hi guys,
I've written a little hangman game which works pretty good, but I want to add a Help button which will fill in a random letter from the word.
I use this bit of code to display the "_"
This bit is to work out if a letter picked is in the wordCode:Private Sub DisplayBlanks() Dim iLetter As Integer Dim iNumberOfLetters As Integer iNumberOfLetters = Len(sWord) For iLetter = 0 To iNumberOfLetters - 1 If Asc(Mid$(sWord, iLetter + 1, 1)) = vbKeySpace Then lblLetterOfWord(iLetter) = " " Else lblLetterOfWord(iLetter) = "_" End If Next iLetter End Sub
And this is for when a letter is clicked:Code:Private Function FindLetters(sLetterPick) As Integer Dim iLettersFound As Integer Dim iLetter As Integer For iLetter = 1 To Len(sWord) If lblLetterOfWord(iLetter - 1) = "_" And Mid$(sWord, iLetter, 1) = Chr$(sLetterPick) Then lblLetterOfWord(iLetter - 1) = Mid$(sWord, iLetter, 1) iLettersFound = iLettersFound + 1 End If Next iLetter FindLetters = iLettersFound End Sub
Code:Dim iLetterPicked As Integer Dim iLettersFound As Integer If imgLetter(Index).Visible = False Then Exit Sub iLetterPicked = Index + 65 imgLetter(Index).Visible = False iLettersFound = FindLetters(iLetterPicked) If iLettersFound = 0 Then iChancesRemaining = iChancesRemaining - 1 ShowBodyPart lblRemainingChances = iChancesRemaining Else bGameOver = DoPlayerWin If bGameOver Then ShowPlayerWins End If End If If iChancesRemaining = 0 Then bGameOver = True ShowPlayerLose End If
So, how would I get it to pick a random letter from the word and fill it in?




Reply With Quote