alexnolan

atmslots

Mar 26th, 2025 (edited)
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 21.84 KB | None | 0 0
  1. -- Casino Slots Game
  2. -- Integrates with player card system
  3.  
  4. -- Initialize peripherals
  5. local monitor = peripheral.find("monitor")
  6. local oldTerm = term.current()
  7.  
  8. if monitor then
  9.   monitor.setTextScale(0.5)
  10.   monitor.clear()
  11. end
  12.  
  13. -- Find disk drive
  14. local function findDiskDrive()
  15.   local sides = {"top", "bottom", "left", "right", "front", "back"}
  16.  
  17.   for _, side in ipairs(sides) do
  18.     if peripheral.getType(side) == "drive" then
  19.       return side
  20.     end
  21.   end
  22.  
  23.   return nil
  24. end
  25.  
  26. local diskDrive = findDiskDrive()
  27.  
  28. -- Colors
  29. local COLORS = {
  30.   background = colors.black,
  31.   header = colors.blue,
  32.   headerText = colors.white,
  33.   primary = colors.white,
  34.   highlight = colors.yellow,
  35.   success = colors.lime,
  36.   error = colors.orange,  -- Changed from red to orange for better visibility
  37.   balance = colors.lime,
  38.   balanceNegative = colors.orange,  -- Changed from red to orange
  39.   button = colors.lightGray,
  40.   buttonText = colors.black,
  41.   buttonHighlight = colors.yellow,
  42.   slotBorder = colors.gray,
  43.   slotBackground = colors.black,
  44.   cherry = colors.pink,  -- Changed from red to pink
  45.   lemon = colors.yellow,
  46.   orange = colors.orange,
  47.   plum = colors.purple,
  48.   seven = colors.lightBlue,
  49.   bar = colors.white,
  50.   exitButton = colors.gray,
  51.   exitText = colors.white
  52. }
  53.  
  54. -- Slot symbols
  55. local SYMBOLS = {
  56.   {name = "Cherry", color = COLORS.cherry, char = "O", value = 2},
  57.   {name = "Lemon", color = COLORS.lemon, char = "O", value = 3},
  58.   {name = "Orange", color = COLORS.orange, char = "O", value = 4},
  59.   {name = "Plum", color = COLORS.plum, char = "O", value = 5},
  60.   {name = "Seven", color = COLORS.seven, char = "7", value = 7},
  61.   {name = "BAR", color = COLORS.bar, char = "=", value = 10}
  62. }
  63.  
  64. -- Helper functions
  65. local function centerText(text, y, color, targetTerm)
  66.   targetTerm = targetTerm or term.current()
  67.   local w, h = targetTerm.getSize()
  68.   local x = math.floor((w - #text) / 2) + 1
  69.  
  70.   if y then
  71.     targetTerm.setCursorPos(x, y)
  72.     if color then
  73.       targetTerm.setTextColor(color)
  74.     end
  75.     targetTerm.write(text)
  76.   end
  77.  
  78.   return x
  79. end
  80.  
  81. local function drawBox(x, y, width, height, bgColor, fgColor, targetTerm)
  82.   targetTerm = targetTerm or term.current()
  83.   targetTerm.setBackgroundColor(bgColor or COLORS.button)
  84.   targetTerm.setTextColor(fgColor or COLORS.buttonText)
  85.  
  86.   for i = 1, height do
  87.     targetTerm.setCursorPos(x, y + i - 1)
  88.     targetTerm.write(string.rep(" ", width))
  89.   end
  90. end
  91.  
  92. local function drawButton(x, y, text, bgColor, fgColor, targetTerm)
  93.   targetTerm = targetTerm or term.current()
  94.   local padding = 2
  95.   local width = #text + (padding * 2)
  96.  
  97.   drawBox(x, y, width, 3, bgColor, fgColor, targetTerm)
  98.   targetTerm.setCursorPos(x + padding, y + 1)
  99.   targetTerm.write(text)
  100.  
  101.   return {
  102.     x1 = x,
  103.     y1 = y,
  104.     x2 = x + width,
  105.     y2 = y + 2,
  106.     text = text
  107.   }
  108. end
  109.  
  110. local function isInside(x, y, button)
  111.   return x >= button.x1 and x <= button.x2 and
  112.          y >= button.y1 and y <= button.y2
  113. end
  114.  
  115. local function drawHeader(targetTerm)
  116.   targetTerm = targetTerm or term.current()
  117.   local w, h = targetTerm.getSize()
  118.  
  119.   -- Header background
  120.   targetTerm.setBackgroundColor(COLORS.header)
  121.   targetTerm.setTextColor(COLORS.headerText)
  122.   for i = 1, 3 do
  123.     targetTerm.setCursorPos(1, i)
  124.     targetTerm.write(string.rep(" ", w))
  125.   end
  126.  
  127.   -- Game title
  128.   local title = "LUCKY SLOTS"
  129.   centerText(title, 2, COLORS.headerText, targetTerm)
  130.  
  131.   -- Reset for main content
  132.   targetTerm.setBackgroundColor(COLORS.background)
  133. end
  134.  
  135. local function formatCredits(amount)
  136.   local formatted = tostring(amount)
  137.   local pos = #formatted - 3
  138.   while pos > 0 do
  139.     formatted = formatted:sub(1, pos) .. "," .. formatted:sub(pos + 1)
  140.     pos = pos - 3
  141.   end
  142.   return formatted
  143. end
  144.  
  145. -- Show intro screen
  146. local function showIntroScreen()
  147.   if monitor then term.redirect(monitor) end
  148.   local w, h = term.getSize()
  149.  
  150.   term.clear()
  151.   drawHeader()
  152.  
  153.   term.setTextColor(COLORS.highlight)
  154.   centerText("WELCOME TO", 5)
  155.   centerText("LUCKY SLOTS", 6)
  156.  
  157.   term.setTextColor(COLORS.primary)
  158.   centerText("Insert your player card", 9)
  159.   centerText("to begin playing!", 10)
  160.  
  161.   -- Draw slot machine graphic
  162.   local slotWidth = 26
  163.   local slotX = math.floor((w - slotWidth) / 2)
  164.   local slotY = 12
  165.  
  166.   -- Machine body
  167.   drawBox(slotX, slotY, slotWidth, 8, COLORS.slotBorder)
  168.   drawBox(slotX + 2, slotY + 1, slotWidth - 4, 3, COLORS.slotBackground)
  169.  
  170.   -- Reels
  171.   local reelWidth = 5
  172.   local reelPadding = 2
  173.   local reelX = slotX + 3
  174.  
  175.   for i = 1, 3 do
  176.     drawBox(reelX, slotY + 1, reelWidth, 3, COLORS.slotBackground)
  177.    
  178.     -- Draw random symbol
  179.     local symbol = SYMBOLS[math.random(1, #SYMBOLS)]
  180.     term.setTextColor(symbol.color)
  181.     term.setCursorPos(reelX + 2, slotY + 2)
  182.     term.write(symbol.char)
  183.    
  184.     reelX = reelX + reelWidth + reelPadding
  185.   end
  186.  
  187.   -- Lever
  188.   term.setBackgroundColor(COLORS.background)
  189.   term.setTextColor(COLORS.slotBorder)
  190.   term.setCursorPos(slotX + slotWidth + 1, slotY + 1)
  191.   term.write("|")
  192.   term.setCursorPos(slotX + slotWidth + 1, slotY + 2)
  193.   term.write("O")
  194.   term.setCursorPos(slotX + slotWidth + 1, slotY + 3)
  195.   term.write("|")
  196.  
  197.   -- Payout info
  198.   term.setTextColor(COLORS.highlight)
  199.   centerText("PAYOUTS:", slotY + 10)
  200.  
  201.   term.setTextColor(COLORS.primary)
  202.   local payoutY = slotY + 11
  203.   for i, symbol in ipairs(SYMBOLS) do
  204.     term.setTextColor(symbol.color)
  205.     term.setCursorPos(slotX + 2, payoutY + i - 1)
  206.     term.write(symbol.char .. " " .. symbol.name)
  207.    
  208.     term.setTextColor(COLORS.primary)
  209.     term.setCursorPos(slotX + 15, payoutY + i - 1)
  210.     term.write("x" .. symbol.value)
  211.   end
  212.  
  213.   -- Wait for disk to be inserted
  214.   while not disk.isPresent(diskDrive) do
  215.     sleep(0.5)
  216.     -- Check if disk drive is still connected
  217.     if not peripheral.isPresent(diskDrive) then
  218.       diskDrive = findDiskDrive()
  219.       if not diskDrive then
  220.         term.setTextColor(COLORS.error)
  221.         centerText("Disk drive disconnected!", h - 2)
  222.         sleep(1)
  223.         return showIntroScreen() -- Restart the process
  224.       end
  225.     end
  226.   end
  227.  
  228.   term.setTextColor(COLORS.success)
  229.   centerText("Card detected!", h - 2)
  230.   sleep(1)
  231.  
  232.   return diskDrive
  233. end
  234.  
  235. -- Load player data from card
  236. local function loadPlayerData(drive)
  237.   local path = disk.getMountPath(drive) .. "/player.dat"
  238.  
  239.   if not fs.exists(path) then
  240.     if monitor then term.redirect(monitor) end
  241.     local w, h = term.getSize()
  242.    
  243.     term.clear()
  244.     drawHeader()
  245.    
  246.     term.setTextColor(COLORS.error)
  247.     centerText("Invalid player card!", 8)
  248.     centerText("Please visit the Casino PC", 10)
  249.     centerText("to create a new account", 11)
  250.    
  251.     -- Wait for disk to be removed
  252.     while disk.isPresent(drive) do
  253.       sleep(0.5)
  254.     end
  255.    
  256.     return nil
  257.   end
  258.  
  259.   local file = fs.open(path, "r")
  260.   local data = textutils.unserialize(file.readAll())
  261.   file.close()
  262.  
  263.   return data
  264. end
  265.  
  266. -- Save player data to card
  267. local function savePlayerData(drive, playerData)
  268.   local path = disk.getMountPath(drive) .. "/player.dat"
  269.  
  270.   -- Update last played
  271.   playerData.lastPlayed = os.day()
  272.  
  273.   -- Save updated data
  274.   local file = fs.open(path, "w")
  275.   file.write(textutils.serialize(playerData))
  276.   file.close()
  277. end
  278.  
  279. -- Get bet amount from player
  280. local function getBetAmount(playerData)
  281.   if monitor then term.redirect(monitor) end
  282.   local w, h = term.getSize()
  283.  
  284.   term.clear()
  285.   drawHeader()
  286.  
  287.   term.setTextColor(COLORS.primary)
  288.   centerText("Welcome, " .. playerData.name, 5)
  289.  
  290.   term.setTextColor(COLORS.balance)
  291.   centerText("Balance: " .. formatCredits(playerData.credits), 7)
  292.  
  293.   term.setTextColor(COLORS.highlight)
  294.   centerText("Select your bet amount:", 10)
  295.  
  296.   -- Draw bet buttons in a more organized grid
  297.   local betButtons = {}
  298.   local betAmounts = {100, 500, 1000, 5000, 10000}
  299.  
  300.   -- Calculate button positions for a centered grid
  301.   local buttonWidth = 10
  302.   local buttonSpacing = 3
  303.   local totalWidth = (buttonWidth * 3) + (buttonSpacing * 2)
  304.   local startX = math.floor((w - totalWidth) / 2)
  305.  
  306.   -- First row (3 buttons)
  307.   for i = 1, 3 do
  308.     local buttonX = startX + (i-1) * (buttonWidth + buttonSpacing)
  309.     local button = drawButton(buttonX, 12, tostring(betAmounts[i]), COLORS.button, COLORS.buttonText)
  310.     button.amount = betAmounts[i]
  311.     table.insert(betButtons, button)
  312.   end
  313.  
  314.   -- Second row (2 buttons)
  315.   startX = math.floor((w - ((buttonWidth * 2) + buttonSpacing)) / 2)
  316.   for i = 4, 5 do
  317.     local buttonX = startX + (i-4) * (buttonWidth + buttonSpacing)
  318.     local button = drawButton(buttonX, 16, tostring(betAmounts[i]), COLORS.button, COLORS.buttonText)
  319.     button.amount = betAmounts[i]
  320.     table.insert(betButtons, button)
  321.   end
  322.  
  323.   -- Custom bet button (centered)
  324.   local customButton = drawButton(math.floor(w/2) - 8, 20, "Custom Bet", COLORS.button, COLORS.buttonText)
  325.  
  326.   -- Back button (bottom left)
  327.   local backButton = drawButton(5, h - 4, "Back", COLORS.exitButton, COLORS.exitText)
  328.  
  329.   while true do
  330.     local event, button, x, y = os.pullEvent("monitor_touch")
  331.    
  332.     -- Check if card is still present
  333.     if not disk.isPresent(diskDrive) then
  334.       return nil
  335.     end
  336.    
  337.     -- Check bet buttons
  338.     for _, btn in ipairs(betButtons) do
  339.       if isInside(x, y, btn) then
  340.         if btn.amount <= playerData.credits then
  341.           return btn.amount
  342.         else
  343.           -- Show insufficient funds message
  344.           term.setTextColor(COLORS.error)
  345.           centerText("Insufficient funds!", h - 8)
  346.           sleep(1.5)
  347.          
  348.           -- Clear error message
  349.           term.setBackgroundColor(COLORS.background)
  350.           term.setCursorPos(1, h - 8)
  351.           term.write(string.rep(" ", w))
  352.         end
  353.       end
  354.     end
  355.    
  356.     -- Check custom bet button
  357.     if isInside(x, y, customButton) then
  358.       -- Switch to computer terminal for input
  359.       term.redirect(oldTerm)
  360.       term.clear()
  361.       term.setCursorPos(1, 1)
  362.       term.setTextColor(colors.yellow)
  363.       print("LUCKY SLOTS - CUSTOM BET")
  364.       print("-----------------------")
  365.       print("")
  366.       term.setTextColor(colors.white)
  367.       print("Player: " .. playerData.name)
  368.       print("Balance: " .. formatCredits(playerData.credits))
  369.       print("")
  370.       print("Enter your bet amount:")
  371.      
  372.       local input = read()
  373.       local betAmount = tonumber(input)
  374.      
  375.       -- Switch back to monitor
  376.       if monitor then term.redirect(monitor) end
  377.      
  378.       if betAmount and betAmount > 0 and betAmount <= playerData.credits then
  379.         return betAmount
  380.       else
  381.         -- Show invalid bet message
  382.         term.setTextColor(COLORS.error)
  383.         centerText("Invalid bet amount!", h - 8)
  384.         sleep(1.5)
  385.        
  386.         -- Clear error message
  387.         term.setBackgroundColor(COLORS.background)
  388.         term.setCursorPos(1, h - 8)
  389.         term.write(string.rep(" ", w))
  390.       end
  391.     end
  392.    
  393.     -- Check back button
  394.     if isInside(x, y, backButton) then
  395.       return 0 -- Signal to go back
  396.     end
  397.   end
  398. end
  399.  
  400. -- Draw slot machine
  401. local function drawSlotMachine(reels)
  402.   if monitor then term.redirect(monitor) end
  403.   local w, h = term.getSize()
  404.  
  405.   -- Draw slot machine graphic
  406.   local slotWidth = 26
  407.   local slotX = math.floor((w - slotWidth) / 2)
  408.   local slotY = 8
  409.  
  410.   -- Machine body
  411.   drawBox(slotX, slotY, slotWidth, 8, COLORS.slotBorder)
  412.   drawBox(slotX + 2, slotY + 1, slotWidth - 4, 3, COLORS.slotBackground)
  413.  
  414.   -- Reels
  415.   local reelWidth = 5
  416.   local reelPadding = 2
  417.   local reelX = slotX + 3
  418.  
  419.   for i = 1, 3 do
  420.     drawBox(reelX, slotY + 1, reelWidth, 3, COLORS.slotBackground)
  421.    
  422.     -- Draw symbol if provided
  423.     if reels and reels[i] then
  424.       local symbol = reels[i]
  425.       term.setTextColor(symbol.color)
  426.       term.setCursorPos(reelX + 2, slotY + 2)
  427.       term.write(symbol.char)
  428.     end
  429.    
  430.     reelX = reelX + reelWidth + reelPadding
  431.   end
  432.  
  433.   -- Lever
  434.   term.setBackgroundColor(COLORS.background)
  435.   term.setTextColor(COLORS.slotBorder)
  436.   term.setCursorPos(slotX + slotWidth + 1, slotY + 1)
  437.   term.write("|")
  438.   term.setCursorPos(slotX + slotWidth + 1, slotY + 2)
  439.   term.write("O")
  440.   term.setCursorPos(slotX + slotWidth + 1, slotY + 3)
  441.   term.write("|")
  442.  
  443.   return {
  444.     x = slotX,
  445.     y = slotY,
  446.     width = slotWidth,
  447.     height = 8,
  448.     reelX = slotX + 3,
  449.     reelY = slotY + 2,
  450.     reelWidth = reelWidth,
  451.     reelPadding = reelPadding
  452.   }
  453. end
  454.  
  455. -- Spin the reels animation
  456. local function spinReels(slotMachine, spinTime)
  457.   local spinStartTime = os.clock()
  458.   local spinEndTime = spinStartTime + spinTime
  459.  
  460.   -- Spin animation
  461.   while os.clock() < spinEndTime do
  462.     -- Generate random symbols for each reel
  463.     local currentReels = {}
  464.     for i = 1, 3 do
  465.       currentReels[i] = SYMBOLS[math.random(1, #SYMBOLS)]
  466.     end
  467.    
  468.     -- Draw the current symbols
  469.     local reelX = slotMachine.reelX
  470.     for i = 1, 3 do
  471.       local symbol = currentReels[i]
  472.       term.setTextColor(symbol.color)
  473.       term.setCursorPos(reelX + 2, slotMachine.reelY)
  474.       term.write(symbol.char)
  475.      
  476.       reelX = reelX + slotMachine.reelWidth + slotMachine.reelPadding
  477.     end
  478.    
  479.     -- Slow down the animation as it approaches the end
  480.     local timeLeft = spinEndTime - os.clock()
  481.     local delay = math.min(0.3, 0.05 + (0.3 * (1 - timeLeft / spinTime)))
  482.     sleep(delay)
  483.   end
  484.  
  485.   -- Generate final results
  486.   local finalReels = {}
  487.   for i = 1, 3 do
  488.     finalReels[i] = SYMBOLS[math.random(1, #SYMBOLS)]
  489.   end
  490.  
  491.   -- Draw the final symbols
  492.   local reelX = slotMachine.reelX
  493.   for i = 1, 3 do
  494.     local symbol = finalReels[i]
  495.     term.setTextColor(symbol.color)
  496.     term.setCursorPos(reelX + 2, slotMachine.reelY)
  497.     term.write(symbol.char)
  498.    
  499.     reelX = reelX + slotMachine.reelWidth + slotMachine.reelPadding
  500.   end
  501.  
  502.   return finalReels
  503. end
  504.  
  505. -- Calculate winnings based on the final reels
  506. local function calculateWinnings(reels, betAmount)
  507.   -- Check if all symbols are the same
  508.   local allSame = true
  509.   local firstSymbol = reels[1]
  510.  
  511.   for i = 2, 3 do
  512.     if reels[i].name ~= firstSymbol.name then
  513.       allSame = false
  514.       break
  515.     end
  516.   end
  517.  
  518.   if allSame then
  519.     -- Jackpot! All three symbols match
  520.     return betAmount * firstSymbol.value
  521.   end
  522.  
  523.   -- Check for pairs
  524.   for i = 1, 2 do
  525.     for j = i + 1, 3 do
  526.       if reels[i].name == reels[j].name then
  527.         -- Pair found
  528.         return math.floor(betAmount * (reels[i].value / 2))
  529.       end
  530.     end
  531.   end
  532.  
  533.   -- No matches
  534.   return 0
  535. end
  536.  
  537. -- Play one round of slots
  538. local function playSlots(playerData, betAmount)
  539.   if monitor then term.redirect(monitor) end
  540.   local w, h = term.getSize()
  541.  
  542.   term.clear()
  543.   drawHeader()
  544.  
  545.   -- Show player info in a nice box at the top
  546.   local infoBoxY = 5
  547.   local infoBoxHeight = 3
  548.  
  549.   -- Draw info box
  550.   drawBox(5, infoBoxY, w - 10, infoBoxHeight, COLORS.header, COLORS.primary)
  551.  
  552.   -- Player name
  553.   term.setTextColor(COLORS.primary)
  554.   term.setCursorPos(8, infoBoxY + 1)
  555.   term.write("Player: " .. playerData.name)
  556.  
  557.   -- Balance
  558.   term.setTextColor(COLORS.balance)
  559.   term.setCursorPos(w - 25, infoBoxY + 1)
  560.   term.write("Balance: " .. formatCredits(playerData.credits))
  561.  
  562.   -- Draw bet amount in a highlighted box
  563.   local betBoxWidth = 20
  564.   local betBoxX = math.floor((w - betBoxWidth) / 2)
  565.   drawBox(betBoxX, infoBoxY + infoBoxHeight + 2, betBoxWidth, 3, COLORS.background, COLORS.highlight)
  566.  
  567.   term.setTextColor(COLORS.highlight)
  568.   centerText("Bet: " .. formatCredits(betAmount), infoBoxY + infoBoxHeight + 3)
  569.  
  570.   -- Draw the slot machine
  571.   local slotMachine = drawSlotMachine()
  572.  
  573.   -- Draw spin button with a more attractive style
  574.   local spinButtonWidth = 12
  575.   local spinButtonX = math.floor((w - spinButtonWidth) / 2)
  576.   local spinButtonY = slotMachine.y + slotMachine.height + 2
  577.  
  578.   drawBox(spinButtonX, spinButtonY, spinButtonWidth, 3, COLORS.highlight, COLORS.buttonText)
  579.   term.setTextColor(COLORS.buttonText)
  580.   term.setCursorPos(spinButtonX + 4, spinButtonY + 1)
  581.   term.write("SPIN")
  582.  
  583.   local spinButton = {
  584.     x1 = spinButtonX,
  585.     y1 = spinButtonY,
  586.     x2 = spinButtonX + spinButtonWidth,
  587.     y2 = spinButtonY + 2
  588.   }
  589.  
  590.   -- Wait for player to press spin
  591.   while true do
  592.     local event, button, x, y = os.pullEvent("monitor_touch")
  593.    
  594.     -- Check if card is still present
  595.     if not disk.isPresent(diskDrive) then
  596.       return nil
  597.     end
  598.    
  599.     if isInside(x, y, spinButton) then
  600.       break
  601.     end
  602.   end
  603.  
  604.   -- Deduct bet amount
  605.   playerData.credits = playerData.credits - betAmount
  606.  
  607.   -- Animate lever pull
  608.   term.setTextColor(COLORS.slotBorder)
  609.   term.setCursorPos(slotMachine.x + slotMachine.width + 1, slotMachine.y + 1)
  610.   term.write(" ")
  611.   term.setCursorPos(slotMachine.x + slotMachine.width + 1, slotMachine.y + 2)
  612.   term.write("|")
  613.   term.setCursorPos(slotMachine.x + slotMachine.width + 1, slotMachine.y + 3)
  614.   term.write("O")
  615.   term.setCursorPos(slotMachine.x + slotMachine.width + 1, slotMachine.y + 4)
  616.   term.write("|")
  617.   sleep(0.3)
  618.  
  619.   -- Spin the reels
  620.   local finalReels = spinReels(slotMachine, 3.0)
  621.  
  622.   -- Reset lever
  623.   term.setTextColor(COLORS.slotBorder)
  624.   term.setCursorPos(slotMachine.x + slotMachine.width + 1, slotMachine.y + 1)
  625.   term.write("|")
  626.   term.setCursorPos(slotMachine.x + slotMachine.width + 1, slotMachine.y + 2)
  627.   term.write("O")
  628.   term.setCursorPos(slotMachine.x + slotMachine.width + 1, slotMachine.y + 3)
  629.   term.write("|")
  630.   term.setCursorPos(slotMachine.x + slotMachine.width + 1, slotMachine.y + 4)
  631.   term.write(" ")
  632.  
  633.   -- Calculate winnings
  634.   local winnings = calculateWinnings(finalReels, betAmount)
  635.  
  636.   -- Update player credits
  637.   playerData.credits = playerData.credits + winnings
  638.  
  639.   -- Record game in player history
  640.   if not playerData.games then
  641.     playerData.games = {}
  642.   end
  643.  
  644.   table.insert(playerData.games, {
  645.     game = "slots",
  646.     bet = betAmount,
  647.     winnings = winnings,
  648.     time = os.day()
  649.   })
  650.  
  651.   -- Display results in a nice box
  652.   local resultBoxY = slotMachine.y + slotMachine.height + 6
  653.   local resultBoxHeight = 4
  654.   local resultBoxWidth = 20
  655.   local resultBoxX = math.floor((w - resultBoxWidth) / 2)
  656.  
  657.   if winnings > 0 then
  658.     -- Win message with fancy box
  659.     drawBox(resultBoxX, resultBoxY, resultBoxWidth, resultBoxHeight, COLORS.success, COLORS.primary)
  660.    
  661.     term.setTextColor(COLORS.primary)
  662.     centerText("YOU WIN!", resultBoxY + 1)
  663.     centerText(formatCredits(winnings), resultBoxY + 2)
  664.   else
  665.     -- Lose message
  666.     drawBox(resultBoxX, resultBoxY, resultBoxWidth, resultBoxHeight, COLORS.error, COLORS.primary)
  667.    
  668.     term.setTextColor(COLORS.primary)
  669.     centerText("NO MATCH", resultBoxY + 1)
  670.     centerText("Try Again!", resultBoxY + 2)
  671.   end
  672.  
  673.   -- Update balance display
  674.   term.setTextColor(COLORS.balance)
  675.   term.setCursorPos(w - 25, infoBoxY + 1)
  676.   term.write("Balance: " .. formatCredits(playerData.credits) .. "   ")
  677.  
  678.   -- Draw buttons in a more organized way
  679.   local buttonY = h - 5
  680.   local playAgainButton = drawButton(10, buttonY, "Play Again", COLORS.button, COLORS.buttonText)
  681.   local cashOutButton = drawButton(w - 20, buttonY, "Cash Out", COLORS.button, COLORS.buttonText)
  682.  
  683.   -- Wait for player decision
  684.   while true do
  685.     local event, button, x, y = os.pullEvent("monitor_touch")
  686.    
  687.     -- Check if card is still present
  688.     if not disk.isPresent(diskDrive) then
  689.       return nil
  690.     end
  691.    
  692.     if isInside(x, y, playAgainButton) then
  693.       return true -- Play again
  694.     elseif isInside(x, y, cashOutButton) then
  695.       return false -- Cash out
  696.     end
  697.   end
  698. end
  699.  
  700. -- Main game loop
  701. while true do
  702.   -- Show intro screen and wait for card
  703.   local drive = showIntroScreen()
  704.  
  705.   -- Load player data
  706.   local playerData = loadPlayerData(drive)
  707.  
  708.   -- If valid player data was loaded
  709.   if playerData then
  710.     local playing = true
  711.    
  712.     while playing and disk.isPresent(drive) do
  713.       -- Get bet amount
  714.       local betAmount = getBetAmount(playerData)
  715.      
  716.       -- Check if player wants to exit or card was removed
  717.       if not betAmount then
  718.         break
  719.       elseif betAmount == 0 then
  720.         -- Player pressed back, show intro screen
  721.         break
  722.       end
  723.      
  724.       -- Play a round of slots
  725.       local playAgain = playSlots(playerData, betAmount)
  726.      
  727.       -- Save player data after each round
  728.       savePlayerData(drive, playerData)
  729.      
  730.       -- Check if player wants to play again
  731.       if not playAgain then
  732.         playing = false
  733.       end
  734.      
  735.       -- Check if player is out of credits
  736.       if playerData.credits <= 0 then
  737.         if monitor then term.redirect(monitor) end
  738.         term.clear()
  739.         drawHeader()
  740.        
  741.         -- Draw a nicer "out of credits" message
  742.         local messageBoxY = 10
  743.         local messageBoxHeight = 5
  744.         local messageBoxWidth = 30
  745.         local messageBoxX = math.floor((w - messageBoxWidth) / 2)
  746.        
  747.         drawBox(messageBoxX, messageBoxY, messageBoxWidth, messageBoxHeight, COLORS.error, COLORS.primary)
  748.        
  749.         term.setTextColor(COLORS.primary)
  750.         centerText("OUT OF CREDITS!", messageBoxY + 1)
  751.         centerText("Please visit the Casino PC", messageBoxY + 3)
  752.         centerText("to add more credits", messageBoxY + 4)
  753.        
  754.         -- Draw exit button
  755.         local exitButton = drawButton(math.floor(w/2) - 4, h - 5, "Exit", COLORS.exitButton, COLORS.exitText)
  756.        
  757.         -- Wait for exit button or card removal
  758.         while disk.isPresent(drive) do
  759.           local event, button, x, y = os.pullEvent()
  760.          
  761.           if event == "monitor_touch" and isInside(x, y, exitButton) then
  762.             break
  763.           end
  764.         end
  765.        
  766.         playing = false
  767.       end
  768.     end
  769.   end
  770.  
  771.   -- Wait for card to be removed before showing intro again
  772.   while disk.isPresent(drive) do
  773.     sleep(0.5)
  774.   end
  775. end
  776.  
Add Comment
Please, Sign In to add comment