|
-
Sep 27th, 2002, 10:46 AM
#1
Thread Starter
Hyperactive Member
Random Letters
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 "_"
Code:
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
This bit is to work out if a letter picked is in the word
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
And this is for when a letter is clicked:
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?
-
Sep 27th, 2002, 05:15 PM
#2
Thread Starter
Hyperactive Member
Anyone?
-
Sep 27th, 2002, 08:59 PM
#3
Fanatic Member
Here it is:
VB Code:
' Scrambler
' Function will scramble a word and return it
Function MakeScramble (SearchWord As String) As String
Dim tempStr As String
Dim i As Integer
Dim len As Integer
Dim char As String
' First reverse
tempStr = StrReverse (SearchWord)
' Then swap some random bits (1/3 times the size of the string)
len = Len(SearchWord)
For i = 1 To len-1
If Int(Rnd * 3) == 1 Then
char = Mid(tempStr, i, 1)
Mid(tempStr, i, 1) = Mid(tempStr, len - i, 1)
Mid(tempStr, len - i, 1) = char
End If
Next i
MakeScramble = tempStr
End Function
Just make a global variable and do a MakeScramble on it and just get the next number from that list that hasnt been chosen.
-
Sep 29th, 2002, 09:40 AM
#4
Thread Starter
Hyperactive Member
Thanks for that MoMad
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|