AssortedBrunoz

mineee

Sep 7th, 2024
9
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.07 KB | None | 0 0
  1. local modem = peripheral.wrap("bottom")
  2.  
  3. local monitors = {"monitor_2", "monitor_3"}
  4.  
  5. local routers = {4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22}
  6.  
  7. local won = false
  8.  
  9. io.write("Please input amount of players:\n")
  10.  
  11. local input_players = tonumber(io.read())
  12.  
  13. io.write("Please input amount of seconds per player:\n")
  14.  
  15. local input_time = tonumber(io.read())
  16.  
  17. io.write("Match starting..")
  18.  
  19. function cursor_down()
  20. for _, monitor in pairs(monitors) do
  21. local x,y = modem.callRemote(monitor, "getCursorPos")
  22. modem.callRemote(monitor, "setCursorPos", 1, y+1)
  23. end
  24. end
  25.  
  26. function ding(pitch)
  27. modem.callRemote("speaker_0", "playNote", "harp", 3, pitch)
  28. end
  29.  
  30. function monitor_write(text)
  31. for _, monitor in pairs(monitors) do
  32. modem.callRemote(monitor,"write", text)
  33. end
  34. end
  35.  
  36. function monitor_clear()
  37. for _, monitor in pairs(monitors) do
  38. modem.callRemote(monitor, "clear")
  39. end
  40. end
  41.  
  42. function cursor_reset()
  43. for _, monitor in pairs(monitors) do
  44. modem.callRemote(monitor, "setCursorPos", 1,1)
  45. end
  46. end
  47. cursor_reset()
  48.  
  49. local fired = {}
  50.  
  51. local function find_in_table(item, tb)
  52. for _, v in pairs(tb) do
  53. if item == v then
  54. return true
  55. end
  56. end
  57. end
  58.  
  59. function check_routers()
  60. local points = 0
  61. for _, router in pairs(routers) do
  62. result = modem.callRemote("redrouter_"..router, "getAnalogInput", "top")
  63. if result > 0 and not find_in_table(router, fired) then
  64. points = points + result
  65. table.insert(fired, router)
  66. end
  67. end
  68. return points
  69. end
  70.  
  71. function buzz(pitch)
  72. modem.callRemote("speaker_0", "playNote", "cow_bell", 3, pitch)
  73. end
  74.  
  75. local scores = {}
  76.  
  77. for player = 1, input_players, 1 do
  78.  
  79. local points = 0
  80.  
  81. local start = os.time(os.date("*t"))
  82.  
  83. local _end = start + input_time
  84.  
  85. local cycles = 0
  86.  
  87. ding(15)
  88. os.sleep(1)
  89. ding(16)
  90. os.sleep(1)
  91. ding(17)
  92. os.sleep(1)
  93. ding(24)
  94.  
  95. repeat
  96. if cycles == 38 then
  97. table.remove(fired, 1)
  98. cycles = 0
  99. end
  100. cycles = cycles + 1
  101.  
  102. monitor_clear()
  103. cursor_reset()
  104.  
  105. monitor_write("Player "..player.."'s turn!")
  106. cursor_down()
  107. monitor_write(points.." points")
  108.  
  109. points = points + check_routers()
  110.  
  111. os.sleep(0.1)
  112.  
  113. until os.time(os.date("*t")) >= _end
  114.  
  115. fired = {}
  116.  
  117. table.insert(scores, points)
  118.  
  119. monitor_clear()
  120. cursor_reset()
  121.  
  122. monitor_write("Time's up!")
  123. cursor_down()
  124. monitor_write("Player "..player.." got "..points.." points!")
  125.  
  126. buzz(12)
  127.  
  128. end
  129.  
  130. monitor_clear()
  131. cursor_reset()
  132.  
  133. local top_score = 0
  134. local top_player = 0
  135.  
  136. for player, score in pairs(scores) do
  137. if score > top_score then
  138. top_player = player
  139. top_score = score
  140. end
  141. end
  142.  
  143. monitor_write("Player "..top_player.." has won with..")
  144. cursor_down()
  145.  
  146. monitor_write(top_score.."points!")
  147.  
Add Comment
Please, Sign In to add comment