Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Module Module1
- Dim dont, line As Integer
- Dim playerchoice(1), players, randomselection, pass, result, name(1), p2, p1, playagain As String
- Dim singleplayer As Boolean
- Sub Main()
- Console.Clear()
- setup()
- Select Case players
- Case 1
- player1()
- Case 2
- player2()
- Case Else
- Console.ReadLine()
- End Select
- End Sub
- Sub player1()
- Lines()
- If p1 = 0 Then
- Console.Write("Please enter your name: ")
- name(0) = Console.ReadLine
- Lines()
- End If
- p2 = 0
- p1 = 1
- singleplayer = True
- Do Until playerchoice(0) = "rock" Or playerchoice(0) = "paper" Or playerchoice(0) = "scissors"
- Console.Write("Please enter either rock, paper or scissors: ")
- playerchoice(0) = Console.ReadLine.ToLower
- Loop
- Randomize() 'calls random integer
- playerchoice(1) = (CInt(Int((3 * Rnd()) + 1))) 'chooses random integer between 1 and 3
- If playerchoice(1) = 1 Then 'corresponding number with selection
- playerchoice(1) = "rock" 'value
- ElseIf playerchoice(1) = 2 Then 'corresponding number with selection
- playerchoice(1) = "paper" 'value
- ElseIf playerchoice(1) = 3 Then 'corresponding number with selection
- playerchoice(1) = "scissors" 'value
- End If
- Console.WriteLine("Computer chose: " & playerchoice(1)) 'prints random computer choice
- result = playerchoice(0) & playerchoice(1)
- winner()
- End Sub
- Sub player2()
- Lines()
- If p2 = 0 Then
- Console.Write("Please enter Player 1's name: ")
- name(0) = Console.ReadLine
- Console.Write("Please enter Player 2's name: ")
- name(1) = Console.ReadLine
- Lines()
- End If
- p1 = 0
- singleplayer = False
- p2 = 1
- Do Until playerchoice(0) = "rock" Or playerchoice(0) = "paper" Or playerchoice(0) = "scissors" 'Validation
- Console.Write(name(0) & ", enter either rock, paper or scissors: ") 'Asking for player 1's input
- playerchoice(0) = Console.ReadLine.ToLower 'Retrieving input & allowing upper and lower case inputs
- Loop
- Console.Clear() 'Clears console so player 2 can't see player 1's choice
- Lines()
- Do Until playerchoice(1) = "rock" Or playerchoice(1) = "paper" Or playerchoice(1) = "scissors" 'Validation
- Console.Write(name(1) & ", enter either rock, paper or scissors: ") 'Asking for player 2's input
- playerchoice(1) = Console.ReadLine.ToLower 'Retrieves input
- Loop
- result = playerchoice(0) + playerchoice(1) 'Calculates who wins
- winner() 'Switches to winner sub
- End Sub
- Sub winner()
- Select Case singleplayer
- Case True
- If result = "rockrock" Or result = "paperpaper" Or result = "scissorsscissors" Then
- Lines()
- Console.WriteLine("Draw! Try again.") 'Decides what is a draw
- Lines()
- Console.ReadLine()
- Main()
- ElseIf result = "rockscissors" Or result = "paperrock" Or result = "scissorspaper" Then 'Player 1 win
- Lines()
- Console.WriteLine(name(0) & " wins!")
- Lines()
- Do Until playagain = "yes" Or playagain = "no"
- Console.Write("Do you want to play again? (yes or no): ")
- playagain = Console.ReadLine.ToLower
- Loop
- If playagain = "yes" Then
- Main()
- Else
- Environment.Exit(0)
- End If
- Else
- Lines()
- Console.WriteLine("Computer wins!")
- Lines()
- Do Until playagain = "yes" Or playagain = "no"
- Console.Write("Do you want to play again? (yes or no): ")
- playagain = Console.ReadLine.ToLower
- Loop
- If playagain = "yes" Then
- Main()
- Else
- Environment.Exit(0)
- End If
- End If
- Case False
- If result = "rockrock" Or result = "paperpaper" Or result = "scissorsscissors" Then
- Lines()
- Console.WriteLine("Draw! Try again.") 'Decides what is a draw
- Lines()
- Console.ReadLine()
- Main()
- ElseIf result = "rockscissors" Or result = "paperrock" Or result = "scissorspaper" Then 'Player 1 win
- Lines()
- Console.WriteLine(name(0) & " wins!")
- Lines()
- Do Until playagain = "yes" Or playagain = "no"
- Console.WriteLine("Do you want to play again? (yes or no)")
- playagain = Console.ReadLine.ToLower
- Loop
- If playagain = "yes" Then
- Main()
- Else
- Environment.Exit(0)
- End If
- Else
- Lines()
- Console.WriteLine(name(1) & " wins!")
- Lines()
- Do Until playagain = "yes" Or playagain = "no"
- Console.WriteLine("Do you play again? (yes or no)")
- playagain = Console.ReadLine.ToLower
- Loop
- If playagain = "yes" Then
- Main()
- Else
- Environment.Exit(0)
- End If
- End If
- End Select
- End Sub
- Sub Lines()
- Console.ForegroundColor = ConsoleColor.DarkGreen
- Console.WriteLine("--------------------")
- Console.ForegroundColor = ConsoleColor.Gray
- End Sub
- Sub setup()
- singleplayer = False
- playerchoice(0) = Nothing
- playerchoice(1) = Nothing
- players = 0
- pass = 0
- playagain = Nothing
- result = Nothing
- Lines()
- Console.WriteLine("Rock Paper Scissors")
- Lines()
- Console.WriteLine("1. Single player")
- Console.WriteLine("2. Multiplayer")
- Console.WriteLine("3. Rules")
- Console.WriteLine("4. Settings")
- Lines()
- Console.Write("Please enter a number to chose an option: ")
- players = Console.ReadLine
- If players = Nothing Or IsNumeric(players) = False Then
- players = 0
- End If
- Do Until IsNumeric(players) And players = 1 Or players = 2
- If pass = 0 Then
- Lines()
- End If
- pass = 1
- Console.Write("Error, please enter a number: ")
- players = Console.ReadLine
- If players = Nothing Or IsNumeric(players) = False Then
- players = 0
- End If
- Loop
- End Sub
- End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement