Advertisement
Guest User

Untitled

a guest
Jul 29th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. local s = 0
  2. local m = 0
  3. local names = {" ", "Nounours", "VB", "Farfie"}
  4. mon = peripheral.wrap("top")
  5. local start = false
  6. local best = {}
  7. local on = true
  8. local selectedName = 0
  9.  
  10. local function writeScreen(sec)
  11. local y = 2
  12. local lSec = 0
  13. local lMin = 0
  14.  
  15. --calculate to minutes and seconds
  16.  
  17. lMin = sec / 60
  18. lSec = sec % 60
  19.  
  20. mon.clear()
  21. mon.setCursorPos(1,y)
  22. mon.write("Time lapse:")
  23. mon.setCursorPos("1,3")
  24.  
  25. if sec < 10 then
  26. mon.write("0" .. lmin .. ":0" .. lsec)
  27. else
  28. mon.write("0" .. lmin .. ":" .. lsec)
  29. end
  30.  
  31. mon.setCursorPos("1,5")
  32. mon.write("Best Times:")
  33. --write name best score 1
  34. mon.setCursorPos("3,6")
  35. mon.write(best[0][0]])
  36. --write time best score 1
  37. mon.setCursorPos("13,6")
  38. mon.write(best[0][1]]])
  39.  
  40. --write name best score 2
  41. mon.setCursorPos("3,7")
  42. mon.write(Best[1][0]])
  43. --write time best score 2
  44. mon.setCursorPos("13,7")
  45. mon.write(best[0][1]]])
  46.  
  47. --write name best score 3
  48. mon.setCursorPos("3,8")
  49. mon.write(Best[2][0]])
  50. --write time best score 3
  51. mon.setCursorPos("13,8")
  52. mon.write(best[0][1]]])
  53.  
  54. mon.setCursorPos("2,10")
  55. mon.write("Player selected :" .. names[selectedName])
  56.  
  57.  
  58. end
  59.  
  60. local function checkHighScore(score,player)
  61. if score < best[2] then
  62. if score < best [1] then
  63. if score < best [0] then
  64. --best score
  65. best[0] = score
  66. else
  67. --second best score
  68. best[1] = score
  69. end
  70. else
  71. -- 3th best score
  72. best[2] = score
  73. end
  74. end
  75. end
  76.  
  77.  
  78. while on == true do
  79.  
  80.  
  81. -- check if start buttom is changed
  82. if redstone.getInput("left") == true then
  83. start = true
  84. s = (s+1)
  85. else
  86. if start == true then
  87. --player has completed course
  88. checkHighScore(s,names[selectedName])
  89. end
  90. start = false
  91.  
  92. end
  93.  
  94. -- chekc if reset button is pressed
  95. if redstone.getInput("Right") == true then
  96. s = 0
  97. m = 0
  98. end
  99.  
  100. --check if name change button is pressed
  101. if redstone.getInput("button") = true then
  102. selectedName = (selectedName + 1)
  103. if selectedName > 4 then
  104. selectedName = 0
  105. end
  106.  
  107. --write screen
  108. writeScreen(s)
  109.  
  110. --sleep for one second
  111. sleep(1)
  112.  
  113. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement