Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local s = 0
- local m = 0
- local names = {" ", "Nounours", "VB", "Farfie"}
- mon = peripheral.wrap("top")
- local start = false
- local best = {}
- local on = true
- local selectedName = 0
- local function writeScreen(sec)
- local y = 2
- local lSec = 0
- local lMin = 0
- --calculate to minutes and seconds
- lMin = sec / 60
- lSec = sec % 60
- mon.clear()
- mon.setCursorPos(1,y)
- mon.write("Time lapse:")
- mon.setCursorPos("1,3")
- if sec < 10 then
- mon.write("0" .. lmin .. ":0" .. lsec)
- else
- mon.write("0" .. lmin .. ":" .. lsec)
- end
- mon.setCursorPos("1,5")
- mon.write("Best Times:")
- --write name best score 1
- mon.setCursorPos("3,6")
- mon.write(best[0][0]])
- --write time best score 1
- mon.setCursorPos("13,6")
- mon.write(best[0][1]]])
- --write name best score 2
- mon.setCursorPos("3,7")
- mon.write(Best[1][0]])
- --write time best score 2
- mon.setCursorPos("13,7")
- mon.write(best[0][1]]])
- --write name best score 3
- mon.setCursorPos("3,8")
- mon.write(Best[2][0]])
- --write time best score 3
- mon.setCursorPos("13,8")
- mon.write(best[0][1]]])
- mon.setCursorPos("2,10")
- mon.write("Player selected :" .. names[selectedName])
- end
- local function checkHighScore(score,player)
- if score < best[2] then
- if score < best [1] then
- if score < best [0] then
- --best score
- best[0] = score
- else
- --second best score
- best[1] = score
- end
- else
- -- 3th best score
- best[2] = score
- end
- end
- end
- while on == true do
- -- check if start buttom is changed
- if redstone.getInput("left") == true then
- start = true
- s = (s+1)
- else
- if start == true then
- --player has completed course
- checkHighScore(s,names[selectedName])
- end
- start = false
- end
- -- chekc if reset button is pressed
- if redstone.getInput("Right") == true then
- s = 0
- m = 0
- end
- --check if name change button is pressed
- if redstone.getInput("button") = true then
- selectedName = (selectedName + 1)
- if selectedName > 4 then
- selectedName = 0
- end
- --write screen
- writeScreen(s)
- --sleep for one second
- sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement