TNT_Nolan

ProbabilitySim 0.2Alpha

Mar 31st, 2016
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.28 KB | None | 0 0
  1. --Variables
  2.  
  3. --Functions
  4.  
  5. function init()
  6. drawMenu()
  7. menuInput = getMenuInput()
  8. if menuInput == "repeat" then
  9. init()
  10. end
  11. if menuInput == 1 then
  12. flipCoin()
  13. end
  14. if menuInput == 2 then
  15. rollDie()
  16. end
  17. if menuInput == 3 then
  18. throwCard()
  19. end
  20. if menuInput == 4 then
  21. exit()
  22. else
  23. init()
  24. end
  25. end
  26.  
  27. function exit()
  28. term.clear()
  29. term.setCursorPos(6,1)
  30. term.setTextColor(colors.green)
  31. term.write("Thank you for using probablity simulator!")
  32. term.setCursorPos(6,2)
  33. term.write("By TNT_Nolan!")
  34. term.setCursorPos(1,3)
  35. end
  36.  
  37. function startup()
  38. _img = paintutils.loadImage(shell.dir() .. "/probablitysimpaint")
  39. term.clear()
  40. term.setCursorPos(1,1)
  41. paintutils.drawImage(_img,1,1)
  42. term.setCursorPos(15,18)
  43. term.setTextColor(colors.green)
  44. term.setBackgroundColor(colors.black)
  45. term.write("Probablity Sim 0.2alpha by TNT_Nolan")
  46. sleep(2.5)
  47. init()
  48. end
  49.  
  50. function drawMenu()
  51. term.clear()
  52. term.setCursorPos(11,1)
  53. term.setTextColor(colors.white)
  54. print("Probality Sim by TNT_Nolan")
  55. term.setCursorPos(1,3)
  56. print("[1] Flip a coin")
  57. term.setCursorPos(1,4)
  58. print("[2] Roll a die")
  59. term.setCursorPos(1,5)
  60. print("[3] Throw a card")
  61. term.setCursorPos(1,6)
  62. print("[4] Exit")
  63. end
  64.  
  65. function getMenuInput()
  66. term.setCursorPos(1,19)
  67. term.setTextColor(colors.green)
  68. input = io.read()
  69. input = tonumber(input)
  70. if input > 0 and input < 5 then
  71. return input
  72. elseif input == 4 then
  73. return input
  74. else
  75. return "repeat"
  76. end
  77. end
  78.  
  79. function flipCoin()
  80. term.clear()
  81. term.setCursorPos(15,1)
  82. term.setTextColor(colors.lime)
  83. term.write("Flip a coin")
  84. term.setCursorPos(1,18)
  85. term.write("Flip a coin? [y/n]: ")
  86. input = read()
  87. if input == "n" then
  88. return
  89. elseif input == "y" then
  90. chance = probablity("coin")
  91. else
  92. flipCoin()
  93. end
  94. if chance == "tails" then
  95. term.setCursorPos(16,5)
  96. term.write("(T)")
  97. term.setCursorPos(16,7)
  98. term.write("Tails")
  99. sleep(2)
  100. elseif chance == "heads" then
  101. term.setCursorPos(16,5)
  102. term.write("(H)")
  103. term.setCursorPos(16,7)
  104. term.write("Heads")
  105. sleep(2)
  106. end
  107. flipCoin()
  108. end
  109.  
  110. function rollDie()
  111. term.clear()
  112. term.setCursorPos(15,1)
  113. term.setTextColor(colors.lime)
  114. term.write("Roll a die")
  115. term.setCursorPos(1,18)
  116. term.write("Roll a die? [y/n] ")
  117. input = read()
  118. if input == "n" then
  119. return
  120. elseif input == "y" then
  121. chance = probablity("die")
  122. else
  123. rollDie()
  124. end
  125. term.setCursorPos(1,5)
  126. if chance == 1 then
  127. print("+---+")
  128. print("| |")
  129. print("| o |")
  130. print("| |")
  131. print("+---+")
  132. print("One")
  133. elseif chance == 2 then
  134. print("+---+")
  135. print("|o |")
  136. print("| |")
  137. print("| o|")
  138. print("+---+")
  139. print("Two")
  140. elseif chance == 3 then
  141. print("+---+")
  142. print("| o|")
  143. print("| o |")
  144. print("|o |")
  145. print("+---+")
  146. print("Three")
  147. elseif chance == 4 then
  148. print("+---+")
  149. print("|o o|")
  150. print("| |")
  151. print("|o o|")
  152. print("+---+")
  153. print("Four")
  154. elseif chance == 5 then
  155. print("+---+")
  156. print("|o o|")
  157. print("| o |")
  158. print("|o o|")
  159. print("+---+")
  160. print("Five")
  161. elseif chance == 6 then
  162. print("+---+")
  163. print("|o o|")
  164. print("|o o|")
  165. print("|o o|")
  166. print("+---+")
  167. print("Six")
  168. end
  169. sleep(2)
  170. rollDie()
  171. end
  172. function throwCard()
  173. term.clear()
  174. term.setCursorPos(18,1)
  175. term.setTextColor(colors.lime)
  176. print("Throw a Card")
  177. term.setCursorPos(1,18)
  178. term.write("Throw a card? [y/n]: ")
  179. input = read()
  180. if input == "y" then
  181. cardnumber = probablity("cardnumber")
  182. elseif input == "n" then
  183. return
  184. else
  185. throwCard()
  186. end
  187. term.setCursorPos(1,6)
  188. if cardnumber == 2 then
  189. print("+----+")
  190. print("|2 2|")
  191. print("| |")
  192. print("|2 2|")
  193. print("+----+")
  194. elseif cardnumber == 3 then
  195. print("+----+")
  196. print("|3 3|")
  197. print("| |")
  198. print("|3 3|")
  199. print("+----+")
  200. elseif cardnumber == 4 then
  201. print("+----+")
  202. print("|4 4|")
  203. print("| |")
  204. print("|4 4|")
  205. print("+----+")
  206. elseif cardnumber == 5 then
  207. print("+----+")
  208. print("|5 5|")
  209. print("| |")
  210. print("|5 5|")
  211. print("+----+")
  212. elseif cardnumber == 6 then
  213. print("+----+")
  214. print("|6 6|")
  215. print("| |")
  216. print("|6 6|")
  217. print("+----+")
  218. elseif cardnumber == 7 then
  219. print("+----+")
  220. print("|7 7|")
  221. print("| |")
  222. print("|7 7|")
  223. print("+----+")
  224. elseif cardnumber == 8 then
  225. print("+----+")
  226. print("|8 8|")
  227. print("| |")
  228. print("|8 8|")
  229. print("+----+")
  230. elseif cardnumber == 9 then
  231. print("+----+")
  232. print("|9 9|")
  233. print("| |")
  234. print("|9 9|")
  235. print("+----+")
  236. elseif cardnumber == 10 then
  237. print("+----+")
  238. print("| |")
  239. print("| 10 |")
  240. print("| |")
  241. print("+----+")
  242. elseif cardnumber == 11 then
  243. print("+----+")
  244. print("|J J|")
  245. print("| |")
  246. print("|J J|")
  247. print("+----+")
  248. elseif cardnumber == 12 then
  249. print("+----+")
  250. print("|Q Q|")
  251. print("| |")
  252. print("|Q Q|")
  253. print("+----+")
  254. elseif cardnumber == 13 then
  255. print("+----+")
  256. print("|K K|")
  257. print("| |")
  258. print("|K K|")
  259. print("+----+")
  260. elseif cardnumber == 14 then
  261. print("+----+")
  262. print("| |")
  263. print("| A |")
  264. print("| |")
  265. print("+----+")
  266. end
  267. cardType = probablity("cardtype")
  268. if cardType == 1 then
  269. print("Clubs")
  270. end
  271. if cardType == 2 then
  272. print("Spades")
  273. end
  274. if cardType == 3 then
  275. print("Diamonds")
  276. end
  277. if cardType == 4 then
  278. print("Hearts")
  279. end
  280. sleep(2)
  281. throwCard()
  282. end
  283. function probablity(mode)
  284. if mode == "coin" then
  285. number = math.random(1,2)
  286. if number == 2 then
  287. return "heads"
  288. elseif number == 1 then
  289. return "tails"
  290. end
  291. end
  292. if mode == "die" then
  293. number = math.random(1,6)
  294. return number
  295. end
  296. if mode == "cardnumber" then
  297. number = math.random(2,14)
  298. return number
  299. end
  300. if mode == "cardtype" then
  301. number = math.random(1,4)
  302. return number
  303. end
  304. end
  305.  
  306.  
  307. startup()
Advertisement
Add Comment
Please, Sign In to add comment