THIS IS NOT FOR BEGINNERS
Hey guys,
I have been working on Visual basic a lot recently and would like to share my code.
Here it is:
Humid's Hangman
Code:
Module Hangman
'Author = Humid
Dim deductlife, arrayvalue, wordlength, random, i As Integer
Dim lives As Integer = 6
Dim word, wordset(8), invisible, answer As String
Dim inuse(25), character As Char
Sub Main()
Rules()
Words()
Randomiser()
Hide()
Game()
End Sub
Private Sub Rules()
lives = 6
deductlife = 1
Console.WriteLine(" Space Hangman Rules: ")
Console.WriteLine(" 1. You will have to guess letters of different planets in our solar system.")
Console.WriteLine(" 2. You will have 6 lives in total and everytime you guess wrong, a life will be deducted.")
Console.WriteLine(" 3. If you run out of lives then: `Rule 5")
Console.WriteLine(" 4. If you correct the guess planet then: `Rule 6")
Console.WriteLine(" 5. You are going back to planet earth.")
Console.WriteLine(" 6. You have won your space adventure.")
Console.WriteLine(" Press enter to contintue... ")
Console.ReadLine()
End Sub
Private Sub Words()
wordset(1) = "Mercury"
wordset(2) = "Venus"
wordset(3) = "Earth"
wordset(4) = "Mars"
wordset(5) = "Jupiter"
wordset(6) = "Saturn"
wordset(7) = "Uranus"
wordset(8) = "Neptune"
End Sub
Private Sub Randomiser()
Randomize()
random = CInt(Int((4 * Rnd()) + 0))
word = wordset(random)
End Sub
Private Sub Hide()
wordlength = Len(word)
For i As Integer = 1 To wordlength
invisible = invisible & "*"
Next
End Sub
Private Sub Game()
deductlife = 1
Console.Clear()
Console.WriteLine(wordset(random))
Console.WriteLine(" Please start geussing")
character = Console.ReadLine()
For i As Integer = 0 To 25
If character = inuse(i) Then
Alert()
End If
Next
AddingValue()
End Sub
Private Sub AddingValue()
arrayvalue = arrayvalue + 1
inuse(arrayvalue) = character
CorrectGuess()
End Sub
Private Sub CorrectGuess()
For i As Integer = 1 To wordlength
If character = Mid(word, i, 1) Then
Mid(invisible, i, 1) = character
deductlife = 0
End If
Next
If deductlife = 1 Then
lives = lives - 1
Console.WriteLine(" Your adventure is coming to an end! You have lost a life! ")
Console.WriteLine(" You have" & lives & "lives remaining. ")
Console.ReadLine()
End If
If invisible = word Then
Victory()
ElseIf lives = 0 Then
Defeat()
End If
Game()
End Sub
Private Sub Alert()
Console.WriteLine(" You have already used this letter and can not use it again.")
Console.ReadLine()
End Sub
Private Sub Victory()
Console.Clear()
Console.BackgroundColor = ConsoleColor.DarkBlue
Console.ForegroundColor = ConsoleColor.White
Console.WriteLine(" You have completed your space adventure, well done! ")
Console.WriteLine(" *_*")
Console.WriteLine(" \|/")
Console.WriteLine(" |")
Console.WriteLine(" / \")
Console.Clear()
Console.WriteLine("Enter `Y/N` if you would like to play again")
answer = Console.ReadLine()
If answer = "y" Or answer = "Y" Then
Main()
ElseIf answer = "n" Or answer = "N" Then
End
Else
Console.WriteLine("You must enter a valid answer")
Victory()
End If
End Sub
Private Sub Defeat()
Console.Clear()
Console.BackgroundColor = ConsoleColor.DarkGreen
Console.ForegroundColor = ConsoleColor.White
Console.WriteLine(" You have lost! ")
Console.WriteLine(" O_O")
Console.WriteLine(" /|\")
Console.WriteLine(" |")
Console.WriteLine(" / \")
Console.Clear()
Console.WriteLine("Enter `Y/N` if you would like to play again")
answer = Console.ReadLine()
If answer = "y" Or answer = "Y" Then
Main()
ElseIf answer = "n" Or answer = "N" Then
End
Else
Console.WriteLine("You must enter a valid answer")
Victory()
End If
End Sub
End Module