Advertisement
ravneravn

slot

May 14th, 2013
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.19 KB | None | 0 0
  1. mSide = "right"
  2. results = {}
  3. slotImage = {"seven", "heart", "club", "spade", "diamond", "bomb", "star"}
  4. slotLooserImage = {"looserSeven", "looserHeart", "looserClub", "looserSpade", "looserDiamond", "looserBomb", "looserStar"}
  5. --mon = peripheral.wrap(mSide)
  6. --mon.setTextScale(3)
  7. term.setBackgroundColor(colors.white)
  8. credits = 500 - ".0"
  9. pot = 50 - ".0"
  10. hold = false
  11. hold1 = false
  12. hold2 = false
  13. hold3 = false
  14. winner = {}
  15. winnerX = {}
  16. winnerY = {}
  17. prize = 0
  18. win = false
  19. c = 1
  20. d = 1
  21. e = 1
  22. slotWheel1 = {}
  23. slotWheel2 = {}
  24. slotWheel3 = {}
  25.  
  26.  
  27.  
  28. function activate()
  29. os.pullEvent("disk")
  30. end
  31.  
  32. function getCredits()
  33. if fs.exists("/disk/credits") == false then
  34. term.clear()
  35. mWrite("There is no credits on the disk.", 9, 9)
  36. mWrite("To get credits, go to the check-in counter", 4, 10)
  37. sleep(10)
  38. os.reboot()
  39. end
  40. f = fs.open("/disk/credits", "r")
  41. credits = f.readLine()
  42. f.close()
  43.  
  44. f = fs.open("startCredits", "w")
  45. f.write(credits)
  46. f.close()
  47. credits = tonumber(credits)
  48. end
  49.  
  50. function startingCredits()
  51. f = fs.open("startCredits", "r")
  52. startCredits = f.readLine()
  53. f.close()
  54. startCredits = tonumber(startCredits)
  55. end
  56.  
  57.  
  58.  
  59. function generateNumber()
  60. for i = 1,9 do
  61. randomNum = tonumber(math.random(1,7))
  62. table.insert(results, randomNum)
  63. end
  64. end
  65.  
  66.  
  67.  
  68.  
  69.  
  70. function randomNumber()
  71. number = tonumber(math.random(1,9))
  72. return number
  73. end
  74.  
  75.  
  76.  
  77.  
  78.  
  79. function slotsTable1()
  80. for i = 1, 260 do
  81. randomNum = tonumber(math.random(1,7))
  82. table.insert(slotWheel1, randomNum)
  83. end
  84. end
  85.  
  86.  
  87. function slotsTable2()
  88. for i = 1, 260 do
  89. randomNum = tonumber(math.random(1,7))
  90. table.insert(slotWheel2, randomNum)
  91. end
  92. end
  93.  
  94.  
  95. function slotsTable3()
  96. for i = 1, 260 do
  97. randomNum = tonumber(math.random(1,7))
  98. table.insert(slotWheel3, randomNum)
  99. end
  100. end
  101.  
  102.  
  103.  
  104. function makeSlotWheel()
  105. slotsTable1()
  106. slotsTable2()
  107. slotsTable3()
  108. end
  109.  
  110.  
  111.  
  112.  
  113. function generateSlots()
  114. holdingScreen()
  115. stopWatch = os.startTimer(0.12)
  116. numberSpin = tonumber(math.random(130, 260))
  117. for i = 1, numberSpin do
  118. if hold1 == true and hold2 == true and hold3 == true then
  119. break
  120. end
  121. term.clear()
  122. creditsScreen()
  123. potScreen()
  124. drawSlots()
  125. holdingScreen()
  126. event, timerID, x, y = os.pullEvent()
  127. if event == "timer" then
  128. stopWatch = 0
  129. stopWatch = os.startTimer(0.12)
  130. elseif event == "mouse_click" and x > 1 and x < 8 and y > 17 and y < 20 and hold1 == false then
  131. hold1 = true
  132. elseif event == "mouse_click" and x > 9 and x < 16 and y > 17 and y < 20 and hold2 == false then
  133. hold2 = true
  134. elseif event == "mouse_click" and x > 17 and x < 24 and y > 17 and y < 20 and hold3 == false then
  135. hold3 = true
  136. end
  137. end
  138. end
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146. function drawSlots()
  147. a = 1
  148. b = 1
  149. if hold1 == false then
  150. slot1 = slotWheel1[c+2]
  151. drawSlot(slot1, a, b)
  152. b = b + 6
  153. slot2 = slotWheel1[c+1]
  154. drawSlot(slot2, a, b)
  155. b = b + 6
  156. slot3 = slotWheel1[c]
  157. drawSlot(slot3, a, b)
  158. b = b + 6
  159. c = c + 1
  160. elseif hold1 == true then
  161. drawSlot(slot1, a, b)
  162. b = b + 6
  163. drawSlot(slot2, a, b)
  164. b = b + 6
  165. drawSlot(slot3, a, b)
  166. b = b + 6
  167. end
  168. a = a +8
  169. b = 1
  170.  
  171. if hold2 == false then
  172. slot4 = slotWheel2[d+2]
  173. drawSlot(slot4, a, b)
  174. b = b + 6
  175.  
  176. slot5 = slotWheel2[d+1]
  177. drawSlot(slot5, a, b)
  178. b = b + 6
  179.  
  180. slot6 = slotWheel2[d]
  181. drawSlot(slot6, a, b)
  182. b = b + 6
  183. d = d+1
  184. elseif hold2 == true then
  185. drawSlot(slot4, a, b)
  186. b = b + 6
  187. drawSlot(slot5, a, b)
  188. b = b + 6
  189. drawSlot(slot6, a, b)
  190. b = b + 6
  191. end
  192. a= a + 8
  193. b = 1
  194.  
  195. if hold3 == false then
  196. slot7 = slotWheel3[e+2]
  197. drawSlot(slot7, a, b)
  198. b = b + 6
  199.  
  200. slot8 = slotWheel3[e+1]
  201. drawSlot(slot8, a, b)
  202. b = b + 6
  203.  
  204. slot9 = slotWheel3[e]
  205. drawSlot(slot9, a, b)
  206. b = b + 6
  207. e = e +1
  208. elseif hold3 == true then
  209. drawSlot(slot7, a, b)
  210. b = b + 6
  211. drawSlot(slot8, a, b)
  212. b = b + 6
  213. drawSlot(slot9, a, b)
  214. b = b + 6
  215. end
  216. end
  217.  
  218.  
  219.  
  220.  
  221. function bombOrSeven()
  222. for i = 1, #winner do
  223. if winner[i] == 1 then
  224. prize = prize *2
  225. elseif winner[i] == 6 then
  226. prize = pot -(pot*2)
  227. win = false
  228. end
  229. end
  230. end
  231.  
  232.  
  233.  
  234. function getWinner()
  235. if slot1 == slot2 and slot1 == slot3 then -- hvis den forreste række ned
  236. table.insert(winner, slot1)
  237. table.insert(winner, slot2)
  238. table.insert(winner, slot3)
  239. table.insert(winnerX, 1)
  240. table.insert(winnerX, 1)
  241. table.insert(winnerX, 1)
  242. table.insert(winnerY, 1)
  243. table.insert(winnerY, 7)
  244. table.insert(winnerY, 13)
  245. prize = prize + pot*4
  246. win = true
  247. bombOrSeven()
  248. end
  249. if slot4 == slot5 and slot4 == slot6 then -- midterste ned
  250. table.insert(winner, slot4)
  251. table.insert(winner, slot5)
  252. table.insert(winner, slot6)
  253. table.insert(winnerX, 9)
  254. table.insert(winnerX, 9)
  255. table.insert(winnerX, 9)
  256. table.insert(winnerY, 1)
  257. table.insert(winnerY, 7)
  258. table.insert(winnerY, 13)
  259. prize = prize + pot*4
  260. win = true
  261. bombOrSeven()
  262. end
  263. if slot7 == slot8 and slot7 == slot9 then -- yderste og ned
  264. table.insert(winner, slot7)
  265. table.insert(winner, slot8)
  266. table.insert(winner, slot9)
  267. table.insert(winnerX, 17)
  268. table.insert(winnerX, 17)
  269. table.insert(winnerX, 17)
  270. table.insert(winnerY, 1)
  271. table.insert(winnerY, 7)
  272. table.insert(winnerY, 13)
  273. prize = prize + pot*4
  274. win = true
  275. bombOrSeven()
  276. end
  277. if slot1 == slot5 and slot1 == slot9 then -- fra øverste venstre hjørne og ned
  278. table.insert(winner, slot1)
  279. table.insert(winner, slot5)
  280. table.insert(winner, slot9)
  281. table.insert(winnerX, 1)
  282. table.insert(winnerX, 9)
  283. table.insert(winnerX, 17)
  284. table.insert(winnerY, 1)
  285. table.insert(winnerY, 7)
  286. table.insert(winnerY, 13)
  287. prize = prize + pot*2
  288. win = true
  289. bombOrSeven()
  290. end
  291. if slot3 == slot5 and slot3 == slot7 then -- fra nederste venstre hjørne og op
  292. table.insert(winner, slot3)
  293. table.insert(winner, slot5)
  294. table.insert(winner, slot7)
  295. table.insert(winnerX, 1)
  296. table.insert(winnerX, 9)
  297. table.insert(winnerX, 17)
  298. table.insert(winnerY, 1)
  299. table.insert(winnerY, 7)
  300. table.insert(winnerY, 13)
  301. prize = prize + pot*2
  302. win = true
  303. bombOrSeven()
  304. end
  305. if slot1 == slot4 and slot1 == slot7 then -- øverste hen
  306. table.insert(winner, slot1)
  307. table.insert(winner, slot4)
  308. table.insert(winner, slot7)
  309. table.insert(winnerX, 1)
  310. table.insert(winnerX, 9)
  311. table.insert(winnerX, 17)
  312. table.insert(winnerY, 1)
  313. table.insert(winnerY, 1)
  314. table.insert(winnerY, 1)
  315. prize = prize + math.ceil(pot*2)
  316. win = true
  317. bombOrSeven()
  318. end
  319. if slot2 == slot5 and slot2 == slot8 then -- midterste hen
  320. table.insert(winner, slot2)
  321. table.insert(winner, slot5)
  322. table.insert(winner, slot8)
  323. table.insert(winnerX, 1)
  324. table.insert(winnerX, 9)
  325. table.insert(winnerX, 17)
  326. table.insert(winnerY, 7)
  327. table.insert(winnerY, 7)
  328. table.insert(winnerY, 7)
  329. prize = prize + math.ceil(pot*2)
  330. win = true
  331. bombOrSeven()
  332. end
  333. if slot3 == slot6 and slot3 == slot9 then -- nederste hen
  334. table.insert(winner, slot3)
  335. table.insert(winner, slot6)
  336. table.insert(winner, slot9)
  337. table.insert(winnerX, 1)
  338. table.insert(winnerX, 9)
  339. table.insert(winnerX, 17)
  340. table.insert(winnerY, 13)
  341. table.insert(winnerY, 13)
  342. table.insert(winnerY, 13)
  343. prize = prize + math.ceil(pot*2)
  344. win = true
  345. bombOrSeven()
  346. end
  347. end
  348.  
  349.  
  350.  
  351.  
  352. function displayWinner()
  353. credits = credits + prize
  354. if win == false then
  355. credits = credits - pot
  356. end
  357. term.clear()
  358. creditsScreen()
  359. potScreen()
  360. for i = 1, #winner do
  361. drawSlot(winner[i], winnerX[i], winnerY[i])
  362. end
  363. end
  364.  
  365.  
  366.  
  367.  
  368. function waitClick()
  369. event = os.pullEvent("mouse_click")
  370. if event == "mouse_click" then
  371. notInUse2 = 0
  372. end
  373. end
  374.  
  375.  
  376.  
  377. ----------- SCREENS -------------
  378.  
  379.  
  380. function startScreen2()
  381. term.setTextColor(colors.black)
  382. term.setBackgroundColor(colors.black)
  383. drawImage("background", 1,1)
  384. term.setTextColor(colors.black)
  385. term.setBackgroundColor(colors.black)
  386. drawImage("logoSeven2", 12, 2)
  387. term.setTextColor(colors.black)
  388. term.setBackgroundColor(colors.black)
  389. drawImage("logoSeven2", -12, 2)
  390. term.setTextColor(colors.black)
  391. term.setBackgroundColor(colors.black)
  392. drawImage("logoSeven2", 0, 1)
  393. term.setTextColor(colors.black)
  394. term.setBackgroundColor(colors.black)
  395. end
  396.  
  397. function startScreen4()
  398. term.setTextColor(colors.black)
  399. term.setBackgroundColor(colors.black)
  400. drawImage("background", 1,1)
  401. term.setTextColor(colors.black)
  402. term.setBackgroundColor(colors.black)
  403. drawImage("logoSeven4", 12, 2)
  404. term.setTextColor(colors.black)
  405. term.setBackgroundColor(colors.black)
  406. drawImage("logoSeven4", -12, 2)
  407. term.setTextColor(colors.black)
  408. term.setBackgroundColor(colors.black)
  409. drawImage("logoSeven4", 0, 1)
  410. term.setTextColor(colors.black)
  411. term.setBackgroundColor(colors.black)
  412. end
  413.  
  414. function bettingScreen()
  415. drawImage("betScreen", 32, 13)
  416. mWrite("+1", colors.lightGray, colors.black, 32,13)
  417. mWrite("+10", colors.lightGray, colors.black, 32,15)
  418. mWrite("-1", colors.lightGray, colors.black, 46,13)
  419. mWrite("-10", colors.lightGray, colors.black, 46,15)
  420. mWrite("Place", colors.gray, colors.white, 38, 15)
  421. end
  422.  
  423.  
  424.  
  425.  
  426.  
  427. function potScreen()
  428. drawImage("creditScreen", 32, 8)
  429. mWrite("Pot", colors.gray, colors.white, 39, 8)
  430. mWrite(pot, colors.white, colors.black, 39, 9)
  431. end
  432.  
  433.  
  434.  
  435.  
  436.  
  437. function creditsScreen()
  438. drawImage("creditScreen", 32, 3)
  439. mWrite("Credits", colors.gray, colors.white, 37, 3)
  440. mWrite(credits, colors.white, colors.black, 39, 4)
  441. end
  442.  
  443.  
  444.  
  445.  
  446.  
  447. function holdingScreen()
  448. drawImage("holdScreen", 2, 18)
  449. mWrite("Hold", colors.white, colors.black, 3, 19)
  450. mWrite("Hold", colors.white, colors.black, 11, 19)
  451. mWrite("Hold", colors.white, colors.black, 19, 19)
  452. end
  453.  
  454.  
  455.  
  456.  
  457.  
  458. function startScreen()
  459. term.clear()
  460. a = 1
  461. b = 1
  462. for slotNumber = 1,3 do
  463. drawSlot(2, a, b)
  464. a = a +8
  465. end
  466. a = 1
  467. b = b + 6
  468. for slotNumber = 1,3 do
  469. drawSlot(1, a, b)
  470. a = a +8
  471. end
  472. a= 1
  473. b = b + 6
  474. for slotNumber = 1,3 do
  475. drawSlot(3, a, b)
  476. a = a +8
  477. end
  478. end
  479.  
  480.  
  481.  
  482.  
  483.  
  484. function mWrite(message, background, text, x, y)
  485. term.setCursorPos(x,y)
  486. term.setBackgroundColor(background)
  487. term.setTextColor(text)
  488. term.write(message)
  489. end
  490.  
  491.  
  492.  
  493. function drawSlot(image, x, y)
  494. myImage = paintutils.loadImage(slotImage[image])
  495. paintutils.drawImage(myImage, x, y)
  496. term.setBackgroundColor(colors.white)
  497. end
  498.  
  499. function drawLooserSlot(image, x, y)
  500. myImage = paintutils.loadImage(slotLooserImage[image])
  501. paintutils.drawImage(myImage, x, y)
  502. term.setBackgroundColor(colors.white)
  503. end
  504.  
  505. function drawImage(image, x, y)
  506. myImage = paintutils.loadImage(image)
  507. paintutils.drawImage(myImage, x, y)
  508. term.setBackgroundColor(colors.black)
  509. end
  510.  
  511.  
  512.  
  513.  
  514.  
  515.  
  516.  
  517.  
  518. function newGame()
  519. hold = false
  520. hold1 = false
  521. hold2 = false
  522. hold3 = false
  523. q = 1
  524. winner = 0
  525. winnerX = 0
  526. winnerY = 0
  527. winner = {}
  528. winnerX = {}
  529. winnerY = {}
  530. prize = 0
  531. win = false
  532. c = 1
  533. d = 1
  534. e = 1
  535. slotWheel1 = 0
  536. slotWheel2 = 0
  537. slotWheel3 = 0
  538. slotWheel1 = {}
  539. slotWheel2 = {}
  540. slotWheel3 = {}
  541. end
  542.  
  543.  
  544.  
  545.  
  546.  
  547. -- ##### LOOP #####
  548. term.clear()
  549. term.clear()
  550. startScreen4()
  551. term.setBackgroundColor(colors.black)
  552. term.setTextColor(colors.white)
  553. term.setCursorPos(14,19)
  554. term.write("Insert credit-disk to play")
  555. waitClick()
  556. term.clear()
  557. term.setBackgroundColor(colors.white)
  558.  
  559.  
  560. while true do
  561. newGame()
  562. makeSlotWheel()
  563. startScreen()
  564. bettingScreen()
  565. creditsScreen()
  566. potScreen()
  567. waitClick()
  568. creditsScreen()
  569. potScreen()
  570. holdingScreen()
  571. generateNumber()
  572. generateSlots()
  573. sleep(3)
  574. getWinner()
  575. displayWinner()
  576. waitClick()
  577. newGame()
  578. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement