Advertisement
ComputerMan123

8-Ball

Feb 25th, 2017
2,635
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --[[
  2. **************
  3.      8-Ball
  4.  Recreated in CC
  5. **************
  6.  
  7. By: houseofkraft
  8. ]]--
  9.  
  10. -- Disables Native Terminating
  11. os.pullEvent = os.pullEventRaw
  12.  
  13. local responses = {
  14.   "Yes",
  15.   "No",
  16.   "Doubt it",
  17.   "Certainly",
  18.   "Without a doubt",
  19.   "Ask me again",
  20.   "I don't understand you",
  21.   "RIP",
  22.   "Uhhhh...",
  23.   "Okay then...",
  24.   "Yeah sure",
  25.   "Get me out of here!!!"
  26. }
  27.  
  28. local function writeColored( sColor, sText, newLine )
  29.   if newLine == nil then
  30.     newLine = true
  31.   end
  32.  
  33.   local oc = term.getTextColor()
  34.  
  35.   if term.isColor and term.isColor() then
  36.     term.setTextColor(sColor)
  37.   else
  38.     term.setTextColor(colors.white)
  39.   end
  40.    
  41.   write(sText)
  42.    
  43.   if newLine then
  44.     print()
  45.   end  
  46.   term.setTextColor(oc)
  47. end
  48.  
  49. term.clear()
  50. term.setCursorPos(1,1)
  51.  
  52. writeColored(colors.yellow, "The famous game of 8-Ball... now in CC!", true)
  53. writeColored(colors.yellow, "Type in a question and have it answered!", true)
  54. print()
  55.  
  56. local function init()
  57.   while true do
  58.     writeColored(colors.yellow, "8ball> ", false)
  59.     local sText = read()
  60.     textutils.slowPrint(responses[math.random(1, #responses)])
  61.   end
  62. end
  63.  
  64. local function onTerminate()
  65.   while true do
  66.     local event = os.pullEventRaw()
  67.     if event == "terminate" then
  68.       -- Draw the custom screen
  69.       term.clear()
  70.       term.setCursorPos(1,1)
  71.       writeColored(colors.blue, "I hope you enjoyed the game!")
  72.       writeColored(colors.blue, "Make sure to check 'houseofkraft' on the CC forums!")
  73.       break
  74.     end
  75.   end
  76. end
  77.  
  78. parallel.waitForAny(onTerminate, init)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement