Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Some stupid game thing by Mitchfizz05.
- Code under the GNU General Public License v3.
- ]]
- -- Constants.
- local version = 1.0
- local width,height = term.getSize()
- -- Current game variables.
- local score = 0
- local rounds = 9
- local key
- local countdown = 10
- -- Index of keys.
- local keys = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"}
- -- Render main menu.
- local function mainMenu()
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- term.clear()
- term.setCursorPos(1,1)
- term.setBackgroundColor(colors.blue)
- local bar = string.rep(" ", width)
- term.write(bar)
- term.setCursorPos(1,1)
- term.setTextColor(colors.white)
- term.write("Button Press Game Thing")
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- term.setCursorPos(1,3)
- print("Welcome to Button Press Game Thing. By Mitchfizz05.")
- print("")
- print(" Press enter key to start!")
- end
- -- Render countdown.
- local function countdownScreen()
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- term.clear()
- term.setCursorPos(1,1)
- term.setBackgroundColor(colors.blue)
- local bar = string.rep(" ", width)
- term.write(bar)
- term.setCursorPos(1,1)
- term.setTextColor(colors.white)
- term.write("Button Press Game Thing")
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- term.setCursorPos(1,3)
- term.write("Starting in " .. countdown .. " seconds...")
- end
- -- Render game screen.
- local function gameScreen()
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- term.clear()
- term.setCursorPos(1,1)
- term.setBackgroundColor(colors.blue)
- local bar = string.rep(" ", width)
- term.write(bar)
- term.setCursorPos(1,1)
- term.setTextColor(colors.white)
- term.write("Button Press Game Thing")
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- term.setCursorPos(1,3)
- term.write("Quick! Press... ")
- term.setTextColor(colors.red)
- term.write(key)
- term.setTextColor(colors.purple)
- term.setCursorPos(width - #"score: " - #tostring(score) - 1, 3)
- term.write("Score: " .. score)
- end
- -- Render time-up screen.
- local function timeupScreen()
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- term.clear()
- term.setCursorPos(1,1)
- term.setBackgroundColor(colors.blue)
- local bar = string.rep(" ", width)
- term.write(bar)
- term.setCursorPos(1,1)
- term.setTextColor(colors.white)
- term.write("Button Press Game Thing")
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- term.setCursorPos(1,3)
- term.write("Time up!")
- term.setCursorPos(3,5)
- term.setTextColor(colors.green)
- term.write("Score: ")
- term.setTextColor(colors.gray)
- term.write(math.floor(score))
- sleep(2)
- term.setCursorPos(1,7)
- term.setTextColor(colors.lightGray)
- term.write("Press any key to exit...")
- end
- -- Show menu.
- mainMenu()
- while true do
- local e,p1,p2,p3 = os.pullEvent()
- if e == "key" and p1 == 28 then
- break
- end
- end
- -- Run countdown.
- while (countdown > 0) do
- -- Trololol.
- if countdown > 6 and not countdown == 10 then
- if math.random(1,20) == 1 then
- -- Hehe.
- countdown = 1
- end
- end
- countdownScreen()
- sleep(1)
- countdown = countdown - 1
- end
- -- Main loop.
- while (rounds > 0) do
- -- Pick a random key.
- key = keys[math.random(1, #keys)]
- -- Print message.
- gameScreen()
- os.startTimer( math.random(1,20)/10 )
- while true do
- local e,p1,p2,p3 = os.pullEvent()
- if e == "char" and p1 == key then
- score = score + 2
- gameScreen()
- elseif e == "char" then
- score = score - 1
- gameScreen()
- elseif e == "timer" then
- break
- end
- end
- rounds = rounds - 1
- end
- -- Game finish.
- timeupScreen()
- -- Wait for exit.
- os.pullEvent("key")
- -- Cleanup for exit.
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorPos(1,1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement