Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local modem = peripheral.wrap("bottom")
- local monitors = {}
- local routers = {}
- local speakers = {}
- for i, v in pairs(modem.getNamesRemote()) do
- if string.find(v,"monitor") then
- table.insert(monitors, v)
- elseif string.find(v,"redrouter") then
- table.insert(routers, v)
- elseif string.find(v, "speaker") then
- table.insert(speakers, v)
- end
- end
- local won = false
- term.clear()
- io.write("Target Practice program by @the_orion.5, enjoy!\n")
- 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 play_speakers(instrument, pitch)
- for _, speaker in pairs(speakers) do
- modem.callRemote(speaker, "playNote", instrument, 3, pitch)
- end
- end
- function ding(pitch)
- play_speakers("harp", 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(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)
- play_speakers("cow_bell", 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 == 380 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.01)
- until os.time(os.date("*t")) >= _end
- fired = {}
- table.insert(scores, {player, 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()
- table.sort(scores, function(a,b)
- return a[2] > b[2]
- end)
- ding(24)
- for position, pack in pairs(scores) do
- local player, score = pack[1], pack[2]
- monitor_write(position..". Player ".. player..": "..score.." points,")
- cursor_down()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement