Advertisement
j3d247

Untitled

Feb 16th, 2014
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.88 KB | None | 0 0
  1. os.loadAPI("displayAPI")
  2. --Peripherals
  3. local b = peripheral.wrap("bottom") -- Bridge Pos
  4. local d = peripheral.wrap("left") -- Monitor Pos
  5. --End Peripherals
  6.  
  7. --Winner Config
  8. local dispwin = 2 -- How Long To Display Winner
  9. local wintxt = "And The Winner Is:" -- Winner Text
  10. local wintxtsz = 3 -- Winner Font Size
  11. --End Winner Config
  12.  
  13. --Scoreboard Config
  14. local glasses = true -- Display on glasses? true/false
  15. local sbtxtsz = 3 -- Scoreboard Text Size
  16. --End Scoreboard Config
  17. term.clear()
  18. term.setCursorPos(1,1)
  19. d.clear()
  20.  
  21. function cwrite(text)
  22. local w, h = d.getSize()
  23. local x, y = d.getCursorPos()
  24. x = math.max(math.floor((w/2) - (#text / 2)), 0)
  25. d.setCursorPos(x,y)
  26. text = string.upper(text)
  27. d.write(text)
  28. d.setCursorPos(x,y+1)
  29. end
  30. function pwrite(text)
  31. local w, h = d.getSize()
  32. local x,y = d.getCursorPos()
  33. x = math.max(math.floor((15/2) - (#text / 2)), 0)
  34. d.setCursorPos(x,y)
  35. text = string.upper(text)
  36. d.write(text)
  37. d.setCursorPos(x,y+1)
  38. end
  39. function twrite(text)
  40. local x2,y2 = term.getCursorPos()
  41. local x,y = term.getSize()
  42. term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
  43. print(text)
  44. end
  45.  
  46. function winner(name)
  47. d.clear()
  48. d.setCursorPos(1,6)
  49. d.setTextScale(wintxtsz)
  50. cwrite(wintxt)
  51. sleep(1)
  52. cwrite(name)
  53. for n,s in pairs(players) do
  54. if n == name then
  55. players[n] = s+1
  56. end
  57. end
  58. players[name] = score
  59. sleep(dispwin)
  60. scoreboard()
  61. end
  62.  
  63. function refreshScreen()
  64. d.clear()
  65. scoreboard()
  66. end
  67.  
  68. function restartGame()
  69. os.reboot()
  70. end
  71.  
  72. function scoreboard()
  73. d.clear()
  74. term.clear()
  75. term.setCursorPos(1,8)
  76. twrite("Loneztar's Sheep Race")
  77. term.write(players)
  78. if not players == nil then
  79. d.setCursorPos(3,3)
  80. d.setTextScale(sbtxtsz)
  81. d.write("Players")
  82. d.setCursorPos(19,3)
  83. d.write("Score")
  84. -- Player Loop
  85. d.setCursorPos(1,4)
  86. for name,score in pairs(players) do
  87. pwrite(name)
  88. end
  89. -- Score Loop
  90. d.setCursorPos(21,4)
  91. for name,score in pairs(players) do
  92. local h, v = d.getCursorPos()
  93. d.write(score)
  94. d.setCursorPos(h,v+1)
  95. end
  96. else
  97. d.setCursorPos(1,4)
  98. cwrite("No Players Added")
  99. end
  100. end
  101.  
  102. function addPlayer(name)
  103. name = string.upper(name)
  104. if not players == nil then
  105. if not players[name] == nil then
  106. players[name] = "0"
  107. end
  108. else
  109. players = {}
  110. players[name] = "0"
  111. end
  112. end
  113.  
  114. function startScreen()
  115. term.setCursorPos(1,8)
  116. twrite("Loneztar's Sheep Race")
  117. term.setCursorPos(1,11)
  118. twrite("To Get Started")
  119. twrite("Type '$$Start' into your chat")
  120. d.clear()
  121. d.setCursorPos(1,6)
  122. d.setTextScale(3)
  123. cwrite("Loneztars'")
  124. cwrite("Sheep Race")
  125. d.setCursorPos(1,9)
  126. cwrite("$$start to begin!")
  127. end
  128.  
  129. function help()
  130. local opacity = 0
  131. local curopac = 0
  132. if commandBox.getOpacity == 0.5 then
  133. commandBox.setOpacity(0)
  134. elseif commandBox.getOpacity == 0 then
  135. commandBox.setOpacity(0.5)
  136. cmdx = commandBox.getX()
  137. cmdy = commandBox.getY()
  138. cmdop = commandBox.getOpacity()
  139. cTitle = b.addText((cmdx+1), (cmdy+2), "Commands List:", 0x000000)
  140. local commands = {"winner <name>", "refresh", "addplayer <name>", "RESTART"}
  141. vpos = cmdy+12
  142. for _,v in pairs(commands) do
  143. b.addText(cmdx+1,vpos, v,0x000000)
  144. vpos = vpos+10
  145. end
  146. end
  147. end
  148.  
  149. startScreen()
  150. while true do
  151. commandBox = b.addBox(10, 20, 80, 60, 0xffffff, 0)
  152. local e, msg = os.pullEvent("chat_command")
  153. b.clear()
  154.  
  155. local tWords = {}
  156. for match in string.gmatch(msg, "[^ \t]+" ) do
  157. table.insert( tWords, match )
  158. end
  159. -- Commands List
  160. if tWords[1] == "winner" then
  161. winner(tWords[2])
  162. elseif tWords[1] == "refresh" then
  163. refreshScreen()
  164. elseif tWords[1] == "addplayer" then
  165. addPlayer(tWords[2])
  166. elseif tWords[1] == "RESTART" then
  167. restartGame()
  168. elseif tWords[1] == "help" then
  169. help()
  170. elseif tWords[1] == "start" then
  171. while true do
  172. scoreboard()
  173. end
  174. end
  175. -- End Commands
  176. end --whiletruedo
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement