InfinityDark

Bankomat Original

Nov 5th, 2018
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.32 KB | None | 0 0
  1. --|============================|
  2. --| Bankomat. |
  3. --| Автор: SkyDrive_ |
  4. --| Проект McSkill, cервер TM |
  5. --| 25.09.2018 |
  6. --| Version: 1.00 |
  7. --|============================|
  8. local component = require("component")
  9. local computer=require("computer")
  10. local event = require("event")
  11. local term = require("term")
  12. local shell = require("shell")
  13. local fs = require("filesystem")
  14. local unicode=require("unicode")
  15. local serial = require("serialization")
  16. if not fs.exists("/lib/Sky.lua") then
  17. shell.execute("wget https://pastebin.com/raw/uL180xek /lib/Sky.lua")
  18. end
  19. local sky = require("Sky")
  20. local g = component.gpu
  21. event.shouldInterrupt = function () return false end
  22. --------------------Настройки--------------------
  23. local WIDTH, HEIGHT = 49, 24 --Разрешение моника
  24. local AUTOEXIT = 30 --Автовыход через n сек.
  25. local TONE = 600 --Тональность звука
  26. local MAX_OPERATION = 2000
  27. local MONEY_ITEM_ID = 5122
  28. local COLOR1 = 0x00ff00 --Рамка
  29. local COLOR2 = 0x333333 --Цвет кнопок
  30. -------------------------------------------------
  31. print("\nИнициализация...")
  32. os.sleep(2)
  33. print("Запуск программы...")
  34. os.sleep(2)
  35.  
  36. local mid = WIDTH / 2
  37. local login = false
  38. local summa = 0
  39. local timer = 0
  40. local timeClear = 0
  41.  
  42. function drawStart()
  43. g.setResolution(WIDTH, HEIGHT)
  44. sky.logo("Bankomat", COLOR1, COLOR2, WIDTH, HEIGHT)
  45. g.setForeground(COLOR2)
  46. sky.mid(WIDTH, 6, "───────────────────────────────────")
  47. sky.mid(WIDTH, 11, "▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔")
  48. g.setForeground(COLOR1)
  49. sky.word(10, 7, "bank", COLOR2)
  50. sky.button(16,17,18,3,COLOR1,COLOR2, "Залогиниться")
  51. end
  52.  
  53. function Exit()
  54. login = false
  55. summa = 0
  56.  
  57. drawStart()
  58.  
  59. local users={computer.users()}
  60. for i=1, #users do
  61. computer.removeUser(users[i])
  62. end
  63. end
  64.  
  65. function drawBalance(nick)
  66. local balance = sky.money(nick)
  67. sky.mid(WIDTH, 8, " ")
  68. g.setForeground(COLOR1)
  69. sky.mid(WIDTH, 8, "[ " .. balance .. " ]")
  70. end
  71.  
  72. function Logic(w,h,nick)
  73. if sky.pressButton(w,h,{5,11,8,3}) then
  74. summa = summa + 1
  75. computer.beep(TONE, 0.05)
  76. elseif sky.pressButton(w,h,{5,14,8,3}) then
  77. summa = summa + 10
  78. computer.beep(TONE, 0.05)
  79. elseif sky.pressButton(w,h,{5,17,8,3}) then
  80. summa = summa + 100
  81. computer.beep(TONE, 0.05)
  82. elseif sky.pressButton(w,h,{38,11,8,3}) then
  83. summa = summa - 1
  84. computer.beep(TONE, 0.05)
  85. elseif sky.pressButton(w,h,{38,14,8,3}) then
  86. summa = summa - 10
  87. computer.beep(TONE, 0.05)
  88. elseif sky.pressButton(w,h,{38,17,8,3}) then
  89. summa = summa - 100
  90. computer.beep(TONE, 0.05)
  91. elseif sky.pressButton(w,h,{14,14,11,3}) then
  92. sky.mid(WIDTH, 21, " ")
  93. timeClear = 3
  94. if summa == 0 then
  95. g.setForeground(0xff0000)
  96. sky.mid(WIDTH, 21, "Введите сумму")
  97. g.setForeground(COLOR1)
  98. elseif sky.checkMoney(nick, summa) then
  99. --sky.com("give " .. nick .. " " .. MONEY_ITEM_ID .. " " .. summa)
  100.  
  101. local ostatok = sky.giveItem(nick, MONEY_ITEM_ID, summa)
  102.  
  103. if ostatok == 0 then
  104. sky.mid(WIDTH, 21, "Операция выполнена")
  105. else
  106. local t = "&2Инвентарь полон, &4" .. ostatok .. " &2возвращено"
  107. sky.com("money give " .. nick .. " " .. ostatok)
  108. sky.text(WIDTH/2 - (unicode.len(t)-6)/2, 21, t)
  109. timeClear = 5
  110. end
  111. summa = 0
  112. else
  113. g.setForeground(0xff0000)
  114. sky.mid(WIDTH, 21, "Недостаточно средств")
  115. g.setForeground(COLOR1)
  116. end
  117. drawBalance(nick)
  118. computer.beep(TONE, 0.05)
  119. elseif sky.pressButton(w,h,{26,14,11,3}) then
  120. sky.mid(WIDTH, 21, " ")
  121. timeClear = 3
  122. if summa == 0 then
  123. g.setForeground(0xff0000)
  124. sky.mid(WIDTH, 21, "Введите сумму")
  125. g.setForeground(COLOR1)
  126. elseif sky.takeItem(nick, MONEY_ITEM_ID, summa) then
  127. sky.com("money give " .. nick .. " " .. summa)
  128. summa = 0
  129. sky.mid(WIDTH, 21, "Операция выполнена")
  130. else
  131. g.setForeground(0xff0000)
  132. sky.mid(WIDTH, 21, "Недостаточно средств")
  133. g.setForeground(COLOR1)
  134. end
  135. drawBalance(nick)
  136. computer.beep(TONE, 0.05)
  137. end
  138.  
  139. if summa < 0 then
  140. summa = 0
  141. elseif summa > MAX_OPERATION then
  142. summa = MAX_OPERATION
  143. end
  144.  
  145. local text = "&0Сумма: &2" .. summa .. "$"
  146. sky.mid(WIDTH, 12, " ")
  147. sky.text(WIDTH/2 - (unicode.len(text)-4)/2, 12, text)
  148. end
  149.  
  150. function Login(w,h,nick)
  151. if (sky.pressButton(w,h,{16,17,18,3}) and not (login)) then
  152. computer.addUser(nick)
  153. login = true
  154. g.fill(3, 2, WIDTH-4, HEIGHT-2, " ")
  155. g.setForeground(COLOR2)
  156. sky.mid(WIDTH,4,"Добро пожаловать")
  157. sky.mid(WIDTH,7,"Ваш баланс:")
  158. g.setForeground(COLOR1)
  159. sky.mid(WIDTH,5,nick)
  160. drawBalance(nick)
  161.  
  162. sky.button(5,11,8,3,COLOR1,COLOR2,"+1")
  163. sky.button(5,14,8,3,COLOR1,COLOR2,"+10")
  164. sky.button(5,17,8,3,COLOR1,COLOR2,"+100")
  165.  
  166. sky.button(38,11,8,3,COLOR1,COLOR2,"-1")
  167. sky.button(38,14,8,3,COLOR1,COLOR2,"-10")
  168. sky.button(38,17,8,3,COLOR1,COLOR2,"-100")
  169.  
  170.  
  171. sky.button(14,14,11,3,COLOR1,COLOR2,"Снять")
  172. sky.button(26,14,11,3,COLOR1,COLOR2,"Внести")
  173.  
  174.  
  175. sky.button(14,17,23,3,COLOR1,COLOR2,"Выход")
  176. computer.beep(TONE, 0.05)
  177. elseif (sky.pressButton(w,h,{14,17,23,3}) and login) then
  178. computer.beep(TONE, 0.05)
  179. Exit()
  180. end
  181. end
  182.  
  183. function autoExit()
  184. timer = timer - 1
  185. g.setForeground(COLOR2)
  186. g.set(WIDTH/2 - 9, 22, "Авто выход через:")
  187. if timer <= 10 then
  188. g.setForeground(0xff0000)
  189. else
  190. g.setForeground(COLOR1)
  191. end
  192. g.set(WIDTH/2 + 9, 22, timer .. " ")
  193. end
  194.  
  195. Exit()
  196.  
  197. while true do
  198. local e,_,w,h,_,nick = event.pull(1, "touch")
  199. if e == "touch" then
  200. Login(w,h,nick)
  201. if (login) then
  202. Logic(w,h,nick)
  203. end
  204. timer = AUTOEXIT
  205. end
  206. if (login) then
  207. autoExit()
  208. if timer == 0 then
  209. Exit()
  210. end
  211. if timeClear > 0 then
  212. timeClear = timeClear -1
  213. if timeClear == 0 then
  214. sky.mid(WIDTH, 21, " ")
  215. end
  216. end
  217. end
  218. end
Add Comment
Please, Sign In to add comment