ravneravn

Untitled

May 15th, 2013
74
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. mSide = "right"
  2. results = {}
  3. slotImage = {"seven", "heart", "club", "spade", "diamond", "bomb", "star"}
  4. --mon = peripheral.wrap(mSide)
  5. --mon.setTextScale(3)
  6. term.setBackgroundColor(colors.white)
  7. credits = tonumber(500)
  8. pot = tonumber(50)
  9. hold = false
  10. hold1 = false
  11. hold2 = false
  12. hold3 = false
  13. winner = {}
  14. winnerX = {}
  15. winnerY = {}
  16. prize = tonumber(0)
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23. function generateNumber()
  24. for i = 1,9 do
  25. randomNum = tonumber(math.random(1,7))
  26. table.insert(results, randomNum)
  27. end
  28. end
  29.  
  30.  
  31.  
  32.  
  33.  
  34. function randomNumber()
  35. number = tonumber(math.random(1,9))
  36. return number
  37. end
  38.  
  39.  
  40.  
  41.  
  42. function generateSlots()
  43. q = 1
  44. holdingScreen()
  45. stopWatch = os.startTimer(0.6)
  46. numberSpin = tonumber(math.random(30, 60))
  47. for i = 1, numberSpin do
  48. --while q ~= 4 do
  49. --if q == 4 then
  50. -- break
  51. --end
  52. if hold1 == true and hold2 == true and hold3 == true then
  53. break
  54. end
  55. term.clear()
  56. creditsScreen()
  57. potScreen()
  58. drawSlots()
  59. holdingScreen()
  60. event, timerID, x, y = os.pullEvent()
  61. if event == "timer" then
  62. stopWatch = 0
  63. stopWatch = os.startTimer(0.6)
  64. elseif event == "mouse_click" and x > 1 and x < 8 and y > 17 and y < 20 and hold1 == false then
  65. hold1 = true
  66. q = q + 1
  67. elseif event == "mouse_click" and x > 9 and x < 16 and y > 17 and y < 20 and hold2 == false then
  68. hold2 = true
  69. q = q + 1
  70. elseif event == "mouse_click" and x > 17 and x < 24 and y > 17 and y < 20 and hold3 == false then
  71. hold3 = true
  72. q = q + 1
  73. end
  74. end
  75. end
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82. function drawSlot(image, x, y)
  83. myImage = paintutils.loadImage(slotImage[image])
  84. paintutils.drawImage(myImage, x, y)
  85. term.setBackgroundColor(colors.white)
  86. end
  87.  
  88. function drawImage(image, x, y)
  89. myImage = paintutils.loadImage(image)
  90. paintutils.drawImage(myImage, x, y)
  91. term.setBackgroundColor(colors.white)
  92. end
  93.  
  94.  
  95.  
  96.  
  97.  
  98. function drawSlots()
  99. a = 1
  100. b = 1
  101. if hold1 == false then
  102. slot1 = tonumber(math.random(1,7))
  103. drawSlot(slot1, a, b)
  104. b = b + 6
  105.  
  106. slot2 = tonumber(math.random(1,7))
  107. drawSlot(slot2, a, b)
  108. b = b + 6
  109.  
  110. slot3 = tonumber(math.random(1,7))
  111. drawSlot(slot3, a, b)
  112. b = b + 6
  113. elseif hold1 == true then
  114. drawSlot(slot1, a, b)
  115. b = b + 6
  116. drawSlot(slot2, a, b)
  117. b = b + 6
  118. drawSlot(slot3, a, b)
  119. b = b + 6
  120. end
  121. a = a +8
  122. b = 1
  123.  
  124. if hold2 == false then
  125. slot4 = tonumber(math.random(1,7))
  126. drawSlot(slot4, a, b)
  127. b = b + 6
  128.  
  129. slot5 = tonumber(math.random(1,7))
  130. drawSlot(slot5, a, b)
  131. b = b + 6
  132.  
  133. slot6 = tonumber(math.random(1,7))
  134. drawSlot(slot6, a, b)
  135. b = b + 6
  136. elseif hold2 == true then
  137. drawSlot(slot4, a, b)
  138. b = b + 6
  139. drawSlot(slot5, a, b)
  140. b = b + 6
  141. drawSlot(slot6, a, b)
  142. b = b + 6
  143. end
  144. a= a + 8
  145. b = 1
  146.  
  147. if hold3 == false then
  148. slot7 = tonumber(math.random(1,7))
  149. drawSlot(slot7, a, b)
  150. b = b + 6
  151.  
  152. slot8 = tonumber(math.random(1,7))
  153. drawSlot(slot8, a, b)
  154. b = b + 6
  155.  
  156. slot9 = tonumber(math.random(1,7))
  157. drawSlot(slot9, a, b)
  158. b = b + 6
  159. elseif hold3 == true then
  160. drawSlot(slot7, a, b)
  161. b = b + 6
  162. drawSlot(slot8, a, b)
  163. b = b + 6
  164. drawSlot(slot9, a, b)
  165. b = b + 6
  166. end
  167. end
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174. function getWinner()
  175. if slot1 == slot2 and slot1 == slot3 then -- hvis den forreste række ned
  176. table.insert(winner, slot1)
  177. table.insert(winner, slot2)
  178. table.insert(winner, slot3)
  179. table.insert(winnerX, 1)
  180. table.insert(winnerX, 1)
  181. table.insert(winnerX, 1)
  182. table.insert(winnerY, 1)
  183. table.insert(winnerY, 7)
  184. table.insert(winnerY, 13)
  185. prize = prize + pot*4
  186. end
  187. if slot4 == slot5 and slot4 == slot6 then -- midterste ned
  188. table.insert(winner, slot4)
  189. table.insert(winner, slot5)
  190. table.insert(winner, slot6)
  191. table.insert(winnerX, 9)
  192. table.insert(winnerX, 9)
  193. table.insert(winnerX, 9)
  194. table.insert(winnerY, 1)
  195. table.insert(winnerY, 7)
  196. table.insert(winnerY, 13)
  197. prize = prize + pot*4
  198. end
  199. if slot7 == slot8 and slot7 == slot9 then -- yderste og ned
  200. table.insert(winner, slot7)
  201. table.insert(winner, slot8)
  202. table.insert(winner, slot9)
  203. table.insert(winnerX, 17)
  204. table.insert(winnerX, 17)
  205. table.insert(winnerX, 17)
  206. table.insert(winnerY, 1)
  207. table.insert(winnerY, 7)
  208. table.insert(winnerY, 13)
  209. prize = prize + pot*4
  210. end
  211. if slot1 == slot5 and slot1 == slot9 then -- fra øverste venstre hjørne og ned
  212. table.insert(winner, slot1)
  213. table.insert(winner, slot5)
  214. table.insert(winner, slot9)
  215. table.insert(winnerX, 1)
  216. table.insert(winnerX, 9)
  217. table.insert(winnerX, 17)
  218. table.insert(winnerY, 1)
  219. table.insert(winnerY, 7)
  220. table.insert(winnerY, 13)
  221. prize = prize + pot*3
  222. end
  223. if slot3 == slot5 and slot3 == slot7 then -- fra nederste venstre hjørne og op
  224. table.insert(winner, slot3)
  225. table.insert(winner, slot5)
  226. table.insert(winner, slot7)
  227. table.insert(winnerX, 1)
  228. table.insert(winnerX, 9)
  229. table.insert(winnerX, 17)
  230. table.insert(winnerY, 1)
  231. table.insert(winnerY, 7)
  232. table.insert(winnerY, 13)
  233. prize = prize + pot*3
  234. end
  235. if slot1 == slot4 and slot1 == slot7 then -- øverste hen
  236. table.insert(winner, slot1)
  237. table.insert(winner, slot4)
  238. table.insert(winner, slot7)
  239. table.insert(winnerX, 1)
  240. table.insert(winnerX, 9)
  241. table.insert(winnerX, 17)
  242. table.insert(winnerY, 1)
  243. table.insert(winnerY, 1)
  244. table.insert(winnerY, 1)
  245. prize = prize + pot*2
  246. end
  247. if slot2 == slot5 and slot2 == slot8 then -- midterste hen
  248. table.insert(winner, slot2)
  249. table.insert(winner, slot5)
  250. table.insert(winner, slot8)
  251. table.insert(winnerX, 1)
  252. table.insert(winnerX, 9)
  253. table.insert(winnerX, 17)
  254. table.insert(winnerY, 7)
  255. table.insert(winnerY, 7)
  256. table.insert(winnerY, 7)
  257. prize = prize + pot*2
  258. end
  259. if slot3 == slot6 and slot3 == slot9 then -- nederste hen
  260. table.insert(winner, slot3)
  261. table.insert(winner, slot6)
  262. table.insert(winner, slot9)
  263. table.insert(winnerX, 1)
  264. table.insert(winnerX, 9)
  265. table.insert(winnerX, 17)
  266. table.insert(winnerY, 13)
  267. table.insert(winnerY, 13)
  268. table.insert(winnerY, 13)
  269. prize = prize + pot*2
  270. end
  271. end
  272.  
  273.  
  274.  
  275.  
  276. function displayWinner()
  277. credits = credits + prize
  278. term.clear()
  279. creditsScreen()
  280. potScreen()
  281. for i = 1, #winner do
  282. drawSlot(winner[i], winnerX[i], winnerY[i])
  283. end
  284. end
  285.  
  286.  
  287.  
  288.  
  289. function waitClick()
  290. event = os.pullEvent("mouse_click")
  291. if event == "mouse_click" then
  292. notInUse2 = 0
  293. end
  294. end
  295.  
  296.  
  297.  
  298.  
  299.  
  300.  
  301. function bettingScreen()
  302. drawImage("betScreen", 32, 13)
  303. mWrite("+1", colors.lightGray, colors.black, 32,13)
  304. mWrite("+10", colors.lightGray, colors.black, 32,15)
  305. mWrite("-1", colors.lightGray, colors.black, 46,13)
  306. mWrite("-10", colors.lightGray, colors.black, 46,15)
  307. mWrite("Place", colors.gray, colors.white, 38, 15)
  308. end
  309.  
  310.  
  311.  
  312.  
  313.  
  314. function potScreen()
  315. drawImage("creditScreen", 32, 8)
  316. mWrite("Pot", colors.gray, colors.white, 39, 8)
  317. mWrite(pot, colors.white, colors.black, 39, 9)
  318. end
  319.  
  320.  
  321.  
  322.  
  323.  
  324. function creditsScreen()
  325. drawImage("creditScreen", 32, 3)
  326. mWrite("Credits", colors.gray, colors.white, 37, 3)
  327. mWrite(credits, colors.white, colors.black, 39, 4)
  328. end
  329.  
  330.  
  331.  
  332.  
  333.  
  334. function holdingScreen()
  335. drawImage("holdScreen", 2, 18)
  336. mWrite("Hold", colors.white, colors.black, 3, 19)
  337. mWrite("Hold", colors.white, colors.black, 11, 19)
  338. mWrite("Hold", colors.white, colors.black, 19, 19)
  339. end
  340.  
  341.  
  342.  
  343.  
  344.  
  345. function startScreen()
  346. term.clear()
  347. a = 1
  348. b = 1
  349. for slotNumber = 1,3 do
  350. drawSlot(2, a, b)
  351. a = a +8
  352. end
  353. a = 1
  354. b = b + 6
  355. for slotNumber = 1,3 do
  356. drawSlot(1, a, b)
  357. a = a +8
  358. end
  359. a= 1
  360. b = b + 6
  361. for slotNumber = 1,3 do
  362. drawSlot(3, a, b)
  363. a = a +8
  364. end
  365. end
  366.  
  367.  
  368.  
  369.  
  370.  
  371. function mWrite(message, background, text, x, y)
  372. term.setCursorPos(x,y)
  373. term.setBackgroundColor(background)
  374. term.setTextColor(text)
  375. term.write(message)
  376. end
  377.  
  378.  
  379.  
  380.  
  381.  
  382. function newGame()
  383. hold = false
  384. hold1 = false
  385. hold2 = false
  386. hold3 = false
  387. q = 1
  388. winner = 0
  389. winnerX = 0
  390. winnerY = 0
  391. winner = {}
  392. winnerX = {}
  393. winnerY = {}
  394. prize = 0
  395. end
  396.  
  397.  
  398.  
  399.  
  400.  
  401. -- ##### LOOP #####
  402. term.setTextColor(colors.black)
  403. term.clear()
  404. term.setCursorPos(4,4)
  405. term.write("Click to play")
  406. waitClick()
  407.  
  408. while true do
  409. startScreen()
  410. bettingScreen()
  411. creditsScreen()
  412. potScreen()
  413. waitClick()
  414. creditsScreen()
  415. potScreen()
  416. holdingScreen()
  417. generateNumber()
  418. generateSlots()
  419. sleep(3)
  420. getWinner()
  421. displayWinner()
  422. waitClick()
  423. term.clear()
  424. mWrite(pot, colors.white, colors.black, 1, 1)
  425. mWrite(credits, colors.white, colors.black, 1, 2)
  426. waitClick()
  427. newGame()
  428. end
RAW Paste Data