Pharap

Cranium's Random Card Display Fully-functioning Beta

Aug 22nd, 2012
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.63 KB | None | 0 0
  1. -----------------------------------------------------
  2. --    This program was made,typed and conceived    --
  3. --                by Craniumkid22                  --
  4. -----------------------------------------------------
  5.  
  6. ----------------------------
  7. --(And debugged by Pharap)--
  8. --         A LOT          --
  9. ----------------------------
  10.  
  11. -------------------------------------------------------------------------------------------
  12. -------------------------------------Debug notes-------------------------------------------
  13. -------------------------------------------------------------------------------------------
  14. --               Fixed the problem with the "10" not displaying correctly                --
  15. --                     I created a title, with an ASCII generator.                       --
  16. --                                                                                       --
  17. -------------------------------------------------------------------------------------------
  18. ------------------------------------Derp goes here-----------------------------------------
  19. -------------------------------------------------------------------------------------------
  20.  
  21. --variables
  22. local symbol = {"A","2","3","4","5","6","7","8","9","10","J","Q","K"}
  23.  
  24. --screen functions
  25.  
  26. function sTitle()
  27. term.setCursorPos(1,15)
  28. print("   __    __   ___  ___    __  _    ___ _____ __ ")
  29. print("  / /'  / /\\ | |_)| | \\  ( ('| |  / / \\ | | ( ('")
  30. print("  \\_\\_,/_/--\\|_| \\|_|_/  _)_)|_|__\\_\\_/ |_| _)_)")
  31. end
  32.  
  33. function loser()
  34. term.clear()
  35. term.setCursorPos(1,5)
  36. print("          __      ___    __   ____ ____ ")
  37. print("          ||     // \\\\  (( \\ ||    || \\\\")
  38. print("          ||    ((   ))  \\\\  ||==  ||_//")
  39. print("          ||__|  \\\\_//  \\_)) ||___ || \\\\")
  40. sleep(3)
  41. term.clear()
  42. end
  43. function jackpot()
  44. for x = 1,5 do
  45. term.clear()
  46. sleep(.25)
  47. term.setCursorPos(1,5)
  48. print("     __  ___    ___ __ __ ____    ___   ______")
  49. print("     || // \\\\  //   || // || \\\\  // \\\\  | || |")
  50. print("     || ||=|| ((    ||<<  ||_// ((   ))   ||  ")
  51. print("  |__|| || ||  \\\\__ || \\\\ ||     \\\\_//    ||  ")
  52. sleep(.25)
  53. end
  54. end
  55.  
  56. function cardtop(x,y)
  57. term.setCursorPos(x,y)
  58. write([[ .------------. ]])
  59. term.setCursorPos(x,y+1)
  60. write([[| .----------. |]])
  61. term.setCursorPos(x,y+2)
  62. write([[| |          | |]])
  63. term.setCursorPos(x,y+3)
  64. write([[| | .------. | |]])
  65. term.setCursorPos(x,y+4)
  66. end
  67.  
  68. function cardbase(x,y)
  69. term.setCursorPos(x,y+8)
  70. write([[| | '------' | |]])
  71. term.setCursorPos(x,y+9)
  72. write([[| |          | |]])
  73. term.setCursorPos(x,y+10)
  74. write([[| '----------' |]])
  75. term.setCursorPos(x,y+11)
  76. write([[ '------------' ]])
  77. end
  78.  
  79. function numtop(n,x,y)
  80. if symbol[n] == "10" then
  81. term.setCursorPos(x,y+4)
  82. write([[| | |]]..symbol[n]..[[--. | | |]])
  83. else
  84. term.setCursorPos(x,y+4)
  85. write([[| | |]]..symbol[n]..[[.--. | | |]])
  86. end
  87. end
  88.  
  89. function numbase(n,x,y)
  90. if symbol[n] == "10" then
  91. term.setCursorPos(x,y+7)
  92. write([[| | | '--]]..symbol[n]..[[| | |]])
  93. else
  94. term.setCursorPos(x,y+7)
  95. write([[| | | '--']]..symbol[n]..[[| | |]])
  96. end
  97. end
  98.  
  99. function spade(x,y)
  100. term.setCursorPos(x,y+5)
  101. write([[| | | :/\: | | |]])
  102. term.setCursorPos(x,y+6)
  103. write([[| | | (__) | | |]])
  104. end
  105. function heart(x,y)
  106. term.setCursorPos(x,y+5)
  107. write([[| | | (\/) | | |]])
  108. term.setCursorPos(x,y+6)
  109. write([[| | | :\/: | | |]])
  110. end
  111. function club(x,y)
  112. term.setCursorPos(x,y+5)
  113. write([[| | | :(): | | |]])
  114. term.setCursorPos(x,y+6)
  115. write([[| | | ()() | | |]])
  116. end
  117. function diamond(x,y)
  118. term.setCursorPos(x,y+5)
  119. write([[| | | :/\: | | |]])
  120. term.setCursorPos(x,y+6)
  121. write([[| | | :\/: | | |]])
  122. end
  123. --action functions
  124.  
  125. function slot(pos)
  126. local c = math.random(1,4)
  127. local n = math.random(1,13)
  128. cardtop(pos,1)
  129. numtop(n,pos,1)
  130. if c == 1 then
  131. spade(pos,1)
  132. elseif c == 2 then
  133. heart(pos,1)
  134. elseif c == 3 then
  135. club(pos,1)
  136. elseif c == 4 then
  137. diamond(pos,1)
  138. end
  139. numbase(n,pos,1)
  140. cardbase(pos,1)
  141. return c,n
  142. end
  143.  
  144. function spin()
  145. for cnt = 1, 10 do
  146. slot(2)
  147. slot(18)
  148. slot(34)
  149. sleep(cnt/30)
  150. end
  151. end
  152.  
  153. function allsuitsmatch(result)
  154. return (result[1] == result[3] and result[3] == result[5] and result[5] ==result[1])
  155. end
  156.  
  157. function allvaluesmatch(result)
  158. return (result[2] == result[4] and result[4] == result[6] and result[6] ==result[2] )
  159. end
  160.  
  161. function isroyalflush(result)
  162. local Fresult = false
  163. if result[2] > 10 and result[4] > 10 and result[6] > 10 then
  164. if result[2] ~= result[4] and result[4] ~= result[6] and result[6] ~= result[2] then return true  -- royal flush discounting Ace
  165. end
  166. end
  167.  
  168. if result[2] == 1 and result[4] > 11 and result[6] > 11 and result[4] ~= result[6] then return true --royal flush including ace, condition 1
  169. elseif result[4] == 1 and result[6] > 11 and result[2] > 11 and result[6] ~= result[2] then return true --royal flush including ace, condition 2
  170. elseif result[6] == 1 and result[2] > 11 and result[4] > 11 and result[2] ~= result[4] then return true --royal flush including ace, condition 3
  171. end
  172.  
  173. return false
  174. end
  175.  
  176. function testwin(results)
  177. ------------------------------
  178. --  This function has been  --
  179. -- brought to you by Pharap --
  180. ------------------------------
  181. local value = 0
  182. if allsuitsmatch(results) then value = (100/4) end -- suits match
  183. if allvaluesmatch(results) then value = (100/13) end -- values match
  184. if allsuitsmatch(results) and allvaluesmatch(results) then value = ((100/4)/13) end --suits and values match
  185. if isroyalflush(results) then value = 1 end -- royal flush
  186. if isroyalflush(results) and allsuitsmatch(results) then value = 1000 end -- royal flush of all matching suits
  187. if isroyalflush(results) and allvaluesmatch(results) then value = "wtfiswrongwithyou,howthehelldidyoucausesuchabloodystupiderror" return "error"  end-- lol, like this would actually happen
  188. return value
  189. end
  190.  
  191. --code
  192.  
  193. function slots()
  194. term.clear()
  195. sTitle()
  196. slot(2)
  197. slot(18)
  198. slot(34)
  199. while true do
  200. local event, p1 = os.pullEvent()
  201.     if event == "key" then
  202.         if p1 == 28 then
  203.             spin()  
  204.             local s1, n1 = slot(2)
  205.             local s2, n2 = slot(18)
  206.             local s3, n3 = slot(34)
  207.             sleep(2)
  208.         --local results = {s1,n1,s2,n2,s3,n3}
  209.                 local results = {3,1,3,12,3,13}
  210.         local condition = testwin(results)
  211.             if condition == 0 then loser()
  212.             elseif condition == 1000 then
  213.                 jackpot()
  214.                                 term.clear()
  215.                                 sTitle()
  216.                                 slot(2)
  217.                                 slot(18)
  218.                                 slot(34)
  219.             end
  220.         elseif p1 == 14 then break
  221.         end
  222.     end
  223. end
  224. end
  225. --test
  226. slots()
Advertisement
Add Comment
Please, Sign In to add comment