Advertisement
DOGGYWOOF

Untitled

Dec 22nd, 2024 (edited)
7
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.94 KB | None | 0 0
  1. -- Function to clear the terminal and set the cursor position
  2. local function clearScreen()
  3. term.clear()
  4. term.setCursorPos(1, 1)
  5. end
  6.  
  7. -- Function to display centered ASCII art
  8. local function displayCenteredArt(art, text)
  9. clearScreen()
  10. local lines = {}
  11. for line in art:gmatch("[^\n]+") do
  12. table.insert(lines, line)
  13. end
  14.  
  15. local _, h = term.getSize()
  16. local startY = math.floor((h - #lines) / 2) + 1
  17. for i, line in ipairs(lines) do
  18. local w, _ = term.getSize()
  19. local startX = math.floor((w - #line) / 2) + 1
  20. term.setCursorPos(startX, startY + i - 1)
  21. print(line)
  22. end
  23.  
  24. if text then
  25. local textX = math.floor((term.getSize() - #text) / 2) + 1
  26. term.setCursorPos(textX, startY + #lines + 1)
  27. print(text)
  28. end
  29. end
  30.  
  31. -- Function to draw a password prompt box
  32. local function drawPasswordBox()
  33. clearScreen()
  34. local w, h = term.getSize()
  35. local boxWidth = 36
  36. local boxHeight = 7
  37. local startX = math.floor((w - boxWidth) / 2) + 1
  38. local startY = math.floor((h - boxHeight) / 2) + 1
  39.  
  40. -- Draw password box
  41. paintutils.drawBox(startX, startY, startX + boxWidth - 1, startY + boxHeight - 1, colors.blue)
  42. paintutils.drawFilledBox(startX + 1, startY + 1, startX + boxWidth - 2, startY + boxHeight - 2, colors.lightBlue)
  43.  
  44. term.setTextColor(colors.white)
  45. term.setCursorPos(startX + 2, startY + 1)
  46. term.write(string.rep(" ", boxWidth - 4))
  47. term.setCursorPos(startX + 3, startY + 1)
  48. term.write("PASSWORD REQUIRED")
  49.  
  50. term.setCursorPos(startX + 2, startY + 3)
  51. term.write(string.rep(" ", boxWidth - 4))
  52. term.setCursorPos(startX + 3, startY + 3)
  53. term.write("Enter Password:")
  54.  
  55. term.setCursorPos(startX + 2, startY + 5)
  56. term.write(string.rep("_", boxWidth - 4))
  57. term.setCursorPos(startX + 2, startY + 5)
  58. return startX + 2, startY + 5, boxWidth - 4
  59. end
  60.  
  61. -- Function to handle password prompt
  62. local function passwordPrompt(correctPassword)
  63. local cursorX, cursorY, inputWidth = drawPasswordBox()
  64. term.setCursorPos(cursorX, cursorY)
  65. local input = read("*") -- Masks input
  66. return input == correctPassword
  67. end
  68.  
  69. -- Function to draw a menu system
  70. local function drawMenu(title, options)
  71. clearScreen()
  72. local w, h = term.getSize()
  73. local boxWidth = 40
  74. local boxHeight = #options + 6
  75. local startX = math.floor((w - boxWidth) / 2) + 1
  76. local startY = math.floor((h - boxHeight) / 2) + 1
  77.  
  78. -- Draw menu background and header
  79. paintutils.drawBox(startX, startY, startX + boxWidth - 1, startY + boxHeight - 1, colors.blue)
  80. paintutils.drawFilledBox(startX + 1, startY + 1, startX + boxWidth - 2, startY + boxHeight - 2, colors.lightBlue)
  81. term.setTextColor(colors.white)
  82.  
  83. term.setCursorPos(startX + 2, startY + 1)
  84. term.write(string.rep(" ", boxWidth - 4))
  85. term.setCursorPos(startX + math.floor((boxWidth - #title) / 2), startY + 1)
  86. term.write(title)
  87.  
  88. -- Draw options
  89. for i, option in ipairs(options) do
  90. term.setCursorPos(startX + 4, startY + 2 + i)
  91. print(i .. ". " .. option)
  92. end
  93. end
  94.  
  95. -- Function to handle menu selection
  96. local function menuSelection(title, options)
  97. drawMenu(title, options)
  98. local w, h = term.getSize()
  99. local startX = math.floor((w - 40) / 2) + 2
  100. local startY = math.floor((h - (#options + 6)) / 2) + #options + 5
  101. term.setCursorPos(startX, startY)
  102. term.write("Select an option: ")
  103. local choice = tonumber(read())
  104. if choice and choice > 0 and choice <= #options then
  105. return choice
  106. else
  107. return nil
  108. end
  109. end
  110.  
  111. -- Main program
  112. local function main()
  113. local correctPassword = "password"
  114. if not passwordPrompt(correctPassword) then
  115. print("Incorrect password. Access denied.")
  116. sleep(2)
  117. return
  118. end
  119.  
  120. local menuTitle = "Main Menu"
  121. local menuOptions = {"Option 1", "Option 2", "Option 3"}
  122. local choice = menuSelection(menuTitle, menuOptions)
  123.  
  124. if choice then
  125. print("You selected option " .. choice)
  126. else
  127. print("Invalid selection.")
  128. end
  129. end
  130.  
  131. main()
  132.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement