Advertisement
Padilk

Untitled

Aug 21st, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. m = peripheral.wrap( "right" )
  2. modem = peripheral.wrap( "top" )
  3. porta = 13815
  4. portb = 13816
  5. modem.open(porta)
  6. m.setTextScale(2)
  7. x,y = m.getSize()
  8.  
  9.  
  10. m.clear()
  11.  
  12. direction = 0
  13.  
  14. --H H H /\
  15. --H H H \/
  16.  
  17. floors = {}
  18. for i=1,6 do
  19. floors[i]=false
  20. end
  21.  
  22. floorsCount=5
  23. currentFloor=3
  24. floors[2]=true
  25.  
  26. function setColors(X)
  27. if X == 0 then --blank
  28. m.setTextColor(colors.white)
  29. m.setBackgroundColor(colors.black)
  30. elseif X==1 then --inactive
  31. m.setTextColor(colors.lightGray)
  32. m.setBackgroundColor(colors.gray)
  33. elseif X==2 then --active
  34. m.setTextColor(colors.white)
  35. m.setBackgroundColor(colors.lightGray)
  36. elseif X==3 then --current
  37. m.setTextColor(colors.white)
  38. m.setBackgroundColor(700)
  39. end
  40.  
  41.  
  42. end
  43.  
  44. function redraw()
  45. setColors(0)
  46. m.clear()
  47. cf = 1
  48. for j=1,2 do
  49. for i=1,5 do
  50. m.setCursorPos(i,j)
  51. if i%2 == 1 and cf<=floorsCount then
  52. if cf==currentFloor then
  53. setColors(3)
  54. elseif floors[cf] == true then
  55. setColors(2)
  56. else
  57. setColors(1)
  58. end
  59. m.write(cf)
  60. cf = cf+1
  61. else
  62. setColors(0)
  63. m.write(" ")
  64. end
  65. end
  66. end
  67.  
  68. setColors(0)
  69. for i=6,9 do
  70. for j=1,2 do
  71. m.setCursorPos(i,j)
  72. m.write(" ")
  73. end
  74. end
  75.  
  76. if direction == 1 then
  77. m.setCursorPos(7,1)
  78. m.write("/\\")
  79. elseif direction == -1 then
  80. m.setCursorPos(7,2)
  81. m.write("\/")
  82. else
  83. m.setCursorPos(7,1)
  84. m.write("||")
  85. m.setCursorPos(7,2)
  86. m.write("||")
  87. end
  88. end
  89.  
  90. function sendCommand(X)
  91. print("SEND "..X)
  92. end
  93.  
  94. function controlAction()
  95. q = 0
  96.  
  97. floors[currentFloor] = false
  98.  
  99. for i=1,floorsCount do
  100. if floors[i] then q = q+1 end
  101. end
  102.  
  103. if q == 0 then
  104. direction = 0
  105. elseif direction == 0 then
  106. if q ~= 0 then
  107. nq = 1
  108. for i=1,floorsCount do
  109. if floors[i] then
  110. nq = i
  111. end
  112. end
  113. if nq<current then
  114. direction = 1
  115. else
  116. direction = -1
  117. end
  118. sendCommand(nq)
  119. end
  120. elseif direction == 1 then
  121. nq = 0
  122. for i=1,currentFloor do
  123. if floors[i] then
  124. nq = i
  125. end
  126. end
  127. if nq == 0 then
  128. for i=1,floorsCount do
  129. if floors[i] then
  130. nq = i
  131. end
  132. end
  133. end
  134. if nq<current then
  135. direction = 1
  136. else
  137. direction = -1
  138. end
  139. sendCommand(nq)
  140. elseif direction == -1 then
  141. nq = 0
  142. for i=floorsCount,currentFloor,-1 do
  143. if floors[i] then
  144. nq = i
  145. end
  146. end
  147. if nq == 0 then
  148. for i=1,floorsCount do
  149. if floors[i] then
  150. nq = i
  151. end
  152. end
  153. end
  154. if nq<current then
  155. direction = 1
  156. else
  157. direction = -1
  158. end
  159. sendCommand(nq)
  160. end
  161.  
  162. end
  163.  
  164. redraw()
  165. while true do
  166. event = {os.pullEvent()}
  167. if event[1] == "monitor_touch" then
  168. print("Touch at "..event[3]..":"..event[4])
  169. if event[3]%2 ~= 0 and event[3]<6 then
  170. num = (event[3]+1)/2+3*(event[4]-1)
  171.  
  172. if num <= floorsCount then
  173. floors[num] = not floors[num]
  174. redraw()
  175. end
  176. end
  177. elseif event[1] == "modem_message" then
  178. print(event[5])
  179. end
  180.  
  181. controlAction()
  182. redraw()
  183. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement