Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mSide = "right"
- results = {}
- slotImage = {"seven", "heart", "club", "spade", "diamond", "bomb", "star"}
- --mon = peripheral.wrap(mSide)
- --mon.setTextScale(3)
- term.setBackgroundColor(colors.white)
- credits = tonumber(500)
- pot = tonumber(50)
- hold = false
- hold1 = false
- hold2 = false
- hold3 = false
- winner = {}
- winnerX = {}
- winnerY = {}
- prize = tonumber(0)
- function generateNumber()
- for i = 1,9 do
- randomNum = tonumber(math.random(1,7))
- table.insert(results, randomNum)
- end
- end
- function randomNumber()
- number = tonumber(math.random(1,9))
- return number
- end
- function generateSlots()
- q = 1
- holdingScreen()
- stopWatch = os.startTimer(0.6)
- numberSpin = tonumber(math.random(30, 60))
- for i = 1, numberSpin do
- --while q ~= 4 do
- --if q == 4 then
- -- break
- --end
- if hold1 == true and hold2 == true and hold3 == true then
- break
- end
- term.clear()
- creditsScreen()
- potScreen()
- drawSlots()
- holdingScreen()
- event, timerID, x, y = os.pullEvent()
- if event == "timer" then
- stopWatch = 0
- stopWatch = os.startTimer(0.6)
- elseif event == "mouse_click" and x > 1 and x < 8 and y > 17 and y < 20 and hold1 == false then
- hold1 = true
- q = q + 1
- elseif event == "mouse_click" and x > 9 and x < 16 and y > 17 and y < 20 and hold2 == false then
- hold2 = true
- q = q + 1
- elseif event == "mouse_click" and x > 17 and x < 24 and y > 17 and y < 20 and hold3 == false then
- hold3 = true
- q = q + 1
- end
- end
- end
- function drawSlot(image, x, y)
- myImage = paintutils.loadImage(slotImage[image])
- paintutils.drawImage(myImage, x, y)
- term.setBackgroundColor(colors.white)
- end
- function drawImage(image, x, y)
- myImage = paintutils.loadImage(image)
- paintutils.drawImage(myImage, x, y)
- term.setBackgroundColor(colors.white)
- end
- function drawSlots()
- a = 1
- b = 1
- if hold1 == false then
- slot1 = tonumber(math.random(1,7))
- drawSlot(slot1, a, b)
- b = b + 6
- slot2 = tonumber(math.random(1,7))
- drawSlot(slot2, a, b)
- b = b + 6
- slot3 = tonumber(math.random(1,7))
- drawSlot(slot3, a, b)
- b = b + 6
- elseif hold1 == true then
- drawSlot(slot1, a, b)
- b = b + 6
- drawSlot(slot2, a, b)
- b = b + 6
- drawSlot(slot3, a, b)
- b = b + 6
- end
- a = a +8
- b = 1
- if hold2 == false then
- slot4 = tonumber(math.random(1,7))
- drawSlot(slot4, a, b)
- b = b + 6
- slot5 = tonumber(math.random(1,7))
- drawSlot(slot5, a, b)
- b = b + 6
- slot6 = tonumber(math.random(1,7))
- drawSlot(slot6, a, b)
- b = b + 6
- elseif hold2 == true then
- drawSlot(slot4, a, b)
- b = b + 6
- drawSlot(slot5, a, b)
- b = b + 6
- drawSlot(slot6, a, b)
- b = b + 6
- end
- a= a + 8
- b = 1
- if hold3 == false then
- slot7 = tonumber(math.random(1,7))
- drawSlot(slot7, a, b)
- b = b + 6
- slot8 = tonumber(math.random(1,7))
- drawSlot(slot8, a, b)
- b = b + 6
- slot9 = tonumber(math.random(1,7))
- drawSlot(slot9, a, b)
- b = b + 6
- elseif hold3 == true then
- drawSlot(slot7, a, b)
- b = b + 6
- drawSlot(slot8, a, b)
- b = b + 6
- drawSlot(slot9, a, b)
- b = b + 6
- end
- end
- function getWinner()
- if slot1 == slot2 and slot1 == slot3 then -- hvis den forreste række ned
- table.insert(winner, slot1)
- table.insert(winner, slot2)
- table.insert(winner, slot3)
- table.insert(winnerX, 1)
- table.insert(winnerX, 1)
- table.insert(winnerX, 1)
- table.insert(winnerY, 1)
- table.insert(winnerY, 7)
- table.insert(winnerY, 13)
- prize = prize + pot*4
- end
- if slot4 == slot5 and slot4 == slot6 then -- midterste ned
- table.insert(winner, slot4)
- table.insert(winner, slot5)
- table.insert(winner, slot6)
- table.insert(winnerX, 9)
- table.insert(winnerX, 9)
- table.insert(winnerX, 9)
- table.insert(winnerY, 1)
- table.insert(winnerY, 7)
- table.insert(winnerY, 13)
- prize = prize + pot*4
- end
- if slot7 == slot8 and slot7 == slot9 then -- yderste og ned
- table.insert(winner, slot7)
- table.insert(winner, slot8)
- table.insert(winner, slot9)
- table.insert(winnerX, 17)
- table.insert(winnerX, 17)
- table.insert(winnerX, 17)
- table.insert(winnerY, 1)
- table.insert(winnerY, 7)
- table.insert(winnerY, 13)
- prize = prize + pot*4
- end
- if slot1 == slot5 and slot1 == slot9 then -- fra øverste venstre hjørne og ned
- table.insert(winner, slot1)
- table.insert(winner, slot5)
- table.insert(winner, slot9)
- table.insert(winnerX, 1)
- table.insert(winnerX, 9)
- table.insert(winnerX, 17)
- table.insert(winnerY, 1)
- table.insert(winnerY, 7)
- table.insert(winnerY, 13)
- prize = prize + pot*3
- end
- if slot3 == slot5 and slot3 == slot7 then -- fra nederste venstre hjørne og op
- table.insert(winner, slot3)
- table.insert(winner, slot5)
- table.insert(winner, slot7)
- table.insert(winnerX, 1)
- table.insert(winnerX, 9)
- table.insert(winnerX, 17)
- table.insert(winnerY, 1)
- table.insert(winnerY, 7)
- table.insert(winnerY, 13)
- prize = prize + pot*3
- end
- if slot1 == slot4 and slot1 == slot7 then -- øverste hen
- table.insert(winner, slot1)
- table.insert(winner, slot4)
- table.insert(winner, slot7)
- table.insert(winnerX, 1)
- table.insert(winnerX, 9)
- table.insert(winnerX, 17)
- table.insert(winnerY, 1)
- table.insert(winnerY, 1)
- table.insert(winnerY, 1)
- prize = prize + pot*2
- end
- if slot2 == slot5 and slot2 == slot8 then -- midterste hen
- table.insert(winner, slot2)
- table.insert(winner, slot5)
- table.insert(winner, slot8)
- table.insert(winnerX, 1)
- table.insert(winnerX, 9)
- table.insert(winnerX, 17)
- table.insert(winnerY, 7)
- table.insert(winnerY, 7)
- table.insert(winnerY, 7)
- prize = prize + pot*2
- end
- if slot3 == slot6 and slot3 == slot9 then -- nederste hen
- table.insert(winner, slot3)
- table.insert(winner, slot6)
- table.insert(winner, slot9)
- table.insert(winnerX, 1)
- table.insert(winnerX, 9)
- table.insert(winnerX, 17)
- table.insert(winnerY, 13)
- table.insert(winnerY, 13)
- table.insert(winnerY, 13)
- prize = prize + pot*2
- end
- end
- function displayWinner()
- credits = credits + prize
- term.clear()
- creditsScreen()
- potScreen()
- for i = 1, #winner do
- drawSlot(winner[i], winnerX[i], winnerY[i])
- end
- end
- function waitClick()
- event = os.pullEvent("mouse_click")
- if event == "mouse_click" then
- notInUse2 = 0
- end
- end
- function bettingScreen()
- drawImage("betScreen", 32, 13)
- mWrite("+1", colors.lightGray, colors.black, 32,13)
- mWrite("+10", colors.lightGray, colors.black, 32,15)
- mWrite("-1", colors.lightGray, colors.black, 46,13)
- mWrite("-10", colors.lightGray, colors.black, 46,15)
- mWrite("Place", colors.gray, colors.white, 38, 15)
- end
- function potScreen()
- drawImage("creditScreen", 32, 8)
- mWrite("Pot", colors.gray, colors.white, 39, 8)
- mWrite(pot, colors.white, colors.black, 39, 9)
- end
- function creditsScreen()
- drawImage("creditScreen", 32, 3)
- mWrite("Credits", colors.gray, colors.white, 37, 3)
- mWrite(credits, colors.white, colors.black, 39, 4)
- end
- function holdingScreen()
- drawImage("holdScreen", 2, 18)
- mWrite("Hold", colors.white, colors.black, 3, 19)
- mWrite("Hold", colors.white, colors.black, 11, 19)
- mWrite("Hold", colors.white, colors.black, 19, 19)
- end
- function startScreen()
- term.clear()
- a = 1
- b = 1
- for slotNumber = 1,3 do
- drawSlot(2, a, b)
- a = a +8
- end
- a = 1
- b = b + 6
- for slotNumber = 1,3 do
- drawSlot(1, a, b)
- a = a +8
- end
- a= 1
- b = b + 6
- for slotNumber = 1,3 do
- drawSlot(3, a, b)
- a = a +8
- end
- end
- function mWrite(message, background, text, x, y)
- term.setCursorPos(x,y)
- term.setBackgroundColor(background)
- term.setTextColor(text)
- term.write(message)
- end
- function newGame()
- hold = false
- hold1 = false
- hold2 = false
- hold3 = false
- q = 1
- winner = 0
- winnerX = 0
- winnerY = 0
- winner = {}
- winnerX = {}
- winnerY = {}
- prize = 0
- end
- -- ##### LOOP #####
- term.setTextColor(colors.black)
- term.clear()
- term.setCursorPos(4,4)
- term.write("Click to play")
- waitClick()
- while true do
- startScreen()
- bettingScreen()
- creditsScreen()
- potScreen()
- waitClick()
- creditsScreen()
- potScreen()
- holdingScreen()
- generateNumber()
- generateSlots()
- sleep(3)
- getWinner()
- displayWinner()
- waitClick()
- term.clear()
- mWrite(pot, colors.white, colors.black, 1, 1)
- mWrite(credits, colors.white, colors.black, 1, 2)
- waitClick()
- newGame()
- end
Advertisement
Add Comment
Please, Sign In to add comment