Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Set up some variables
- local myNumber = math.random(1, 100)
- local tries = 0
- local maxTries = 5
- -- Display the intro
- term.clear()
- print("I'm thinking of a number between 1 and 100.")
- print("You have 5 tries to guess it!")
- -- The main game loop
- while true do
- -- Read the next guess from the user
- tries = tries + 1
- print("\nTry #" .. tries .. ". What's your guess?")
- local guess = tonumber(read())
- -- Compare the guess to my number
- if guess < myNumber then
- print("Too low!")
- elseif guess > myNumber then
- print("Too high!")
- else
- print("\nYou got it!")
- shootFireworks(5)
- break
- end
- -- Check if the user has used up their tries
- if tries == maxTries then
- print("\nBad luck, you ran out of tries!")
- break
- else
- print("Try again...")
- end
- end
- -- Shoot some fireworks!
- function shootFireworks(numFireworks)
- sleep(1)
- for i=1,numFireworks do
- redstone.setOutput("left", true)
- sleep(.2)
- redstone.setOutput("left", false)
- sleep(.2)
- end
- end
Add Comment
Please, Sign In to add comment