Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local modem = peripheral.wrap("bottom")
- local monitors = {"monitor_2", "monitor_3"}
- local routers = {4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22}
- local won = false
- io.write("Please input amount of players:\n")
- local input_players = tonumber(io.read())
- io.write("Please input amount of seconds per player:\n")
- local input_time = tonumber(io.read())
- io.write("Match starting..")
- function cursor_down()
- for _, monitor in pairs(monitors) do
- local x,y = modem.callRemote(monitor, "getCursorPos")
- modem.callRemote(monitor, "setCursorPos", 1, y+1)
- end
- end
- function ding(pitch)
- modem.callRemote("speaker_0", "playNote", "harp", 3, pitch)
- end
- function monitor_write(text)
- for _, monitor in pairs(monitors) do
- modem.callRemote(monitor,"write", text)
- end
- end
- function monitor_clear()
- for _, monitor in pairs(monitors) do
- modem.callRemote(monitor, "clear")
- end
- end
- function cursor_reset()
- for _, monitor in pairs(monitors) do
- modem.callRemote(monitor, "setCursorPos", 1,1)
- end
- end
- cursor_reset()
- local fired = {}
- local function find_in_table(item, tb)
- for _, v in pairs(tb) do
- if item == v then
- return true
- end
- end
- end
- function check_routers()
- local points = 0
- for _, router in pairs(routers) do
- result = modem.callRemote("redrouter_"..router, "getAnalogInput", "top")
- if result > 0 and not find_in_table(router, fired) then
- points = points + result
- table.insert(fired, router)
- end
- end
- return points
- end
- function buzz(pitch)
- modem.callRemote("speaker_0", "playNote", "cow_bell", 3, pitch)
- end
- local scores = {}
- for player = 1, input_players, 1 do
- local points = 0
- local start = os.time(os.date("*t"))
- local _end = start + input_time
- local cycles = 0
- ding(15)
- os.sleep(1)
- ding(16)
- os.sleep(1)
- ding(17)
- os.sleep(1)
- ding(24)
- repeat
- if cycles == 38 then
- table.remove(fired, 1)
- cycles = 0
- end
- cycles = cycles + 1
- monitor_clear()
- cursor_reset()
- monitor_write("Player "..player.."'s turn!")
- cursor_down()
- monitor_write(points.." points")
- points = points + check_routers()
- os.sleep(0.1)
- until os.time(os.date("*t")) >= _end
- fired = {}
- table.insert(scores, points)
- monitor_clear()
- cursor_reset()
- monitor_write("Time's up!")
- cursor_down()
- monitor_write("Player "..player.." got "..points.." points!")
- buzz(12)
- end
- monitor_clear()
- cursor_reset()
- local top_score = 0
- local top_player = 0
- for player, score in pairs(scores) do
- if score > top_score then
- top_player = player
- top_score = score
- end
- end
- monitor_write("Player "..top_player.." has won with..")
- cursor_down()
- monitor_write(top_score.."points!")
Add Comment
Please, Sign In to add comment