its a hangman game
- so far i have been able to think of a few such as
- a validation check that prevents numbers from being entered as word guesses & letters used as menu choices
-stopping the menu from comming up everytime after the option of guessing is choosen and until the word has been guess
- allowing the user to guess the word all at once
-importing words from the text file
i do not know how to code any of the above and would also like to know if you can think of anymore possible extensions a copy of the raw code is below
- so far i have been able to think of a few such as
- a validation check that prevents numbers from being entered as word guesses & letters used as menu choices
-stopping the menu from comming up everytime after the option of guessing is choosen and until the word has been guess
- allowing the user to guess the word all at once
-importing words from the text file
i do not know how to code any of the above and would also like to know if you can think of anymore possible extensions a copy of the raw code is below
VB.NET:
Module Module1
Dim NewPhrase As String
Dim PhraseHasBeenSet As Boolean
Dim PhraseGuessed As Boolean
Dim Choice As Integer
Dim IndividualLettersArray(20) As Char
Dim GuessStatusArray(20) As Char
Dim LettersGuessedArray(26) As Char
Dim NextGuessedLetter As Char
Dim Index As Integer
Sub DisplayMenu()
Console.WriteLine("__________________________________")
Console.WriteLine("")
Console.WriteLine("1. SETTER - Makes new word/phrase")
Console.WriteLine("")
Console.WriteLine("2. USER - Next letter guess")
Console.WriteLine("")
Console.WriteLine("5. End")
Console.WriteLine("")
End Sub
Sub Main()
PhraseHasBeenSet = False
Do
Call DisplayMenu()
Console.Write("Choice? ")
Choice = Console.ReadLine
If Choice = 1 Then
NewPhrase = GetNewPhrase()
SetUpGuessStatusArray(NewPhrase, IndividualLettersArray, GuessStatusArray)
PhraseHasBeenSet = True
End If
If Choice = 2 Then
If PhraseHasBeenSet = True Then
DisplayCurrentStatus(Len(NewPhrase), GuessStatusArray)
NextGuessedLetter = GetNextLetterGuess()
' is this letter present ?
For Index = 1 To Len(NewPhrase)
If NextGuessedLetter = IndividualLettersArray(Index) Then
GuessStatusArray(Index) = NextGuessedLetter
End If
Next
DisplayCurrentStatus(Len(NewPhrase), GuessStatusArray)
PhraseGuessed = AllLettersGuessedCorrectly(GuessStatusArray, NewPhrase, _
IndividualLettersArray)
If PhraseGuessed = True Then
Console.WriteLine("You have guessed correctly")
End If
Else
Console.WriteLine("The setter has not specified the word/phrase ..")
End If
End If
If Choice = 5 And PhraseGuessed = False Then
Console.WriteLine("You have not completed this word/phrase...Press return to exit")
Console.ReadLine()
End If
Loop Until Choice = 5
End Sub
Function GetNewPhrase() As String
Dim PhraseOK As Boolean
Dim ThisNewPhrase As String
Do
Console.Write("Key in the new phrase … (letters and any Spaces) ") : ThisNewPhrase =
Console.ReadLine()
If Len(ThisNewPhrase) < 10 Then
PhraseOK = False
Console.WriteLine("Not enough letters ... ")
' possible futher validation check(s)
Else
PhraseOK = True
GetNewPhrase = ThisNewPhrase
End If
Loop Until PhraseOK = True
End Function
Sub SetUpGuessStatusArray(ByVal NewPhrase As String, ByVal IndividualLettersArray() As Char, _
ByVal GuessStatusArray() As Char)
Dim Position As Integer
For Position = 1 To Len(NewPhrase)
IndividualLettersArray(Position) = Mid(NewPhrase, Position, 1)
If IndividualLettersArray(Position) = " " Then
GuessStatusArray(Position) = " "
Else
GuessStatusArray(Position) = "*"
End If
Next
End Sub
Sub DisplayCurrentStatus(ByVal PhraseLength As Byte, ByVal GuessStatusArray() As Char)
Dim Position As Integer
For Position = 1 To PhraseLength
Console.Write(GuessStatusArray(Position))
Next
Console.WriteLine()
End Sub
Function GetNextLetterGuess() As Char
Dim GuessedLetter As Char
Console.WriteLine()
Console.Write("Next guess ? ") : GuessedLetter = Console.ReadLine()
GetNextLetterGuess = GuessedLetter
End Function
Function AllLettersGuessedCorrectly(ByVal GuessStatusArray() As Char, _
ByVal NewPhrase As String, ByVal IndividualLettersArray() As Char) As Boolean
Dim Position As Integer
Dim MissingLetter As Boolean
MissingLetter = False
Position = 1
Do
If GuessStatusArray(Position) <> IndividualLettersArray(Position) Then
MissingLetter = True
Else
Position = Position + 1
End If
Loop Until MissingLetter = True Or Position = Len(NewPhrase) + 1
If MissingLetter = False Then
AllLettersGuessedCorrectly = True
Else
AllLettersGuessedCorrectly = False
End If
End Function
End Module