Advertisement
zipyzapyus

2023 computercraft turtle

Dec 3rd, 2023 (edited)
925
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.37 KB | None | 0 0
  1. local oldpull = os.pullEvent
  2. os.pullEvent = os.pullEventRaw
  3. local password = "zipy"
  4.  
  5. local function c(col)
  6.   if term.isColor() then
  7.     term.setTextColor(col)
  8.   end
  9. end
  10.  
  11. term.clear()
  12. local l, h = term.getSize()
  13.  
  14. local function pos(x, y)
  15.   term.setCursorPos(x, y)
  16. end
  17.  
  18. local function w(string)
  19.   local x, y = term.getCursorPos()
  20.   term.write(string)
  21.   y = y + 1
  22.   pos(x, y)
  23. end
  24.  
  25. local function border(height)
  26.   c(colors.lime)
  27.   local l1 = "**"
  28.   for i = 5, l do
  29.     l1 = l1 .. "="
  30.   end
  31.   l1 = l1 .. "**"
  32.   local l2 = "||"
  33.   pos(1, 1)
  34.   w(l1)
  35.   for i = 2, height - 1 do
  36.     pos(1, i)
  37.     w(l2)
  38.     pos(l - 1, i)
  39.     w(l2)
  40.   end
  41.   pos(1, height)
  42.   w(l1)
  43.   c(colors.white)
  44. end
  45.  
  46. local function bunney(x, y)
  47.   x = x - 3
  48.   pos(x, y)
  49.   c(colors.orange)
  50.   w("(\\_/)")
  51.   w("(',')")
  52.   w("(\\\")(\")")
  53.   pos(x - 3, y + 4)
  54.   w("Chubby Bunney")
  55.   c(colors.white)
  56. end
  57.  
  58. local function star(x, y)
  59.   pos(x, y)
  60.   c(colors.lightBlue)
  61.   w(" /\\")
  62.   w("<  >")
  63.   w(" \\/")
  64.   c(colors.white)
  65. end
  66.  
  67. local function pass(x, y)
  68.   x = x - 4
  69.   pos(x, y)
  70.   c(colors.lightGray)
  71.   w("Please type")
  72.   w(" Password:")
  73.   pos(x, y + 5)
  74.   w("-----------")
  75.   pos(x, y + 3)
  76.   w("-----------")
  77.   c(colors.white)
  78.   term.setCursorBlink(true)
  79. end
  80.  
  81. local function build()
  82.   border(18)
  83.   star(4, 3)
  84.   star(l - 6, 3)
  85.   star(4, h - 4)
  86.   star(l - 6, h - 4)
  87.   bunney(l / 2, 3)
  88.   pass((l / 2) - 1, 9)
  89. end
  90. build()
  91. local t = true
  92.  
  93. while t do
  94.   input = read("*")
  95.   if input == password then
  96.     t = false
  97.     term.setCursorBlink(false)
  98.     os.pullEvent = oldpull
  99.  
  100.   else
  101.     term.clear()
  102.     pos(1, 1)
  103.     build()
  104.   end
  105. end
  106. term.clear()
  107.  
  108. --shell.run("test")
  109.  
  110. local function getProgramsInDirectory()
  111.   local programs = {}
  112.   local files = fs.list(shell.dir())
  113.   local programName = shell.getRunningProgram()
  114.  
  115.   for _, file in ipairs(files) do
  116.     if not fs.isDir(file) and file ~= programName then
  117.       table.insert(programs, {
  118.         name = file,
  119.         func = function() shell.run(file) end
  120.       })
  121.     end
  122.   end
  123.  
  124.   return programs
  125. end
  126.  
  127. local function displayMenu(menuOptions, selectedOption)
  128.   term.clear()
  129.   Pos(1,1)
  130. c(colors.red)
  131. w("Logged In To " .. os.getComputerLabel())
  132.   c(colors.green)
  133. w("Select a program to run:")
  134.   for idx, option in ipairs(menuOptions) do
  135.     if idx == selectedOption then
  136.       w("-> " .. option.name)
  137.     else
  138.       w("   " .. option.name)
  139.     end
  140.   end
  141. end
  142.  
  143. local function handleChoice(choice, menuOptions)
  144.   local option = menuOptions[choice]
  145.   option.func()
  146. end
  147.  
  148. local function main()
  149.   local menuOptions = getProgramsInDirectory()
  150.   table.insert(menuOptions, { name = "Exit", func = function() return end }) -- Insert an "Exit" option
  151.  
  152.   local selectedOption = 1
  153.  
  154.   displayMenu(menuOptions, selectedOption)
  155.  
  156.   while true do
  157.     local event, key = os.pullEvent("key")
  158.     if key == keys.w and selectedOption > 1 then
  159.       selectedOption = selectedOption - 1
  160.       displayMenu(menuOptions, selectedOption)
  161.     elseif key == keys.s and selectedOption < #menuOptions then
  162.       selectedOption = selectedOption + 1
  163.       displayMenu(menuOptions, selectedOption)
  164.     elseif key == keys.enter then
  165.       handleChoice(selectedOption, menuOptions)
  166.       if selectedOption == #menuOptions then -- Check if "Exit" was selected
  167.         return
  168.       end
  169.       break
  170.     end
  171.   end
  172. end
  173.  
  174. main()
  175.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement