Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Module Module1
- Dim fileName = "Scores.txt" 'store the file name of the text file
- Dim fileAppend As New System.IO.StreamWriter(fileName, True) 'open the file to write in append mode
- Dim score As Integer
- Dim randomClass As New Random
- Dim R1 As Integer
- Dim R2 As Integer
- Dim Rollagain As Integer
- Dim R3 As Integer
- Dim name1 As String
- Dim name2 As String
- Dim max1 As Integer
- Dim max2 As Integer
- Dim player As String
- Dim temp As Integer
- Sub Main()
- Dim user As String
- Dim password As String
- Console.ForegroundColor = ConsoleColor.Cyan
- Console.WriteLine("Username:")
- user = Console.ReadLine()
- Console.WriteLine("Password:")
- password = Console.ReadLine()
- Console.ForegroundColor = ConsoleColor.White
- If user = "Matthew" Then
- If password = "pass" Then
- Console.WriteLine("Welcome")
- Console.ReadLine()
- initialise()
- player = name1
- playergo()
- max1 = max1 + score
- Console.WriteLine(player & " has got " & max1 & " at the end of this round")
- Console.ReadLine()
- player = name2
- playergo()
- max2 = max2 + score
- Console.WriteLine(player & " has got " & max2 & " and the end of this round")
- Console.ReadLine()
- player = name1
- playergo()
- max1 = max1 + score
- Console.WriteLine(player & " has got " & max1 & " at the end of this round")
- Console.ReadLine()
- player = name2
- playergo()
- max2 = max2 + score
- Console.WriteLine(player & " has got " & max2 & " and the end of this round")
- Console.ReadLine()
- player = name1
- playergo()
- max1 = max1 + score
- Console.WriteLine(player & " has got " & max1 & " at the end of this round")
- Console.ReadLine()
- player = name2
- playergo()
- max2 = max2 + score
- Console.WriteLine(player & " has got " & max2 & " and the end of this round")
- Console.ReadLine()
- player = name1
- playergo()
- max1 = max1 + score
- Console.WriteLine(player & " has got " & max1 & " at the end of this round")
- Console.ReadLine()
- player = name2
- playergo()
- max2 = max2 + score
- Console.WriteLine(player & " has got " & max2 & " and the end of this round")
- Console.ReadLine()
- player = name1
- playergo()
- max1 = max1 + score
- Console.WriteLine(player & " has got " & max1 & " at the end of this round")
- Console.ReadLine()
- player = name2
- playergo()
- max2 = max2 + score
- Console.WriteLine(player & " has got " & max2 & " and the end of this round")
- Console.ReadLine()
- winner()
- Else
- Console.ForegroundColor = ConsoleColor.Red
- Console.WriteLine("Wrong username or password")
- Console.ReadLine()
- End If
- Console.ForegroundColor = ConsoleColor.Cyan
- ElseIf user = "Joe" Then
- If password = "pass" Then
- Console.WriteLine("Welcome")
- Console.ReadLine()
- initialise()
- Console.ForegroundColor = ConsoleColor.White
- player = name1
- playergo()
- max2 = max2 + score
- Console.WriteLine(player & " has got " & max1 & " at the end of this round")
- Console.ReadLine()
- player = name2
- playergo()
- max2 = max2 + score
- Console.WriteLine(player & " has got " & max2 & " and the end of this round")
- Console.ReadLine()
- player = name1
- playergo()
- max1 = max1 + score
- Console.WriteLine(player & " has got " & max1 & " at the end of this round")
- Console.ReadLine()
- player = name2
- playergo()
- max2 = max2 + score
- Console.WriteLine(player & " has got " & max2 & " and the end of this round")
- Console.ReadLine()
- player = name1
- playergo()
- max1 = max1 + score
- Console.WriteLine(player & " has got " & max1 & " at the end of this round")
- Console.ReadLine()
- player = name2
- playergo()
- max2 = max2 + score
- Console.WriteLine(player & " has got " & max2 & " and the end of this round")
- Console.ReadLine()
- player = name1
- playergo()
- max1 = max1 + score
- Console.WriteLine(player & " has got " & max1 & " at the end of this round")
- Console.ReadLine()
- player = name2
- playergo()
- max2 = max2 + score
- Console.WriteLine(player & " has got " & max2 & " and the end of this round")
- Console.ReadLine()
- player = name1
- playergo()
- max1 = max1 + score
- Console.WriteLine(player & " has got " & max1 & " at the end of this round")
- Console.ReadLine()
- player = name2
- playergo()
- max2 = max2 + score
- Console.WriteLine(player & " has got " & max2 & " and the end of this round")
- Console.ReadLine()
- winner()
- Else
- Console.WriteLine("Wrong username or password")
- Console.ReadLine()
- End If
- End If
- End Sub
- Sub initialise()
- Console.WriteLine("Player 1 enter your name:")
- name1 = Console.ReadLine()
- Console.WriteLine("Player 2 enter your name:")
- name2 = Console.ReadLine()
- End Sub
- Sub playergo()
- Dim rnd As New Random
- Console.WriteLine(player & " rolled a dice")
- R1 = (rnd.Next(1, 6) + 1)
- R2 = (rnd.Next(1, 6) + 1)
- Console.WriteLine(player & " rolled a:" & R1 & "," & R2)
- Console.ReadLine()
- R3 = R1 + R2
- score = R3
- If R1 = R2 Then
- Console.WriteLine("You rolled a double. You get to roll again")
- Rollagain = (rnd.Next(1, 6) + 1)
- Console.WriteLine(Rollagain)
- score = score + Rollagain
- Console.ReadLine()
- ElseIf R3 = "2" Then
- score = score + 10
- ElseIf R3 = "4" Then
- score = score + 10
- ElseIf R3 = "6" Then
- score = score + 10
- ElseIf R3 = "8" Then
- score = score + 10
- ElseIf R3 = "10" Then
- score = score + 10
- ElseIf R3 = "12" Then
- score = score + 10
- ElseIf R3 = "14" Then
- score = score + 10
- ElseIf R3 = "16" Then
- score = score + 10
- ElseIf R3 = "18" Then
- score = score + 10
- Else
- If score > 0 Then
- score = score - 5
- Else
- score = score
- End If
- End If
- Console.WriteLine("Your current score is: " & score)
- Console.ReadLine()
- End Sub
- Sub winner()
- Console.ForegroundColor = ConsoleColor.Red
- Console.WriteLine("Lets see who won")
- Console.ReadLine()
- Console.WriteLine(name1 & "'s score was " & max1)
- Console.WriteLine("and")
- Console.WriteLine(name2 & "'s score was " & max2)
- Console.ReadLine()
- If max1 > max2 Then
- Console.WriteLine(name1 & " won!!")
- Console.ReadLine()
- fileAppend.WriteLine(max1 & "," & name1) 'append 11 to the end of the text file
- Console.WriteLine("Highscore Updated") 'output the message
- fileAppend.Close() 'close the file
- Console.WriteLine("*****HighScore*****")
- Console.ReadLine()
- table()
- ElseIf max1 < max2 Then
- Console.WriteLine(name2 & " won!!")
- Console.ReadLine()
- Console.WriteLine(name2 & " won the game")
- Console.ReadLine()
- fileAppend.WriteLine(max2 & "," & name2) 'append 11 to the end of the text file
- Console.WriteLine("Highscore Updated") 'output the message
- fileAppend.Close() 'close the file
- Console.ReadLine()
- Console.WriteLine("*****HighScore*****")
- Console.ReadLine()
- table()
- Else
- Console.WriteLine("It was a draw")
- Console.WriteLine("One last round to see who won")
- Console.ReadLine()
- one_more()
- End If
- End Sub
- Sub one_more()
- player = name1
- playergo()
- max1 = max1 + score
- player = name2
- playergo()
- max2 = max2 + score
- End Sub
- Sub table()
- Dim count As Integer = 6
- Dim score As String
- Dim best As Integer = 0
- Dim temp As Integer
- Dim theInput As String
- Dim inputLength As Integer
- Dim fileName = "Scores.txt" 'store the file name of the text file
- Dim readFile As New System.IO.StreamReader(fileName, True) 'open the file for reading
- While readFile.Peek <> -1 'while there is still another line in the file to read
- score = (readFile.ReadLine()) 'read the line from the file and output it
- theInput = score 'store the input In the variable theInput
- inputLength = theInput.Length 'count the number Of characters In theInput And store it In inputLength
- For x = 0 To 1 'loop from 0 to the number of characters in the input
- temp = (Microsoft.VisualBasic.Left(theInput, 3)) 'output the letter at position x in the string in theInput
- x = x + 1
- For z = 0 To 5
- If temp > best Then
- count = count - 1
- best = temp
- Console.WriteLine(count & ". " & best) 'output the first 5 characters in the variable newWords
- Console.ReadLine()
- z = z + 1
- Else
- End If
- Next
- Next
- End While
- readFile.Close() 'close the file
- Console.ReadLine()
- End Sub
- End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement