Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("displayAPI")
- --Peripherals
- local b = peripheral.wrap("bottom") -- Bridge Pos
- local d = peripheral.wrap("left") -- Monitor Pos
- --End Peripherals
- --Winner Config
- local dispwin = 2 -- How Long To Display Winner
- local wintxt = "And The Winner Is:" -- Winner Text
- local wintxtsz = 3 -- Winner Font Size
- --End Winner Config
- --Scoreboard Config
- local glasses = true -- Display on glasses? true/false
- local sbtxtsz = 3 -- Scoreboard Text Size
- --End Scoreboard Config
- term.clear()
- term.setCursorPos(1,1)
- d.clear()
- b.clear()
- function spairs(t, order)
- -- collect the keys
- local keys = {}
- for k in pairs(t) do keys[#keys+1] = k end
- -- if order function given, sort by it by passing the table and keys a, b,
- -- otherwise just sort the keys
- if order then
- table.sort(keys, function(a,b) return order(t, a, b) end)
- else
- table.sort(keys)
- end
- -- return the iterator function
- local i = 0
- return function()
- i = i + 1
- if keys[i] then
- return keys[i], t[keys[i]]
- end
- end
- end
- function cwrite(text)
- local w, h = d.getSize()
- local x, y = d.getCursorPos()
- x = math.max(math.floor((w/2) - (#text / 2)), 0)
- d.setCursorPos(x,y)
- text = string.upper(text)
- d.write(text)
- d.setCursorPos(x,y+1)
- end
- function pwrite(text)
- local w, h = d.getSize()
- local x,y = d.getCursorPos()
- x = math.max(math.floor((15/2) - (#text / 2)), 0)
- d.setCursorPos(x,y)
- text = string.upper(text)
- d.write(text)
- d.setCursorPos(x,y+1)
- end
- function twrite(text)
- local x2,y2 = term.getCursorPos()
- local x,y = term.getSize()
- term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
- print(text)
- end
- function winner(name)
- name = string.upper(name)
- d.clear()
- d.setCursorPos(1,6)
- d.setTextScale(wintxtsz)
- cwrite(wintxt)
- sleep(1)
- cwrite(name)
- for n,s in pairs(players) do
- if n == name then
- s = tostring(s+1)
- players[n] = s
- end
- end
- sleep(dispwin)
- scoreboard()
- end
- function refreshScreen()
- d.clear()
- scoreboard()
- end
- function restartGame()
- os.reboot()
- end
- function scoreboard()
- d.clear()
- term.clear()
- term.setCursorPos(1,8)
- twrite("Loneztar's Sheep Race")
- if players == nil then
- d.setCursorPos(1,4)
- d.setTextScale(3)
- cwrite("No Players Added")
- else
- d.setCursorPos(3,3)
- d.setTextScale(sbtxtsz)
- d.write("Players")
- d.setCursorPos(19,3)
- d.write("Score")
- d.setCursorPos(1,4)
- for name,score in spairs(players, function(t,a,b) return t[b] < t[a] end) do
- local h, v = d.getCursorPos()
- pwrite(name)
- d.setCursorPos(21,v)
- d.write(score)
- d.setCursorPos(h,v+1)
- end
- end
- end
- function addPlayer(name)
- name = string.upper(name)
- if players == nil then
- players = {}
- players[name] = "0"
- else
- players[name] = "0"
- end
- end
- function startScreen()
- term.setCursorPos(1,8)
- twrite("Loneztar's Sheep Race")
- term.setCursorPos(1,11)
- twrite("To Get Started")
- twrite("Type '$$Start' into your chat")
- d.clear()
- d.setCursorPos(1,6)
- d.setTextScale(3)
- cwrite("Loneztars'")
- cwrite("Sheep Race")
- d.setCursorPos(1,9)
- cwrite("$$start to begin!")
- end
- function help()
- if commandBox == nil then
- commandBox = b.addBox(10, 40, 95, 90, 0xffffff, 0.5)
- cmdx = commandBox.getX()
- cmdy = commandBox.getY()
- cmdop = commandBox.getOpacity()
- titleline = b.addBox(cmdx, cmdy+10, 95, 1, 0x000000, cmdop)
- cTitle = b.addText((cmdx+1), (cmdy+2), "Commands List:", 0x000000)
- local commands = {"addplayer <name>","winner <name>", "refresh", "RESTART"}
- vpos = cmdy+15
- for _,v in pairs(commands) do
- b.addText(cmdx+1,vpos, v,0x000000)
- vpos = vpos+10
- end
- else
- b.clear()
- end
- end
- while true do
- scoreboard()
- local e, msg = os.pullEvent("chat_command")
- local tWords = {}
- for match in string.gmatch(msg, "[^ \t]+" ) do
- table.insert( tWords, match )
- end
- --Commands List
- if tWords[1] == "winner" then
- winner(tWords[2])
- elseif tWords[1] == "refresh" then
- refreshScreen()
- elseif tWords[1] == "addplayer" then
- addPlayer(tWords[2])
- elseif tWords[1] == "RESTART" then
- restartGame()
- elseif tWords[1] == "help" then
- help()
- elseif tWords[1] == "start" then
- scoreboard()
- elseif tWords[1] == "begin" then
- startScreen()
- end
- -- End Commands
- end --whiletruedo
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement