Advertisement
Guest User

Untitled

a guest
Jan 9th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.12 KB | None | 0 0
  1. Module Module1
  2. Dim fileName = "Scores.txt" 'store the file name of the text file
  3. Dim fileAppend As New System.IO.StreamWriter(fileName, True) 'open the file to write in append mode
  4.  
  5. Dim score As Integer
  6. Dim randomClass As New Random
  7. Dim R1 As Integer
  8. Dim R2 As Integer
  9. Dim Rollagain As Integer
  10. Dim R3 As Integer
  11. Dim name1 As String
  12. Dim name2 As String
  13. Dim max1 As Integer
  14. Dim max2 As Integer
  15. Dim player As String
  16. Dim temp As Integer
  17.  
  18. Sub Main()
  19. Dim user As String
  20. Dim password As String
  21.  
  22. Console.ForegroundColor = ConsoleColor.Cyan
  23.  
  24. Console.WriteLine("Username:")
  25. user = Console.ReadLine()
  26. Console.WriteLine("Password:")
  27. password = Console.ReadLine()
  28.  
  29. Console.ForegroundColor = ConsoleColor.White
  30.  
  31. If user = "Matthew" Then
  32. If password = "pass" Then
  33.  
  34. Console.WriteLine("Welcome")
  35. Console.ReadLine()
  36. initialise()
  37.  
  38.  
  39.  
  40. player = name1
  41. playergo()
  42. max1 = max1 + score
  43. Console.WriteLine(player & " has got " & max1 & " at the end of this round")
  44. Console.ReadLine()
  45.  
  46.  
  47. player = name2
  48. playergo()
  49. max2 = max2 + score
  50. Console.WriteLine(player & " has got " & max2 & " and the end of this round")
  51. Console.ReadLine()
  52.  
  53. player = name1
  54. playergo()
  55. max1 = max1 + score
  56. Console.WriteLine(player & " has got " & max1 & " at the end of this round")
  57. Console.ReadLine()
  58.  
  59.  
  60. player = name2
  61. playergo()
  62. max2 = max2 + score
  63. Console.WriteLine(player & " has got " & max2 & " and the end of this round")
  64. Console.ReadLine()
  65.  
  66. player = name1
  67. playergo()
  68. max1 = max1 + score
  69. Console.WriteLine(player & " has got " & max1 & " at the end of this round")
  70. Console.ReadLine()
  71.  
  72.  
  73. player = name2
  74. playergo()
  75. max2 = max2 + score
  76. Console.WriteLine(player & " has got " & max2 & " and the end of this round")
  77. Console.ReadLine()
  78.  
  79. player = name1
  80. playergo()
  81. max1 = max1 + score
  82. Console.WriteLine(player & " has got " & max1 & " at the end of this round")
  83. Console.ReadLine()
  84.  
  85.  
  86. player = name2
  87. playergo()
  88. max2 = max2 + score
  89. Console.WriteLine(player & " has got " & max2 & " and the end of this round")
  90. Console.ReadLine()
  91.  
  92. player = name1
  93. playergo()
  94. max1 = max1 + score
  95. Console.WriteLine(player & " has got " & max1 & " at the end of this round")
  96. Console.ReadLine()
  97.  
  98.  
  99. player = name2
  100. playergo()
  101. max2 = max2 + score
  102. Console.WriteLine(player & " has got " & max2 & " and the end of this round")
  103. Console.ReadLine()
  104.  
  105.  
  106. winner()
  107.  
  108.  
  109. Else
  110. Console.ForegroundColor = ConsoleColor.Red
  111.  
  112. Console.WriteLine("Wrong username or password")
  113. Console.ReadLine()
  114. End If
  115.  
  116. Console.ForegroundColor = ConsoleColor.Cyan
  117.  
  118. ElseIf user = "Joe" Then
  119. If password = "pass" Then
  120.  
  121. Console.WriteLine("Welcome")
  122. Console.ReadLine()
  123. initialise()
  124.  
  125. Console.ForegroundColor = ConsoleColor.White
  126.  
  127. player = name1
  128. playergo()
  129. max2 = max2 + score
  130. Console.WriteLine(player & " has got " & max1 & " at the end of this round")
  131. Console.ReadLine()
  132.  
  133.  
  134. player = name2
  135. playergo()
  136. max2 = max2 + score
  137. Console.WriteLine(player & " has got " & max2 & " and the end of this round")
  138. Console.ReadLine()
  139.  
  140. player = name1
  141. playergo()
  142. max1 = max1 + score
  143. Console.WriteLine(player & " has got " & max1 & " at the end of this round")
  144. Console.ReadLine()
  145.  
  146.  
  147. player = name2
  148. playergo()
  149. max2 = max2 + score
  150. Console.WriteLine(player & " has got " & max2 & " and the end of this round")
  151. Console.ReadLine()
  152.  
  153. player = name1
  154. playergo()
  155. max1 = max1 + score
  156. Console.WriteLine(player & " has got " & max1 & " at the end of this round")
  157. Console.ReadLine()
  158.  
  159.  
  160. player = name2
  161. playergo()
  162. max2 = max2 + score
  163. Console.WriteLine(player & " has got " & max2 & " and the end of this round")
  164. Console.ReadLine()
  165.  
  166. player = name1
  167. playergo()
  168. max1 = max1 + score
  169. Console.WriteLine(player & " has got " & max1 & " at the end of this round")
  170. Console.ReadLine()
  171.  
  172.  
  173. player = name2
  174. playergo()
  175. max2 = max2 + score
  176. Console.WriteLine(player & " has got " & max2 & " and the end of this round")
  177. Console.ReadLine()
  178.  
  179. player = name1
  180. playergo()
  181. max1 = max1 + score
  182. Console.WriteLine(player & " has got " & max1 & " at the end of this round")
  183. Console.ReadLine()
  184.  
  185.  
  186. player = name2
  187. playergo()
  188. max2 = max2 + score
  189. Console.WriteLine(player & " has got " & max2 & " and the end of this round")
  190. Console.ReadLine()
  191.  
  192.  
  193. winner()
  194.  
  195.  
  196.  
  197. Else
  198. Console.WriteLine("Wrong username or password")
  199. Console.ReadLine()
  200. End If
  201. End If
  202.  
  203.  
  204. End Sub
  205.  
  206. Sub initialise()
  207. Console.WriteLine("Player 1 enter your name:")
  208. name1 = Console.ReadLine()
  209. Console.WriteLine("Player 2 enter your name:")
  210. name2 = Console.ReadLine()
  211.  
  212. End Sub
  213.  
  214. Sub playergo()
  215. Dim rnd As New Random
  216.  
  217. Console.WriteLine(player & " rolled a dice")
  218. R1 = (rnd.Next(1, 6) + 1)
  219. R2 = (rnd.Next(1, 6) + 1)
  220. Console.WriteLine(player & " rolled a:" & R1 & "," & R2)
  221. Console.ReadLine()
  222.  
  223. R3 = R1 + R2
  224.  
  225. score = R3
  226.  
  227. If R1 = R2 Then
  228. Console.WriteLine("You rolled a double. You get to roll again")
  229. Rollagain = (rnd.Next(1, 6) + 1)
  230. Console.WriteLine(Rollagain)
  231. score = score + Rollagain
  232. Console.ReadLine()
  233. ElseIf R3 = "2" Then
  234. score = score + 10
  235.  
  236. ElseIf R3 = "4" Then
  237. score = score + 10
  238.  
  239. ElseIf R3 = "6" Then
  240. score = score + 10
  241.  
  242. ElseIf R3 = "8" Then
  243. score = score + 10
  244.  
  245. ElseIf R3 = "10" Then
  246. score = score + 10
  247.  
  248. ElseIf R3 = "12" Then
  249. score = score + 10
  250.  
  251. ElseIf R3 = "14" Then
  252. score = score + 10
  253.  
  254. ElseIf R3 = "16" Then
  255. score = score + 10
  256.  
  257. ElseIf R3 = "18" Then
  258. score = score + 10
  259.  
  260. Else
  261. If score > 0 Then
  262. score = score - 5
  263. Else
  264. score = score
  265. End If
  266. End If
  267.  
  268. Console.WriteLine("Your current score is: " & score)
  269. Console.ReadLine()
  270.  
  271. End Sub
  272.  
  273. Sub winner()
  274.  
  275. Console.ForegroundColor = ConsoleColor.Red
  276.  
  277.  
  278. Console.WriteLine("Lets see who won")
  279. Console.ReadLine()
  280.  
  281. Console.WriteLine(name1 & "'s score was " & max1)
  282. Console.WriteLine("and")
  283. Console.WriteLine(name2 & "'s score was " & max2)
  284. Console.ReadLine()
  285.  
  286. If max1 > max2 Then
  287. Console.WriteLine(name1 & " won!!")
  288. Console.ReadLine()
  289.  
  290. fileAppend.WriteLine(max1 & "," & name1) 'append 11 to the end of the text file
  291. Console.WriteLine("Highscore Updated") 'output the message
  292. fileAppend.Close() 'close the file
  293.  
  294. Console.WriteLine("*****HighScore*****")
  295. Console.ReadLine()
  296.  
  297. table()
  298.  
  299. ElseIf max1 < max2 Then
  300. Console.WriteLine(name2 & " won!!")
  301. Console.ReadLine()
  302.  
  303. Console.WriteLine(name2 & " won the game")
  304. Console.ReadLine()
  305.  
  306. fileAppend.WriteLine(max2 & "," & name2) 'append 11 to the end of the text file
  307. Console.WriteLine("Highscore Updated") 'output the message
  308. fileAppend.Close() 'close the file
  309. Console.ReadLine()
  310.  
  311. Console.WriteLine("*****HighScore*****")
  312. Console.ReadLine()
  313.  
  314. table()
  315.  
  316. Else
  317. Console.WriteLine("It was a draw")
  318. Console.WriteLine("One last round to see who won")
  319. Console.ReadLine()
  320. one_more()
  321.  
  322. End If
  323.  
  324. End Sub
  325.  
  326. Sub one_more()
  327. player = name1
  328. playergo()
  329. max1 = max1 + score
  330.  
  331. player = name2
  332. playergo()
  333. max2 = max2 + score
  334. End Sub
  335.  
  336. Sub table()
  337. Dim count As Integer = 6
  338. Dim score As String
  339. Dim best As Integer = 0
  340. Dim temp As Integer
  341. Dim theInput As String
  342.  
  343. Dim inputLength As Integer
  344.  
  345.  
  346. Dim fileName = "Scores.txt" 'store the file name of the text file
  347. Dim readFile As New System.IO.StreamReader(fileName, True) 'open the file for reading
  348.  
  349. While readFile.Peek <> -1 'while there is still another line in the file to read
  350. score = (readFile.ReadLine()) 'read the line from the file and output it
  351.  
  352. theInput = score 'store the input In the variable theInput
  353.  
  354. inputLength = theInput.Length 'count the number Of characters In theInput And store it In inputLength
  355. For x = 0 To 1 'loop from 0 to the number of characters in the input
  356. temp = (Microsoft.VisualBasic.Left(theInput, 3)) 'output the letter at position x in the string in theInput
  357.  
  358. x = x + 1
  359.  
  360. For z = 0 To 5
  361.  
  362. If temp > best Then
  363. count = count - 1
  364.  
  365. best = temp
  366.  
  367. Console.WriteLine(count & ". " & best) 'output the first 5 characters in the variable newWords
  368. Console.ReadLine()
  369.  
  370. z = z + 1
  371. Else
  372.  
  373. End If
  374.  
  375. Next
  376.  
  377. Next
  378.  
  379.  
  380.  
  381. End While
  382. readFile.Close() 'close the file
  383.  
  384. Console.ReadLine()
  385. End Sub
  386.  
  387.  
  388. End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement