Advertisement
Guest User

startup

a guest
Apr 19th, 2014
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 25.62 KB | None | 0 0
  1. --CONFIGURATION
  2.    
  3. server = 149 -- put the server's computer id here
  4. cursor = "[] " -- this is the cursor for the welcome screen
  5. cursor2 = "<> " -- this is the cursor for the actual Minebook
  6. maxUserNameLength = 10 --The max ammount of charecters allowed in a username
  7. banners = {"|       Only One       |", "|   Multiple Features  |", "|      Admin Added     |", "|    Super Addicting   |", "|  Updates Coming Soon |"} --This is the banners (what it says under RedBook 1.2) to learn how to add custum banners read the Banner ReadMe
  8.  
  9. -- Banner Template ^
  10.    
  11. --Do not touch anything below this unless you know what you are doing
  12.    
  13. function getFrq()
  14.     rednet.send(server, crntname.."!SP!chck frnd req two")
  15.     id, msg, d = rednet.receive(2)
  16.     frndNumTbl = split(msg, "!SP!")
  17.     if frndNumTbl ~= nil then
  18.         frndNum = #frndNumTbl
  19.     else
  20.         frndNum = 0
  21.     end
  22.     textutils.tabulate(frndNumTbl)
  23. end
  24.    
  25. function getMsgNumber()
  26.     rednet.send(server, crntname.."!SP!getMessages")
  27.     id, msg, d = rednet.receive(2)
  28.     t = textutils.unserialize(msg)
  29.     if t ~= nil then msgNumber = #t else msgNumber = 0 end
  30. end
  31.  
  32. function getMessages()
  33.     rednet.send(server, crntname.."!SP!getMessages")
  34.     id, msg, d = rednet.receive(2)
  35.     t = textutils.unserialize(msg)
  36.     number = #t
  37.     if number ~= 0 then
  38.         c = 1
  39.         while true do
  40.             shell.run("clear")
  41.             curent = t[c]
  42.             rednet.send(server, crntname.."!SP!getMessage!SP!"..curent)
  43.             id, msg2, d = rednet.receive(2)
  44.             parts = split(msg2, "!SP!")
  45.             sender = parts[1]
  46.             message = parts[2]
  47.             print("Sender: "..sender)
  48.             print("Subject: "..t[c])
  49.             print()
  50.             print("----------------------Message---------------------")
  51.             print(message)
  52.             print("--------------------------------------------------")
  53.             print(c.." out of "..number)
  54.             print("Press enter to erase")
  55.             read()
  56.             c = c+1
  57.             if c >= number+1 then
  58.                 msgNumber = 0
  59.                 break
  60.             end
  61.         end
  62.     else
  63.         shell.run("clear")
  64.         print("NO NEW MESSAGES")
  65.         read()
  66.     end
  67.     eraseMessages()
  68.     loadRandomCrap2()
  69. end
  70.  
  71. function eraseMessages()
  72.     rednet.send(server, crntname.."!SP!eraseMessages")
  73. end
  74.  
  75. function printMessageLayout()
  76.     shell.run("clear")
  77.     print("|------------To------------|")
  78.     print("|                          |")
  79.     print("|--------------------------|")
  80.     print()
  81.     print("|-------------Subject-------------|")
  82.     print("|                                 |")
  83.     print("|---------------------------------|")
  84.     print()
  85.     print("|---------------------Message--------------------|")
  86.     print("|                                                |")
  87.     print("|                                                |")
  88.     print("|------------------------------------------------|")
  89.     print()
  90.     print("Press ENTER twice to send")
  91.     composeMessage()
  92. end
  93.  
  94. function composeMessage()
  95.     term.setCursorPos(2,2)
  96.     recipient = read()
  97.     term.setCursorPos(2,6)
  98.     subject = read()
  99.     term.setCursorPos(2,10)
  100.     messageP1 = read()
  101.     term.setCursorPos(2,11)
  102.     messageP2 = read()
  103.     message = messageP1.." "..messageP2
  104.     if recipient ~= "" and subject ~= "" and message ~= "" then
  105.         message = crntname.."!SP!newMessage!SP!"..recipient.."!SP!"..subject.."!SP!"..message
  106.         check = split(message, "!SP!")
  107.         rednet.send(server, message)
  108.     end
  109.     loadRandomCrap2()
  110. end
  111.  
  112. function uploadScript()
  113.     shell.run("clear")
  114.     print("Pick a file to upload")
  115.     sApp = read()
  116.     if fs.exists(sApp) then
  117.             fProgram = fs.open(sApp, "r")
  118.             program = fProgram.readAll()
  119.             fProgram.close()
  120.             s = crntname.."!SP!uploadScript!SP!"..sApp.."!SP!"..program
  121.             rednet.send(server, s)
  122.             id, msg, d = rednet.receive(2)
  123.             if msg ~= nil then
  124.                 print(msg)
  125.                 os.sleep(2)
  126.             end
  127.             loadRandomCrap2()
  128.     else
  129.             shell.run("clear")
  130.             print("NOT A PROGRAM")
  131.             loadRandomCrap2()
  132.     end
  133. end
  134.  
  135. function browseScripts()
  136.     hj = crntname.."!SP!browseScripts!SP!"
  137.     rednet.send(server, hj)
  138.     id, msg, d = rednet.receive(2)
  139.     if msg == nil then
  140.         shell.run("Clear")
  141.         print("SERVER ERROR")
  142.         os.sleep(2)
  143.     else
  144.         t = textutils.unserialize(msg)
  145.         shell.run("clear")
  146.         textutils.tabulate(t)
  147.         print("")
  148.         print("Pick a software to download. If you dont want to download anything then type none")
  149.         print("")
  150.         term.write("Enter software: ")
  151.         app = read()
  152.         if app ~= "none" or "None" or "NOne" or "NONe" or "NONE" or "nONE" or "noNE" or "nonE" or "NoNe" or "nOne" or "noNe" or "nonE" or "nONe" or "nOnE" or "NonE" then
  153.             p = crntname.."!SP!downloadScript!SP!"..app
  154.             rednet.send(server, p)
  155.             id, smsg, d = rednet.receive(2)
  156.             if smsg ~= nil then
  157.                 nScript = fs.open(app, "w")
  158.                 nScript.write(smsg)
  159.                 nScript.close()
  160.             end
  161.         end
  162.     end
  163. loadRandomCrap2()
  164. end
  165.  
  166. function testLogIn()
  167.     shell.run("clear")
  168.     if msg1 == "YOU HAVE BEEN LOGGED IN" then
  169.         print(msg1..": "..crntname)
  170.         term.setCursorBlink(false)
  171.         read()
  172.     else
  173.         print(msg1)
  174.         term.setCursorBlink(false)
  175.         read()
  176.     end
  177.     if msg1 == "YOU HAVE BEEN LOGGED IN" then
  178.         pickNewBanner()
  179.         mineBook()
  180.     else
  181.         pickNewBanner()
  182.         loadRandomCrap()
  183.     end
  184. end
  185.  
  186. function errorQuit()
  187.     a = jkfdls+fjdsjfal
  188.     print(a)
  189. end
  190.  
  191. function searchUser()
  192.     shell.run("clear")
  193.     term.write("ENTER USER: ")
  194.     user2 = read()
  195.     if user2 ~= crntname then
  196.         sndsrch = crntname.."!SP!search!SP!"..user2
  197.         rednet.send(server, sndsrch)
  198.         id3, msg3, d3 = rednet.receive(5)
  199.         if msg3 ~= nil then
  200.             srch = split(msg3, "!SP!")
  201.             nuser = srch[1]
  202.             nstatus = srch[2]
  203.             nfriends = srch[3]
  204.             if nstatus == nil then
  205.                 nstatus = ""
  206.             end
  207.             shell.run("clear")
  208.             print("|||||||||||||||||||||||||||")
  209.             print("||                       ||")
  210.             print("||  USER SEARCH RESULTS  ||")
  211.             print("||                       ||")
  212.             print("|||||||||||||||||||||||||||")
  213.             print("")
  214.             print("")
  215.             print("User Name: "..nuser)
  216.             print("")
  217.             print("Status: "..nstatus)
  218.             print("")
  219.             print("")
  220.             print("PRESS S TO SEND FRIEND REQUEST OR E TO EXIT")
  221.             while true do
  222.                 event9, param9 = os.pullEvent()
  223.                 if event9 == "key" and param9 == 31 and nuser then
  224.                     sndmsg = crntname.."!SP!sndfrq!SP!"..nuser
  225.                     shell.run("clear")
  226.                     rednet.send(server, sndmsg)
  227.                     id8, msg8, d8 = rednet.receive(1)
  228.                     if msg8 == nil then
  229.                         print("REQUEST SENT")
  230.                         read()
  231.                         pickNewBanner()
  232.                         loadRandomCrap2()
  233.                         break
  234.                     else
  235.                         print("YOU ARE ALREADY FRIENDS WITH THIS PERSON")
  236.                         read()
  237.                         pickNewBanner()
  238.                         loadRandomCrap2()
  239.                         break
  240.                     end
  241.                 elseif event9 == "key" and param9 == 18 then
  242.                     pickNewBanner()
  243.                     loadRandomCrap2()
  244.                     break
  245.                 end
  246.             end
  247.         else
  248.             shell.run("clear")
  249.             print("SERVER ERROR")
  250.             read()
  251.             pickNewBanner()
  252.             loadRandomCrap2()
  253.         end
  254.     else
  255.         shell.run("clear")
  256.         print("YOU CAN NOT SEARCH YOURSELF")
  257.         sleep(1)
  258.         pickNewBanner()
  259.         loadRandomCrap2()
  260.     end
  261. end
  262.  
  263. function prntFrq()
  264.     shell.run("clear")
  265.     print("FRIEND REQUESTS")
  266.     print("")
  267.     print(frq[gcur])
  268.     print("")
  269.     print("PRESS A TO ACCEPT OR D TO DECLINE")
  270. end
  271.  
  272. function printFrndReq()
  273.     gcur = 1
  274.     prntFrq()
  275.     while true do
  276.         event2, param2 = os.pullEvent()
  277.         if event2 == "key" and param2 == 30 then
  278.             shell.run("clear")
  279.             print("USER ADDED")
  280.             ju = crntname.."!SP!add friend!SP!"..frq[gcur]
  281.             rednet.send(server, ju)
  282.             gcur = gcur+1
  283.             read()
  284.             if gcur > gmax then
  285.                 loadRandomCrap2()
  286.                 break
  287.             else
  288.                 prntFrq()
  289.             end
  290.         elseif event2 == "key" and param2 == 32 then
  291.             shell.run("clear")
  292.             print("USER DECLINED")
  293.             gcur = gcur+1
  294.             read()
  295.             if gcur > gmax then
  296.                 pickNewBanner()
  297.                 loadRandomCrap2()
  298.                 break
  299.             else
  300.                 prntFrq()
  301.             end
  302.         end
  303.     end
  304. end
  305.  
  306. function checkFrndReq()
  307.     jk = crntname.."!SP!chck frnd req"
  308.     rednet.send(server, jk)
  309.     id, msg, d = rednet.receive(5)
  310.     if msg ~= nil then
  311.         frq = split(msg, "!SP!")
  312.         gmax = #frq
  313.         gmin = 1
  314.         if gmax >= gmin then
  315.             shell.run("clear")
  316.             printFrndReq()
  317.             frndNum = 0
  318.         else
  319.             shell.run("clear")
  320.             print("NO NEW REQUESTS")
  321.             read()
  322.         end
  323.         loadRandomCrap2()
  324.     end
  325. end
  326.  
  327. function updateStatus()
  328.     shell.run("clear")
  329.     stat = read()
  330.     h = crntname.."!SP!status update!SP!"..stat
  331.     rednet.send(server, h)
  332.     g = fs.open("MINEBOOK/STATUS", "w")
  333.     g.write(stat)
  334.     g.close()
  335. end
  336.  
  337. function listFriends()
  338.     y = "list"
  339.     x = crntname.."!SP!"..y
  340.     rednet.send(server, x)
  341.     id, msg, d = rednet.receive(4)
  342.     if msg == nil then
  343.         shell.run("clear")
  344.         print("ERROR")
  345.         read()
  346.         loadRandomCrap2()
  347.     else
  348.         shell.run("clear")
  349.         r = split(msg, "!SP!")
  350.         print("FRIEND LIST")
  351.         textutils.tabulate(r)
  352.         read()
  353.         loadRandomCrap2()
  354.     end
  355. end
  356.  
  357. function testLogInTwo()
  358.     shell.run("clear")
  359.     print(msg2)
  360.     term.setCursorBlink(false)
  361.     read()
  362. end
  363.  
  364. function OpenAll()
  365.       --  for _,side in ipairs(rs.getSides()) do
  366.                 rednet.open("top")
  367.       --  end
  368. end
  369.  
  370. function gameMenu()
  371.    
  372.     g1 = "BlackJack"
  373.     g2 = "Exit"
  374.  
  375.     min = 1
  376.     max = 2
  377.     cur = min
  378.  
  379.     function loadRandomCrap3()
  380.         shell.run("clear")
  381.         print("|----------------------|")
  382.         print("|         Games        |")
  383.         print("|----------------------|")
  384.         if cur == 1 then
  385.             term.setCursorPos(1,8)
  386.             print(""..cursor2..""..g1.."")
  387.         else
  388.             term.setCursorPos(1,8)
  389.             print(g1)
  390.         end
  391.         if cur == 2 then
  392.             term.setCursorPos(1,9)
  393.             print(""..cursor2..""..g2.."")
  394.         else
  395.             term.setCursorPos(1,9)
  396.             print(g2)
  397.         end
  398.     end
  399.  
  400.     function runGames()
  401.         loadRandomCrap3()
  402.         while true do
  403.             event, param1 = os.pullEvent()
  404.             if event == "key" and param1 == 200 then
  405.                 if cur == min then
  406.                     cur = max
  407.                     loadRandomCrap3()
  408.                 else
  409.                     cur = cur-1
  410.                     loadRandomCrap3()
  411.                 end
  412.             elseif event == "key" and param1 == 208 then
  413.                 if cur == max then
  414.                     cur = min
  415.                     loadRandomCrap3()
  416.                 else
  417.                     cur = cur+1
  418.                     loadRandomCrap3()
  419.                 end
  420.             elseif event == "key" and param1 == 28 then
  421.                 if cur == 2 then
  422.                     shell.run("clear")
  423.                     min = 1
  424.                     max = 10
  425.                     cur = min
  426.                     pickNewBanner()
  427.                     loadRandomCrap2()
  428.                     break
  429.                 else
  430.                     printMenu()
  431.                 end
  432.             end
  433.         end
  434.     end
  435. runGames()
  436. end
  437.  
  438. function mineBook()
  439.    
  440.     getFrq()
  441.     getMsgNumber()
  442.    
  443.     w1 = "Search"
  444.     w2 = "Change Status"
  445.     w3 = "Friends"
  446.     w4 = "Check Friend Request"
  447.     w5 = "Upload a Script"
  448.     w6 = "Browse Scripts"
  449.     w7 = "Games"
  450.     w8 = "Send Message"
  451.     w9 = "Get Messages"
  452.     w10 = "Exit"
  453.    
  454.     min = 1
  455.     max = 10
  456.     cur = min
  457.    
  458.     function doThings2()
  459.         if cur == 3 then
  460.             listFriends()
  461.         elseif cur == 4 then
  462.             checkFrndReq()
  463.         elseif cur == 1 then
  464.             searchUser()
  465.         elseif cur == 2 then
  466.             updateStatus()
  467.             pickNewBanner()
  468.             loadRandomCrap2()
  469.         elseif cur == 5 then
  470.             uploadScript()
  471.         elseif cur == 6 then
  472.             browseScripts()
  473.         elseif cur == 7 then
  474.             gameMenu()
  475.         elseif cur == 8 then
  476.             printMessageLayout()
  477.         elseif cur == 9 then
  478.             getMessages()
  479.         end
  480.     end
  481.  
  482.  
  483.     function loadRandomCrap2()
  484.         OpenAll()
  485.         term.clear()
  486.         term.setCursorPos(1,1)
  487.         print("***** ")
  488.         print("**  **")
  489.         print("**   *")
  490.         print("**   *")
  491.         print("**  **")
  492.         print("*****")
  493.         print("")
  494.         term.setCursorPos(28, 1)
  495.         print("|----------------------|")
  496.         term.setCursorPos(28, 2)
  497.         print(banners[curBanner])
  498.         term.setCursorPos(28, 3)
  499.         print("|----------------------|")
  500.         term.setCursorPos(28, 4)
  501.         print("|Welcome: "..crntname)
  502.         term.setCursorPos(28, 5)
  503.         print("|New Messages: "..msgNumber)
  504.         term.setCursorPos(28, 6)
  505.         print("|Friend Requests: "..frndNum)
  506.         term.setCursorPos(28, 7)
  507.         print("|----------------------|")
  508.         term.setCursorPos(51, 1)
  509.         print("|")
  510.         term.setCursorPos(51, 3)
  511.         print("|")
  512.         term.setCursorPos(51, 4)
  513.         print("|")
  514.         term.setCursorPos(51, 5)
  515.         print("|")
  516.         term.setCursorPos(51, 6)
  517.         print("|")
  518.         if cur == 1 then
  519.             term.setCursorPos(1,9)
  520.             print(""..cursor2..""..w1.."")
  521.         else
  522.             term.setCursorPos(1,9)
  523.             print(w1)
  524.         end
  525.         if cur == 2 then
  526.             term.setCursorPos(1,10)
  527.             print(""..cursor2..""..w2.."")
  528.         else
  529.             term.setCursorPos(1,10)
  530.             print(w2)
  531.         end
  532.         if cur == 3 then
  533.             term.setCursorPos(1,11)
  534.             print(""..cursor2..""..w3.."")
  535.         else
  536.             term.setCursorPos(1,11)
  537.             print(w3)
  538.         end
  539.         if cur == 4 then
  540.             term.setCursorPos(1,12)
  541.             print(""..cursor2..""..w4.."")
  542.         else
  543.             term.setCursorPos(1,12)
  544.             print(w4)
  545.         end
  546.         if cur == 5 then
  547.             term.setCursorPos(1,13)
  548.             print(""..cursor2..""..w5.."")
  549.         else
  550.             term.setCursorPos(1,13)
  551.             print(w5)
  552.         end
  553.         if cur == 6 then
  554.             term.setCursorPos(1,14)
  555.             print(""..cursor2..""..w6.."")
  556.         else
  557.             term.setCursorPos(1,14)
  558.             print(w6)
  559.         end
  560.         if cur == 7 then
  561.             term.setCursorPos(1,15)
  562.             print(""..cursor2..""..w7.."")
  563.         else
  564.             term.setCursorPos(1,15)
  565.             print(w7)
  566.         end
  567.         if cur == 8 then
  568.             term.setCursorPos(1,16)
  569.             print(""..cursor2..""..w8.."")
  570.         else
  571.             term.setCursorPos(1,16)
  572.             print(w8)
  573.         end
  574.         if cur == 9 then
  575.             term.setCursorPos(1,17)
  576.             print(""..cursor2..""..w9.."")
  577.         else
  578.             term.setCursorPos(1,17)
  579.             print(w9)
  580.         end
  581.         if cur == 10 then
  582.             term.setCursorPos(1,18)
  583.             print(""..cursor2..""..w10.."")
  584.         else
  585.             term.setCursorPos(1,18)
  586.             print(w10)
  587.         end
  588.     end
  589.  
  590.     function runMineBook()
  591.         loadRandomCrap2()
  592.         while true do
  593.             event, param1 = os.pullEvent()
  594.             if event == "key" and param1 == 200 then
  595.                 if cur == min then
  596.                     cur = max
  597.                     loadRandomCrap2()
  598.                 else
  599.                     cur = cur-1
  600.                     loadRandomCrap2()
  601.                 end
  602.             elseif event == "key" and param1 == 208 then
  603.                 if cur == max then
  604.                     cur = min
  605.                     loadRandomCrap2()
  606.                 else
  607.                     cur = cur+1
  608.                     loadRandomCrap2()
  609.                 end
  610.             elseif event == "key" and param1 == 28 then
  611.                 if cur == 10 then
  612.                     shell.run("clear")
  613.                     min = 1
  614.                     max = 4
  615.                     cur = min
  616.                     pickNewBanner()
  617.                     loadRandomCrap()
  618.                     break
  619.                 end
  620.                 doThings2()
  621.             end
  622.         end
  623.     end
  624.     runMineBook()
  625. end
  626.  
  627. function split(str, pat)
  628.     local t = { }
  629.     local fpat = "(.-)"..pat
  630.     local last_end = 1
  631.     local s, e, cap = str:find(fpat, 1)
  632.         while s do
  633.             if s ~= 1 or cap ~= "" then
  634.                 table.insert(t,cap)
  635.             end
  636.             last_end = e+1
  637.             s, e, cap = str:find(fpat, last_end)
  638.         end
  639.         if last_end <= #str then
  640.             cap = str:sub(last_end)
  641.             table.insert(t, cap)
  642.     end
  643.     return t
  644. end
  645.  
  646. min = 1
  647. max = 4
  648. cur = min
  649.  
  650. function makeUser()
  651.     shell.run("clear")
  652.     term.write("ENTER DESIRED USERNAME: ")
  653.     term.setCursorPos(1,3)
  654.     term.write("ENTER DESIRED PASSWORD: ")
  655.     term.setCursorPos(1,5)
  656.     term.write("RE-ENTER DESIRED PASSWORD: ")
  657.     term.setCursorPos(26,1)
  658.     dusrnm = read()
  659.     term.setCursorPos(26,3)
  660.     dpw = read("*")
  661.     term.setCursorPos(29,5)
  662.     rdpw = read("*")
  663.     if dpw == rdpw then
  664.         if #dusrnm <= maxUserNameLength then
  665.             y = dusrnm.."!SP!makeUser!SP!"..dpw
  666.             rednet.send(server, y)
  667.             id2, msg2, d2 = rednet.receive(1)
  668.             if msg2 == nil then
  669.                 shell.run("clear")
  670.                 print("SERVER ERROR")
  671.                 read()
  672.                 loadRandomCrap()
  673.             else
  674.                 username = dusrnm
  675.                 rednet.send(server, username.."!SP!status update!SP!DEFAULT STATUS")
  676.                 testLogInTwo()
  677.             end
  678.         else
  679.             shell.run("clear")
  680.             print("USERNAME IS TOO LONG")
  681.             read()
  682.         end
  683.     else
  684.         shell.run("clear")
  685.         print("PASSWORDS DO NOT MATCH")
  686.         read()
  687.     end
  688. end
  689.  
  690. function logIn()
  691.     shell.run("clear")
  692.     term.write("ENTER USERNAME: ")
  693.     term.setCursorPos(1,3)
  694.     term.write("ENTER PASSWORD: ")
  695.     term.setCursorPos(17,1)
  696.     usrnm = read()
  697.     term.setCursorPos(17,3)
  698.     pswrd = read("*")
  699.     x = usrnm.."!SP!logIn!SP!"..pswrd
  700.     rednet.send(server, x)
  701.     id1, msg1, d1 = rednet.receive(1)
  702.     if msg1 == nil then
  703.         shell.run("clear")
  704.         print("SERVER ERROR")
  705.         read()
  706.         loadRandomCrap()
  707.     else
  708.         if msg1 == "YOU HAVE BEEN LOGGED IN" then
  709.             crntname = usrnm
  710.             testLogIn()
  711.         else
  712.             testLogIn()
  713.         end
  714.     end
  715. end
  716.  
  717. term.setCursorBlink(false)
  718.  
  719. s1 = "Log In"
  720. s2 = "Make Account"
  721. s3 = "Change Banner"
  722. s4 = "Exit"
  723.  
  724. function doThings()
  725.     if cur == 3 then
  726.         pickNewBanner()
  727.         loadRandomCrap()
  728.     elseif cur == 1 then
  729.         logIn()
  730.     elseif cur == 2 then
  731.         makeUser()
  732.         pickNewBanner()
  733.         loadRandomCrap()
  734.     end
  735. end
  736.  
  737. function pickNewBanner()
  738.     maxBannerNumber = #banners
  739.     curBanner = math.random(maxBannerNumber)
  740. end
  741.  
  742. function loadRandomCrap()
  743.     OpenAll()
  744.     term.clear()
  745.     term.setCursorPos(1,1)      
  746.     print("***** ")
  747.     print("**  **")
  748.     print("**   *")
  749.     print("**   *")
  750.     print("**  **")
  751.     print("*****")
  752.     print("")
  753.     term.setCursorPos(28, 1)
  754.     print("|----------------------|")
  755.     term.setCursorPos(28, 2)
  756.     print(banners[curBanner])
  757.     term.setCursorPos(28, 3)
  758.     print("|----------------------|")
  759.     print()
  760.     if cur == 1 then
  761.         term.setCursorPos(1,11)
  762.         print(""..cursor..""..s1.."")
  763.     else
  764.         term.setCursorPos(1,11)
  765.         print(s1)
  766.     end
  767.     if cur == 2 then
  768.         term.setCursorPos(1,12)
  769.         print(""..cursor..""..s2.."")
  770.     else
  771.         term.setCursorPos(1,12)
  772.         print(s2)
  773.     end
  774.     if cur == 3 then
  775.         term.setCursorPos(1,13)
  776.         print(""..cursor..""..s3.."")
  777.     else
  778.         term.setCursorPos(1,13)
  779.         print(s3)
  780.     end
  781.     if cur == 4 then
  782.         term.setCursorPos(1,14)
  783.         print(""..cursor..""..s4.."")
  784.     else
  785.         term.setCursorPos(1,14)
  786.         print(s4)
  787.     end
  788. end
  789.  
  790. function runProgram()
  791.     fs.makeDir("MINEBOOK")
  792.  
  793.     min = 1
  794.     max = 4
  795.     cur = min
  796.  
  797.     loadRandomCrap()
  798.     while true do
  799.         event, param1 = os.pullEvent()
  800.         if event == "key" and param1 == 200 then
  801.                 if cur == min then
  802.                         cur = max
  803.                         loadRandomCrap()
  804.                 else
  805.                     cur = cur-1
  806.                     loadRandomCrap()
  807.                 end
  808.         elseif event == "key" and param1 == 208 then
  809.             if cur == max then
  810.                 cur = min
  811.                 loadRandomCrap()
  812.             else
  813.                 cur = cur+1
  814.                 loadRandomCrap()
  815.             end
  816.         elseif event == "key" and param1 == 28 then
  817.             if cur == 4 then
  818.                 break
  819.             end
  820.             doThings()
  821.         end
  822.     end
  823. end
  824.  
  825. w,h = term.getSize()
  826.  
  827. function printCentered(height, value)
  828.   local xpos = w/2 - string.len(value)/2
  829.   term.setCursorPos(xpos, height)  
  830.   term.write(value)
  831. end
  832.  
  833. function pickCard()
  834.     pState = 1
  835.     NumberTens = {"J", "Q", "K"}
  836.     cTen = math.random(1, 3)
  837.     AllCards = {"1", "2", "3", "4", "5", "6", "7", "8", "9", NumberTens[cTen], "A"}
  838.     shell.run("clear")
  839.     ndCard = math.random(1, 11)
  840.     ndCard2 = math.random(1, 11)
  841.     ndCard3 = math.random(1, 11)
  842.     ndCard4 = math.random(1, 11)
  843.     ndCard5 = math.random(1, 11)
  844.     ndCard6 = math.random(1, 11)
  845.     dCard = AllCards[ndCard]
  846.     dCard2 = AllCards[ndCard2]
  847.     dCard3 = AllCards[ndCard3]
  848.     dCard4 = AllCards[ndCard4]
  849.     dCard5 = AllCards[ndCard5]
  850.     dCard6 = AllCards[ndCard6]
  851.     nCard = math.random(1, 11)
  852.     nCard2 = math.random(1, 11)
  853.     nCard3 = math.random(1, 11)
  854.     nCard4 = math.random(1, 11)
  855.     nCard5 = math.random(1, 11)
  856.     nCard6 = math.random(1, 11)
  857.     cCard = AllCards[nCard]
  858.     cCard2 = AllCards[nCard2]
  859.     cCard3 = AllCards[nCard3]
  860.     cCard4 = AllCards[nCard4]
  861.     cCard5 = AllCards[nCard5]
  862.     cCard6 = AllCards[nCard6]
  863.     print("Money: "..totalMoney)
  864.     term.write("Enter Bet: ")
  865.     bet = read()
  866.     totalMoney = totalMoney-bet
  867.     shell.run("clear")
  868.     print("BET: "..bet)
  869.     print("Your Cards:               Dealers Card:")
  870.     print()
  871.     print("|----|                      |----|")
  872.     print("|"..cCard.."   |                      |"..dCard.."   |")
  873.     print("|    |                      |    |")
  874.     print("|    |                      |    |")
  875.     print("|   "..cCard.."|                      |   "..dCard.."|")
  876.     print("|----|                      |----|")
  877.     print()
  878.     print("|----|                      |----|")
  879.     print("|"..cCard2.."   |                      ||||||")
  880.     print("|    |                      ||||||")
  881.     print("|    |                      ||||||")
  882.     print("|   "..cCard2.."|                      ||||||")
  883.     print("|----|                      |----|")
  884.     tpCard = nCard + nCard2
  885.     tdCard = ndCard + ndCard2
  886.     if tdCard == 21 then
  887.         print("DEALER HAS BLACKJACK")
  888.         printSubMenu()
  889.     else
  890.         print("Your total card number: "..tpCard)
  891.         printSubMenu()
  892.     end
  893. end
  894.  
  895. function hitOne()
  896.     pState = 2
  897.     tpCard = tpCard + nCard3
  898.     term.setCursorPos(7, 4)
  899.     print("|----|")
  900.     term.setCursorPos(7, 5)
  901.     print("|"..cCard3.."   |")
  902.     term.setCursorPos(7, 6)
  903.     print("|    |")
  904.     term.setCursorPos(7, 7)
  905.     print("|    |")
  906.     term.setCursorPos(7, 8)
  907.     print("|   "..cCard3.."|")
  908.     term.setCursorPos(7, 9)
  909.     print("|----|")
  910.     term.setCursorPos(1, 17)
  911.     print("Your total card number: "..tpCard)
  912. end
  913.  
  914. function hitTwo()
  915.     pState = 3
  916.     tpCard = tpCard + nCard4
  917.     term.setCursorPos(7, 11)
  918.     print("|----|")
  919.     term.setCursorPos(7, 12)
  920.     print("|"..cCard4.."   |")
  921.     term.setCursorPos(7, 13)
  922.     print("|    |")
  923.     term.setCursorPos(7, 14)
  924.     print("|    |")
  925.     term.setCursorPos(7, 15)
  926.     print("|   "..cCard4.."|")
  927.     term.setCursorPos(7, 16)
  928.     print("|----|")
  929.     term.setCursorPos(1, 17)
  930.     print("Your total card number: "..tpCard)
  931. end
  932.  
  933. function hitThree()
  934.     pState = 4
  935.     tpCard = tpCard + nCard5
  936.     term.setCursorPos(13, 4)
  937.     print("|----|")
  938.     term.setCursorPos(13, 5)
  939.     print("|"..cCard5.."   |")
  940.     term.setCursorPos(13, 6)
  941.     print("|    |")
  942.     term.setCursorPos(13, 7)
  943.     print("|    |")
  944.     term.setCursorPos(13, 8)
  945.     print("|   "..cCard5.."|")
  946.     term.setCursorPos(13, 9)
  947.     print("|----|")
  948.     term.setCursorPos(1, 17)
  949.     print("Your total card number: "..tpCard)
  950. end
  951.  
  952. function hitFour()
  953.     pState = 5
  954.     tpCard = tpCard + nCard6
  955.     term.setCursorPos(13, 11)
  956.     print("|----|")
  957.     term.setCursorPos(13, 12)
  958.     print("|"..cCard6.."   |")
  959.     term.setCursorPos(13, 13)
  960.     print("|    |")
  961.     term.setCursorPos(13, 14)
  962.     print("|    |")
  963.     term.setCursorPos(13, 15)
  964.     print("|   "..cCard6.."|")
  965.     term.setCursorPos(13, 16)
  966.     print("|----|")
  967.     term.setCursorPos(1, 17)
  968.     print("Your total card number: "..tpCard)
  969. end
  970.  
  971. function hitDealer()
  972.     tdCard = tdCard + ndCard3
  973.     term.setCursorPos(35, 4)
  974.     print("|----|")
  975.     term.setCursorPos(35, 5)
  976.     print("|"..dCard3.."   |")
  977.     term.setCursorPos(35, 6)
  978.     print("|    |")
  979.     term.setCursorPos(35, 7)
  980.     print("|    |")
  981.     term.setCursorPos(35, 8)
  982.     print("|   "..dCard3.."|")
  983.     term.setCursorPos(35, 9)
  984.     print("|----|")
  985.     term.setCursorPos(30, 17)
  986.     print("DEALER: "..tdCard)
  987. end
  988.  
  989. function hitDealerTwo()
  990.     tdCard = tdCard + ndCard4
  991.     term.setCursorPos(35, 11)
  992.     print("|----|")
  993.     term.setCursorPos(35, 12)
  994.     print("|"..dCard4.."   |")
  995.     term.setCursorPos(35, 13)
  996.     print("|    |")
  997.     term.setCursorPos(35, 14)
  998.     print("|    |")
  999.     term.setCursorPos(35, 15)
  1000.     print("|   "..dCard4.."|")
  1001.     term.setCursorPos(35, 16)
  1002.     print("|----|")
  1003.     term.setCursorPos(30, 17)
  1004.     print("DEALER: "..tdCard)
  1005. end
  1006.  
  1007. function hitDealerThree()
  1008.     tdCard = tdCard + ndCard5
  1009.     term.setCursorPos(41, 4)
  1010.     print("|----|")
  1011.     term.setCursorPos(41, 5)
  1012.     print("|"..dCard5.."   |")
  1013.     term.setCursorPos(41, 6)
  1014.     print("|    |")
  1015.     term.setCursorPos(41, 7)
  1016.     print("|    |")
  1017.     term.setCursorPos(41, 8)
  1018.     print("|   "..dCard5.."|")
  1019.     term.setCursorPos(41, 9)
  1020.     print("|----|")
  1021.     term.setCursorPos(30, 17)
  1022.     print("DEALER: "..tdCard)
  1023. end
  1024.  
  1025. function revealDealerCard()
  1026.     term.setCursorPos(29, 11)
  1027.     print("|----|")
  1028.     term.setCursorPos(29, 12)
  1029.     print("|"..dCard2.."   |")
  1030.     term.setCursorPos(29, 13)
  1031.     print("|    |")
  1032.     term.setCursorPos(29, 14)
  1033.     print("|    |")
  1034.     term.setCursorPos(29, 15)
  1035.     print("|   "..dCard2.."|")
  1036.     term.setCursorPos(29, 16)
  1037.     print("|----|")
  1038.     term.setCursorPos(30, 17)
  1039.     print("DEALER: "..tdCard)
  1040. end
  1041.  
  1042. function printMenu()
  1043.     cur = 1
  1044.     min = 1
  1045.     max = 3
  1046.     while true do
  1047.         drawMenu()
  1048.         event, param1 = os.pullEvent()
  1049.         if event == "key" and param1 == 208 then
  1050.             if cur == max then
  1051.                 cur = min
  1052.             else
  1053.                 cur = cur + 1
  1054.             end
  1055.         elseif event == "key" and param1 == 200 then
  1056.             if cur == min then
  1057.                 cur = max
  1058.             else
  1059.                 cur = cur - 1
  1060.             end
  1061.         elseif event == "key" and param1 == 28 then
  1062.             if cur == 2 then
  1063.                 totalMoney = 100
  1064.                 pickCard()
  1065.             elseif cur == 1 then
  1066.                 if totalMoney ~= nil then
  1067.                     pickCard()
  1068.                 else
  1069.                     totalMoney = 100
  1070.                     pickCard()
  1071.                 end
  1072.             elseif cur == 3 then
  1073.                 min = 1
  1074.                 max = 2
  1075.                 break
  1076.             end
  1077.         break
  1078.         end
  1079.     end
  1080. cur = 1
  1081. loadRandomCrap3()
  1082. end
  1083.  
  1084. function printSubMenu()
  1085.     ncur = 1
  1086.     nmax = 4
  1087.     nmin = 1
  1088.     while true do
  1089.         drawSubMenu()
  1090.         event1, param2 = os.pullEvent()
  1091.         if event1 == "key" and param2 == 205 then
  1092.             if ncur == nmax then
  1093.                 ncur = nmin
  1094.             else
  1095.                 ncur = ncur + 1
  1096.             end
  1097.         elseif event1 == "key" and param2 == 203 then
  1098.             if ncur == nmin then
  1099.                 ncur = nmax
  1100.             else
  1101.                 ncur = ncur - 1
  1102.             end
  1103.         elseif event1 == "key" and param2 == 28 then
  1104.             if ncur == 1 then
  1105.                 if pState == 1 then
  1106.                     hitOne()
  1107.                 elseif pState == 2 then
  1108.                     hitTwo()
  1109.                 elseif pState == 3 then
  1110.                     hitThree()
  1111.                 elseif pState == 4 then
  1112.                     hitFour()
  1113.                 end
  1114.             elseif ncur == 2 then
  1115.                 break
  1116.             elseif ncur == 3 then
  1117.                 revealDealerCard()
  1118.                 if tdCard < 17 then
  1119.                     hitDealer()
  1120.                 end
  1121.                 if tdCard < 17 then
  1122.                     hitDealerTwo()
  1123.                 end
  1124.                 if tdCard < 17 then
  1125.                     hitDealerThree()
  1126.                 end
  1127.                 read()
  1128.                 if tdCard > 21 then
  1129.                     tdCard = 0
  1130.                 end
  1131.                 if tpCard > 21 then
  1132.                     shell.run("CLEAR")
  1133.                     print("YOU BUST")
  1134.                     read()
  1135.                     break
  1136.                 elseif tpCard > tdCard then
  1137.                     shell.run("clear")
  1138.                     print("YOU WIN")
  1139.                     tBet = bet * 2
  1140.                     totalMoney = totalMoney + tBet
  1141.                     read()
  1142.                     break
  1143.                 elseif tpCard < tdCard then
  1144.                     shell.run("clear")
  1145.                     print("YOU LOOSE :(")
  1146.                     read()
  1147.                     break
  1148.                 end
  1149.             elseif ncur == 4 then
  1150.                 break
  1151.             end
  1152.         end
  1153.     end
  1154. printMenu()
  1155. end
  1156.  
  1157. function drawMenu()
  1158.     shell.run("clear")
  1159.     printCentered(1, "|-------------------------|")
  1160.     printCentered(2, "| RedBook Black Jack v1.0 |")
  1161.     printCentered(3, "|-------------------------|")
  1162.     if cur == 1 then
  1163.         printCentered(7, "[ CONTINUE GAME ]")
  1164.     else
  1165.         printCentered(7, "  CONTINUE GAME  ")
  1166.     end
  1167.     if cur == 2 then
  1168.         printCentered(8, "[ NEW GAME ]")
  1169.     else
  1170.         printCentered(8, "  NEW GAME  ")
  1171.     end
  1172.     if cur == 3 then
  1173.         printCentered(9, "[ EXIT ]")
  1174.     else
  1175.         printCentered(9, "  EXIT  ")
  1176.     end
  1177. end
  1178.  
  1179. function drawSubMenu()
  1180.   local ws = string.rep(" ", 4)
  1181.   local pr, ba, de, ne
  1182.   if ncur==1 then pr = "[ HIT ]" else pr = "  HIT  " end
  1183.   if ncur==2 then ba = "[ FOLD ]" else ba = "  FOLD  " end
  1184.   if ncur==3 then de = "[ STAND ]" else de = "  STAND  " end
  1185.   if ncur==4 then ne = "[ EXIT ]" else ne = "  EXIT  " end
  1186.   term.setCursorPos(1,h)
  1187.   printCentered(h, ws..pr..ws..ba..ws..de..ws..ne)
  1188. end
  1189.  
  1190. pickNewBanner()
  1191. runProgram()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement