Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mon = peripheral.wrap("top")
- mon.setTextScale(2)
- mon.clear()
- winRules = window.create(mon, 1, 3, 41, 20, false)
- winNorm = window.create(mon, 1, 3, 41, 20, true)
- button = {}
- function addButton(name, func, xmin, xmax, ymin, ymax, color, activeColor, textColor, label, isInvis)
- color = color or colors.red
- activeColor = activeColor or colors.lime
- isInvis = isInvis or false
- label = label or name
- button[name] = {}
- button[name]["func"] = func
- button[name]["active"] = false
- button[name]["xmin"] = xmin
- button[name]["ymin"] = ymin
- button[name]["xmax"] = xmax
- button[name]["ymax"] = ymax
- button[name]["color"] = color
- button[name]["activeColor"] = activeColor
- button[name]["textColor"] = textColor
- button[name]["isInvis"] = isInvis
- button[name]["label"] = label
- end
- function screenButton()
- local currcolor
- for name, data in pairs(button)do
- local active = data["active"]
- if active == true then
- currcolor = data["activeColor"]
- else
- currcolor = data["color"]
- end
- if not data["isInvis"] then
- fillButton(data["label"], currcolor, data["textColor"], data)
- end
- end
- end
- function fillButton(text, color, textColor, bData)
- if color ~= "invis" then
- mon.setBackgroundColor(color)
- end
- mon.setTextColor(textColor)
- local yspot = math.floor((bData["ymin"] + bData["ymax"])/2)
- local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text)) /2) +1
- for j = bData["ymin"], bData["ymax"] do
- mon.setCursorPos(bData["xmin"], j)
- if j == yspot then
- for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) + 1 do
- if k == xspot then
- if color == "invis" then
- mon.setCursorPos(xspot + bData["xmin"], yspot)
- end
- mon.write(text)
- if color == "invis" then
- return
- end
- else
- if color ~= "invis" then
- mon.write(" ")
- else
- mon.setCursorPos(k+1, j)
- end
- end
- end
- else
- if color ~= "invis" then
- for i = bData["xmin"], bData["xmax"] do
- mon.write(" ")
- end
- end
- end
- end
- mon.setBackgroundColor(colors.black)
- end
- function toggleButton(name)
- button[name]["active"] = not button[name]["active"]
- screenButton()
- end
- function flash(name)
- toggleButton(name)
- sleep(0.15)
- toggleButton(name)
- end
- function deactivateButton(name)
- button[name]["active"] = false
- end
- function activateButton(name)
- button[name]["active"] = true
- end
- function toggleInvisButton(name)
- button[name]["isInvis"] = not button[name]["isInvis"]
- screenButton()
- end
- function checkxy(x, y)
- for name, data in pairs(button) do
- if not data["isInvis"] then
- if y>=data["ymin"] and y<= data["ymax"] then
- if x>=data["xmin"] and x<=data["xmax"] then
- data["func"]()
- --flash(name)
- return true, name
- end
- end
- end
- end
- return false, nil
- end
- function center(obj, line, text)
- local sizeX = obj.getSize()
- local posX = ((sizeX - string.len(text)) / 2) + 1
- obj.setCursorPos(posX, line)
- obj.write(text)
- end
- function right(obj, line, text)
- local sizeX = obj.getSize()
- local posX = sizeX - string.len(text)
- obj.setCursorPos(posX, line)
- obj.write(text)
- end
- function openRules()
- toggleInvisButton("RULES")
- winRules.setVisible(true)
- winNorm.setVisible(false)
- toggleInvisButton("X")
- end
- function closeRules()
- winRules.setVisible(false)
- winNorm.setVisible(true)
- toggleInvisButton("X")
- toggleInvisButton("RULES")
- end
- mon.setTextColor(colors.white)
- center(mon, 1, "-=Cards Against Humanity=-")
- mon.setTextColor(colors.lightGray)
- center(mon, 2, "A party game for horrible people.")
- addButton("X", closeRules, 40, 41, 20, 20, colors.lightGray, colors.red, colors.black, "X", true)
- winRules.setTextColor(colors.lightGray)
- winRules.setCursorPos(1, 2)
- winRules.write("1. Last person to take a shit is The ")
- winRules.setTextColor(colors.red)
- winRules.write("Card")
- winRules.setCursorPos(1, 3)
- winRules.write(" Czar. ")
- winRules.setTextColor(colors.lightGray)
- winRules.write("The ")
- winRules.setTextColor(colors.red)
- winRules.write("Card Czar ")
- winRules.setTextColor(colors.lightGray)
- winRules.write("reads the first")
- winRules.setCursorPos(1, 4)
- winRules.write(" question to the group.")
- winRules.setCursorPos(1, 5)
- winRules.write("2. The rest of the players answers the ")
- winRules.setCursorPos(1, 6)
- winRules.write(" question with one of their white ")
- winRules.setCursorPos(1, 7)
- winRules.write(" answer cards. Pick the one you find ")
- winRules.setCursorPos(1, 8)
- winRules.write(" the funniest, or most offensive.")
- winRules.setCursorPos(1, 9)
- winRules.write("3. The ")
- winRules.setTextColor(colors.red)
- winRules.write("Card Czar ")
- winRules.setTextColor(colors.lightGray)
- winRules.write("reads all answer cards ")
- winRules.setCursorPos(1, 10)
- winRules.write(" out-loud, making them as entertaining ")
- winRules.setCursorPos(1, 11)
- winRules.write(" as possible. After reading all answers, ")
- winRules.setCursorPos(1, 12)
- winRules.write(" The ")
- winRules.setTextColor(colors.red)
- winRules.write("Card Czar ")
- winRules.setTextColor(colors.lightGray)
- winRules.write("picks the 'best' answer. ")
- winRules.setCursorPos(1, 13)
- winRules.write(" The player who chose that card becomes ")
- winRules.setCursorPos(1, 14)
- winRules.write(" the new ")
- winRules.setTextColor(colors.red)
- winRules.write("Card Czar")
- winRules.setTextColor(colors.lightGray)
- winRules.write(", and earns an ")
- winRules.setCursorPos(1, 15)
- winRules.write(" '")
- winRules.setTextColor(colors.green)
- winRules.write("awesome point")
- winRules.setTextColor(colors.lightGray)
- winRules.write("'.")
- winRules.setCursorPos(1, 16)
- winRules.setTextColor(colors.lightGray)
- winRules.write("4. Repeat the process above until the ")
- winRules.setCursorPos(1, 17)
- winRules.write(" deck is gone, people get bored, or ")
- winRules.setCursorPos(1, 18)
- winRules.write(" everyone storms off being offended.")
- --winRules.setVisible(true)
- winNorm.setTextColor(colors.gray)
- center(winNorm, 1, "(AKA Aknotsdeath)")
- addButton("RULES", openRules, 16, 27, 8, 10, colors.brown, colors.gold, colors.red, "RULES", false)
- winNorm.setBackgroundColor(colors.black)
- winNorm.setTextColor(colors.lightGray)
- center(winNorm, 11, "If you're ready to continue, enter ")
- center(winNorm, 12, "into the darkness to your right.")
- center(winNorm, 13, "Then pick a room and enjoy the game.")
- screenButton()
- os.startTimer(15)
- while true do
- event, param1, param2, param3 = os.pullEvent()
- if event == "timer" then
- os.startTimer(15)
- end
- if event == "monitor_touch" then
- print(tostring(checkxy(param2, param3)))
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment