Advertisement
CodeCrafter

Admin

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