Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.IO
- Module Module1
- Dim TempList As New List(Of String)
- Dim UsersInput, Filepath As String
- Dim TempArray() As String
- Dim index As Integer = 0
- Dim TempVar As String
- Sub Main()
- intro(True, "To create a new account press (1) or if you want to login press (2)")
- Do Until UsersInput = "1" Or UsersInput = "2"
- intro(False, "Sorry, To create a new account press (1) or if you want to login press (2). These are the only 2 values that are accepted")
- Loop
- If UsersInput = "1" Then
- CreateNewAccount()
- Else
- login("Username:")
- End If
- Console.Clear()
- UsersInterface()
- Console.ReadLine()
- End Sub
- Sub UsersInterface()
- Console.WriteLine("Hello {0}", TempArray(0))
- Do Until UsersInput = "1" Or UsersInput = "2"
- intro(False, "If you would like to know your prevoius scores press (1). If you would like to play the game, then press (2)")
- Loop
- checkrange(UsersInput, 1, 2, "Sorry you can only type 1 or 2 ")
- If UsersInput = "1" Then
- PrintScores()
- UsersInput = "0"
- UsersInterface()
- Else
- Playgame(0)
- End If
- End Sub
- Sub Playgame(ByVal carrriedscore As Integer)
- Dim score As Integer = carrriedscore
- intro(False, "Which shape would you like to practice from rectange(1) , circle(2) or triangle(3)")
- Do Until UsersInput = "1" Or UsersInput = "2" Or UsersInput = "3"
- intro(False, "You can only type 1, 2 or 3. So which shape would you like to practice from rectange(1) , circle(2) or triangle(3)")
- Loop
- Dim wrongans1, wrongans2, wrongans3 As Integer
- wrongans1 = 0
- wrongans2 = 0
- wrongans3 = 0
- Randomize()
- While wrongans2 = wrongans1 Or wrongans3 = wrongans2 Or wrongans1 = wrongans3
- wrongans1 = CInt(Int((100 * Rnd()) + 1))
- wrongans2 = CInt(Int((100 * Rnd()) + 1))
- wrongans3 = CInt(Int((100 * Rnd()) + 1))
- End While
- TempList.Clear()
- TempList.Add(wrongans1)
- TempList.Add(wrongans2)
- TempList.Add(wrongans3)
- If UsersInput = 1 Then
- If shapes("rectangle") = True Then
- score += 2
- Else
- Try2(score)
- End If
- ElseIf UsersInput = 2 Then
- If shapes("circle") = True Then
- score += 2
- Else
- Try2(score)
- End If
- ElseIf UsersInput = 3 Then
- If shapes("triangle") = True Then
- score += 2
- Else
- Try2(score)
- End If
- End If
- Console.WriteLine("Your current score is now {0}", score)
- intro(False, "If you would like to play again press (1), if you would like logout and save your score press (2) or if you would like to see all your past scores press (3) ")
- checkrange(UsersInput, 1, 3, "Sorry you can only type 1, 2 or 3")
- If UsersInput = "1" Then
- Playgame(score)
- ElseIf UsersInput = "2" Then
- AddScoreToFile(score, Filepath)
- Environment.Exit(0)
- ElseIf usersInput = "3" Then
- PrintScores()
- intro(False, "If you would like to play again press (1), if you would like logout and save your score press (2)")
- checkrange(UsersInput, 1, 3, "Sorry you can only type 1 or 2")
- If UsersInput = "1" Then
- Playgame(score)
- ElseIf UsersInput = "2" Then
- AddScoreToFile(score, Filepath)
- Environment.Exit(0)
- End If
- End If
- End Sub
- Sub AddScoreToFile(ByRef score As String, ByRef filepath As String)
- Dim FileToWrite As New StreamWriter(filepath, True)
- Dim nowtime As String = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")
- Console.WriteLine()
- FileToWrite.WriteLine(score & " -Time this test was done at was " & nowtime)
- FileToWrite.Close()
- End Sub
- Sub Try2(ByRef score As Integer)
- If secondchance() = True Then
- score += 1
- Else
- Console.WriteLine("The correct answer was {0}", TempVar)
- End If
- End Sub
- Function secondchance() As Boolean
- intro(False, "Choose another answer")
- UsersInput = UsersInput.ToLower
- Do Until UsersInput = "a" Or UsersInput = "b" Or UsersInput = "c" Or UsersInput = "d"
- options("Sorry your input can only be a,b,c or d")
- Loop
- If TempList(Asc((UsersInput)) - Asc("a")) = TempVar Then
- Console.WriteLine("Well Done. This is the correct answer !!!")
- Return True
- Else
- Console.WriteLine("Sorry your choice {0} is incorrect", UsersInput)
- Return False
- End If
- End Function
- Function shapes(ByVal chosenshape As String) As Boolean
- Randomize()
- Dim length As Integer = CInt(Int((10 * Rnd()) + 1))
- Dim width As Integer = CInt(Int((10 * Rnd()) + 1))
- Dim ans As String = ""
- If chosenshape = "rectangle" Then
- ans = length * width
- TempList.Add(ans)
- ElseIf chosenshape = "circle" Then
- TempList.Add(Math.Pow(length, 2))
- ans = (Math.Pow(length, 2) & "π")
- For i = 0 To 3
- TempList(i) = (TempList(i) & "π")
- Next
- ElseIf chosenshape = "triangle" Then
- ans = length * width / 2
- TempList.Add(ans)
- End If
- TempVar = ans
- Console.Clear()
- UsersInput = UsersInput.ToLower
- If Not (chosenshape = "circle") Then
- Console.WriteLine("What is the area of a {0} with length {1} and height {2}", chosenshape, length, width)
- ElseIf chosenshape = "circle" Then
- Console.WriteLine("What is the area of a circle with radius {0} ", length)
- End If
- Do Until UsersInput = "a" Or UsersInput = "b" Or UsersInput = "c" Or UsersInput = "d"
- options("Sorry your input can only be a,b,c or d")
- Loop
- If (TempList(Asc((UsersInput)) - Asc("a")) = ans) Then
- Console.WriteLine("This is the correct answer")
- Return True
- Else
- Console.WriteLine("Sorry your choice {0} is incorrect", UsersInput)
- Return False
- End If
- End Function
- Sub options(ByVal output As String)
- Console.WriteLine(output)
- intro(False, "Is It a) " & TempList(0) & " B) " & TempList(1) & " C) " & TempList(2) & " D) " & TempList(3))
- End Sub
- Sub TransformFileToTempArray(ByVal filename As String)
- Dim FileToRead As New StreamReader(filename)
- ReDim TempArray(0)
- index = 0
- Do
- AddElementsToArray(FileToRead.ReadLine, TempArray, index)
- index += 1
- Loop Until FileToRead.EndOfStream
- FileToRead.Close()
- End Sub
- Sub PrintScores()
- TransformFileToTempArray(Filepath)
- If TempArray.Length - 1 <> 1 Then
- Console.WriteLine("Your scores are :")
- For i = 2 To TempArray.Length - 1
- Console.WriteLine(TempArray(i))
- Next
- Else
- Console.WriteLine("You have not done any questions yet")
- End If
- End Sub
- Sub CreateNewAccount()
- intro(False, "What would you like your username to be :")
- checkrange(UsersInput, "a", "z", "Sorry username must contain nothing other than letters")
- While (FileExist("C:" & UsersInput & ".txt"))
- Console.WriteLine("Sorry, this username has already been chosen")
- CreateNewAccount()
- End While
- File.Create("C:" & UsersInput & ".txt").Dispose()
- Filepath = "C:" & UsersInput & ".txt"
- Dim FileToWrite As New StreamWriter(Filepath, True)
- FileToWrite.WriteLine(UsersInput)
- password(5)
- FileToWrite.WriteLine(UsersInput)
- FileToWrite.Close()
- TransformFileToTempArray(Filepath)
- End Sub
- Sub password(ByVal LengthOfPass As Integer)
- intro(False, "New Password :")
- Do Until (UsersInput.Contains(0) Or UsersInput.Contains(1) Or UsersInput.Contains(2) Or UsersInput.Contains(3) Or UsersInput.Contains(4) Or UsersInput.Contains(5) Or UsersInput.Contains(6) Or UsersInput.Contains(7) Or UsersInput.Contains(8) Or UsersInput.Contains(9)) And UsersInput.Length >= LengthOfPass
- intro(False, "Sorry passsword must contain at least a number And must be more than " & LengthOfPass & " characters: ")
- Loop
- End Sub
- Sub login(ByVal output As String)
- intro(False, output)
- Dim username As String = UsersInput
- intro(False, "Password:")
- Dim password As String = UsersInput
- Filepath = "C:" & username & ".txt"
- If FileExist(Filepath) = True Then
- TransformFileToTempArray(Filepath)
- If TempArray(1) = password Then
- Console.WriteLine("Successfully logged In. Press Enter to continue")
- Console.ReadLine()
- Else
- login("Username or password is incorrect. Try again. Username:")
- End If
- Else
- login("Username or password is incorrect. Try again. Username:")
- End If
- End Sub
- Sub AddElementsToArray(ByVal StringToAdd As String, ByRef storage() As String, ByVal i As Integer)
- ReDim Preserve storage(i)
- storage(i) = StringToAdd
- End Sub
- Function FileExist(ByRef filename As String) As Boolean
- If File.Exists(filename) Then
- Return True
- Else Return False
- End If
- End Function
- Sub checkrange(ByVal input As String, ByVal min As String, ByVal max As String, ByVal output As String)
- For i = 0 To input.Length - 1
- If Not (Asc(input(i)) >= Asc(min) And Asc(input(i)) <= Asc(max)) Then
- intro(False, output)
- checkrange(UsersInput, min, max, output)
- Exit Sub
- End If
- Next
- End Sub
- Sub intro(ByVal begin As Boolean, ByVal output As String)
- If begin = True Then
- Console.WriteLine("This is a trainer for people who wish to practice with how to work out the area of Shapes")
- If output = "" Then
- intro(False, "")
- Else
- intro(False, output)
- End If
- ElseIf begin = False And output = "" Then
- Console.WriteLine(">>>>> Command :")
- UsersInput = Console.ReadLine
- ElseIf begin = False And Not (output = "") Then
- Console.WriteLine(output)
- UsersInput = Console.ReadLine
- End If
- End Sub
- End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement