Mouamle

Number

Feb 18th, 2015
499
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.53 KB | None | 0 0
  1. -- Guess the Number, coded in Lua, for ComputerCraft by Kaleb702 is licensed under a
  2. -- Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
  3.  
  4. -- Initialization --
  5.  
  6. do
  7.     numb = math.random(1,100)
  8.     tries = 1
  9.     triesmax = 7
  10.     version = 1.1
  11.     win = false
  12. end
  13.  
  14. -- Intro --
  15.  
  16. do
  17.     term.clear()
  18.     textutils.slowPrint("-------------------------------")
  19.     textutils.slowPrint("Guess the Number V " .. version)
  20.     textutils.slowPrint("-------------------------------")
  21.     print("Enter to continue...")
  22.     io.read()
  23.     print("You have 6 guesses. Guess the number before you run out of guesses.")
  24. end
  25.  
  26. -- Main loop --
  27.  
  28. while true do
  29.     if tries > triesmax then
  30.         break
  31.     else
  32.         print("Guess. [1 - 100, whole number]")
  33.         guess = io.read()
  34.         guess = tonumber(guess)
  35.         if guess == numb then
  36.             win = true
  37.             break
  38.         else
  39.             print("Incorrect!")
  40.             if guess > numb then
  41.                 print("Your guess was too high.")
  42.             elseif guess < numb then
  43.                 print("Your guess was too low.")
  44.             else
  45.                 print("I have no idea what happened.")
  46.             end
  47.             tries = tries + 1
  48.         end
  49.     end
  50. end
  51.  
  52. -- Outro --
  53.  
  54. do
  55.     term.clear()
  56.     textutils.slowPrint("GAME OVER")
  57.     if win == true then
  58.         print("Winner: PLAYER")
  59.     else
  60.         print("Winner: COMPUTER")
  61.     end
  62.         textutils.slowPrint("Thank you for choosing Kapow Creations.")
  63. end
Add Comment
Please, Sign In to add comment