Advertisement
Guest User

Untitled

a guest
Jan 8th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.50 KB | None | 0 0
  1. Module Module1
  2.  
  3. Dim dont, line As Integer
  4. Dim playerchoice(1), players, randomselection, pass, result, name(1), p2, p1, playagain As String
  5. Dim singleplayer As Boolean
  6.  
  7. Sub Main()
  8.  
  9. Console.Clear()
  10. setup()
  11.  
  12. Select Case players
  13.  
  14. Case 1
  15.  
  16. player1()
  17.  
  18. Case 2
  19.  
  20. player2()
  21.  
  22. Case Else
  23.  
  24. Console.ReadLine()
  25.  
  26. End Select
  27.  
  28. End Sub
  29.  
  30. Sub player1()
  31.  
  32. Lines()
  33.  
  34. If p1 = 0 Then
  35.  
  36. Console.Write("Please enter your name: ")
  37. name(0) = Console.ReadLine
  38. Lines()
  39.  
  40. End If
  41.  
  42. p2 = 0
  43. p1 = 1
  44. singleplayer = True
  45.  
  46. Do Until playerchoice(0) = "rock" Or playerchoice(0) = "paper" Or playerchoice(0) = "scissors"
  47.  
  48. Console.Write("Please enter either rock, paper or scissors: ")
  49. playerchoice(0) = Console.ReadLine.ToLower
  50.  
  51. Loop
  52.  
  53. Randomize() 'calls random integer
  54. playerchoice(1) = (CInt(Int((3 * Rnd()) + 1))) 'chooses random integer between 1 and 3
  55.  
  56. If playerchoice(1) = 1 Then 'corresponding number with selection
  57.  
  58. playerchoice(1) = "rock" 'value
  59.  
  60. ElseIf playerchoice(1) = 2 Then 'corresponding number with selection
  61.  
  62. playerchoice(1) = "paper" 'value
  63.  
  64. ElseIf playerchoice(1) = 3 Then 'corresponding number with selection
  65.  
  66. playerchoice(1) = "scissors" 'value
  67.  
  68. End If
  69.  
  70. Console.WriteLine("Computer chose: " & playerchoice(1)) 'prints random computer choice
  71. result = playerchoice(0) & playerchoice(1)
  72. winner()
  73.  
  74. End Sub
  75.  
  76. Sub player2()
  77.  
  78. Lines()
  79.  
  80. If p2 = 0 Then
  81.  
  82. Console.Write("Please enter Player 1's name: ")
  83. name(0) = Console.ReadLine
  84. Console.Write("Please enter Player 2's name: ")
  85. name(1) = Console.ReadLine
  86.  
  87. Lines()
  88.  
  89. End If
  90.  
  91. p1 = 0
  92. singleplayer = False
  93. p2 = 1
  94.  
  95. Do Until playerchoice(0) = "rock" Or playerchoice(0) = "paper" Or playerchoice(0) = "scissors" 'Validation
  96.  
  97. Console.Write(name(0) & ", enter either rock, paper or scissors: ") 'Asking for player 1's input
  98. playerchoice(0) = Console.ReadLine.ToLower 'Retrieving input & allowing upper and lower case inputs
  99.  
  100. Loop
  101.  
  102. Console.Clear() 'Clears console so player 2 can't see player 1's choice
  103. Lines()
  104. Do Until playerchoice(1) = "rock" Or playerchoice(1) = "paper" Or playerchoice(1) = "scissors" 'Validation
  105.  
  106. Console.Write(name(1) & ", enter either rock, paper or scissors: ") 'Asking for player 2's input
  107. playerchoice(1) = Console.ReadLine.ToLower 'Retrieves input
  108.  
  109. Loop
  110.  
  111. result = playerchoice(0) + playerchoice(1) 'Calculates who wins
  112. winner() 'Switches to winner sub
  113.  
  114. End Sub
  115.  
  116. Sub winner()
  117.  
  118. Select Case singleplayer
  119.  
  120. Case True
  121.  
  122. If result = "rockrock" Or result = "paperpaper" Or result = "scissorsscissors" Then
  123.  
  124. Lines()
  125. Console.WriteLine("Draw! Try again.") 'Decides what is a draw
  126. Lines()
  127. Console.ReadLine()
  128. Main()
  129.  
  130. ElseIf result = "rockscissors" Or result = "paperrock" Or result = "scissorspaper" Then 'Player 1 win
  131.  
  132. Lines()
  133. Console.WriteLine(name(0) & " wins!")
  134. Lines()
  135.  
  136. Do Until playagain = "yes" Or playagain = "no"
  137.  
  138. Console.Write("Do you want to play again? (yes or no): ")
  139. playagain = Console.ReadLine.ToLower
  140.  
  141. Loop
  142.  
  143. If playagain = "yes" Then
  144.  
  145. Main()
  146.  
  147. Else
  148.  
  149. Environment.Exit(0)
  150.  
  151. End If
  152.  
  153. Else
  154.  
  155. Lines()
  156. Console.WriteLine("Computer wins!")
  157. Lines()
  158.  
  159. Do Until playagain = "yes" Or playagain = "no"
  160.  
  161. Console.Write("Do you want to play again? (yes or no): ")
  162. playagain = Console.ReadLine.ToLower
  163.  
  164. Loop
  165.  
  166. If playagain = "yes" Then
  167.  
  168. Main()
  169.  
  170. Else
  171.  
  172. Environment.Exit(0)
  173.  
  174. End If
  175.  
  176. End If
  177.  
  178. Case False
  179.  
  180. If result = "rockrock" Or result = "paperpaper" Or result = "scissorsscissors" Then
  181.  
  182. Lines()
  183. Console.WriteLine("Draw! Try again.") 'Decides what is a draw
  184. Lines()
  185. Console.ReadLine()
  186. Main()
  187.  
  188. ElseIf result = "rockscissors" Or result = "paperrock" Or result = "scissorspaper" Then 'Player 1 win
  189.  
  190. Lines()
  191. Console.WriteLine(name(0) & " wins!")
  192. Lines()
  193.  
  194. Do Until playagain = "yes" Or playagain = "no"
  195.  
  196. Console.WriteLine("Do you want to play again? (yes or no)")
  197. playagain = Console.ReadLine.ToLower
  198.  
  199. Loop
  200.  
  201. If playagain = "yes" Then
  202.  
  203. Main()
  204.  
  205. Else
  206.  
  207. Environment.Exit(0)
  208.  
  209. End If
  210.  
  211. Else
  212.  
  213. Lines()
  214. Console.WriteLine(name(1) & " wins!")
  215. Lines()
  216.  
  217. Do Until playagain = "yes" Or playagain = "no"
  218.  
  219. Console.WriteLine("Do you play again? (yes or no)")
  220. playagain = Console.ReadLine.ToLower
  221.  
  222. Loop
  223.  
  224. If playagain = "yes" Then
  225.  
  226. Main()
  227.  
  228. Else
  229.  
  230. Environment.Exit(0)
  231.  
  232. End If
  233.  
  234. End If
  235.  
  236. End Select
  237.  
  238. End Sub
  239.  
  240. Sub Lines()
  241.  
  242. Console.ForegroundColor = ConsoleColor.DarkGreen
  243. Console.WriteLine("--------------------")
  244. Console.ForegroundColor = ConsoleColor.Gray
  245.  
  246. End Sub
  247.  
  248. Sub setup()
  249.  
  250. singleplayer = False
  251. playerchoice(0) = Nothing
  252. playerchoice(1) = Nothing
  253. players = 0
  254. pass = 0
  255. playagain = Nothing
  256. result = Nothing
  257.  
  258. Lines()
  259. Console.WriteLine("Rock Paper Scissors")
  260. Lines()
  261. Console.WriteLine("1. Single player")
  262. Console.WriteLine("2. Multiplayer")
  263. Console.WriteLine("3. Rules")
  264. Console.WriteLine("4. Settings")
  265. Lines()
  266.  
  267. Console.Write("Please enter a number to chose an option: ")
  268. players = Console.ReadLine
  269.  
  270. If players = Nothing Or IsNumeric(players) = False Then
  271.  
  272. players = 0
  273.  
  274. End If
  275.  
  276. Do Until IsNumeric(players) And players = 1 Or players = 2
  277.  
  278. If pass = 0 Then
  279.  
  280. Lines()
  281.  
  282. End If
  283.  
  284. pass = 1
  285.  
  286. Console.Write("Error, please enter a number: ")
  287. players = Console.ReadLine
  288.  
  289. If players = Nothing Or IsNumeric(players) = False Then
  290.  
  291. players = 0
  292.  
  293. End If
  294.  
  295. Loop
  296.  
  297. End Sub
  298.  
  299. End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement