Advertisement
SanyaRamzik

GUI-Casino

Apr 17th, 2020 (edited)
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 14.84 KB | None | 0 0
  1. local component = require('component')
  2. local gpu=component.gpu
  3. local rs=component.redstone
  4. local computer = require('computer')
  5. local event=require('event')
  6. local pull_e = event.pull
  7. local W, H = gpu.getResolution()
  8. b_color, f_color = gpu.getBackground(), gpu.getForeground()
  9. local timeout=30
  10. log_nickname="TEST"
  11. local status='.'
  12. try_count = 0
  13. local gift_toggle=false
  14. local me_if = component.proxy("6d7f0c13-a813-4b67-be66-3e922a22222c")
  15. local me_gift=component.proxy("c5256e66-ae19-4bb6-a798-a9e86b33b251")
  16.  
  17.  
  18. gift_list={
  19.  
  20. {
  21. "dwcity:Powder11",
  22. "IC2:itemOreIridium",
  23. "DraconicEvolution:draconicIngot",
  24. "GraviSuite:advNanoChestPlate",
  25. "CompactSolars:CompactSolarBlock"
  26. },
  27.  
  28. {
  29. "DraconicEvolution:wevernCore",
  30. "minecraft:nether_star",
  31. "IC2:itemArmorQuantumHelmet",
  32. "IC2:itemArmorQuantumChestplate",
  33. "IC2:itemArmorQuantumLegs",
  34. "IC2:itemArmorQuantumBoots",
  35. "CompactSolars:CompactSolarBlock"
  36. },
  37.  
  38. {
  39. "GraviSuite:graviChestPlate",
  40. "CompactSolar:CompactSolarBlock"
  41. }
  42.  
  43. }
  44.  
  45. function event.shouldInterrupt()
  46.     return false
  47. end
  48.  
  49. function check_timeout()
  50.   if timeout<=0 then
  51.     logOut()
  52.     return false
  53.   end
  54.   timeout=timeout-1;
  55.   set_str_timeout()
  56. end
  57.  
  58. background_color=0x000040
  59.  
  60. function drawItem_Heart(x,y)
  61.   gpu.setBackground(0)
  62.   gpu.setForeground(0)
  63.   gpu.fill(x,y,4,1,'x');  gpu.fill(x+7,y,4,1,'x')
  64.   gpu.fill(x-1,y+1,1,1,'x');  gpu.fill(x+4,y+1,1,1,'x');  gpu.fill(x+6,y+1,1,1,'x');  gpu.fill(x+11,y+1,1,1,'x')
  65.   gpu.fill(x-2,y+2,1,2,'x');  gpu.fill(x+4,y+2,1,1,'x');  gpu.fill(x+12,y+2,1,2,'x');
  66.   gpu.fill(x-1,y+4,1,1,'x'); gpu.fill(x+11,y+4,1,1,'x')
  67.   gpu.fill(x,y+5,1,1,'x');  gpu.fill(x+10,y+5,1,1,'x')
  68.   gpu.fill(x+1,y+6,1,1,'x');  gpu.fill(x+9,y+6,1,1,'x')
  69.   gpu.fill(x+2,y+7,1,1,'x');  gpu.fill(x+8,y+7,1,1,'x')
  70.   gpu.fill(x+3,y+8,1,1,'x');  gpu.fill(x+7,y+8,1,1,'x')
  71.   gpu.fill(x+4,y+9,1,1,'x');  gpu.fill(x+6,y+9,1,1,'x')
  72.  
  73.   gpu.setBackground(0xFF0040);
  74.   gpu.setForeground(0xFF0040);
  75.   gpu.fill(x,y+1,4,1,'x');  gpu.fill(x+7,y+1,4,1,'x')
  76.   gpu.fill(x-1,y+2,13,2,'x')
  77.   gpu.fill(x,y+4,11,1,'x')
  78.   gpu.fill(x+1,y+5,9,1,'x')
  79.   gpu.fill(x+2,y+6,7,1,'x')
  80.   gpu.fill(x+3,y+7,5,1,'x')
  81.   gpu.fill(x+4,y+8,3,1,'x')
  82.   gpu.fill(x+5,y+9,1,1,'x')
  83.  
  84.   gpu.setBackground(0xFFFFFF)
  85.   gpu.setForeground(0xFFFFFF)
  86.   gpu.fill(x,y+2,3,1,'x')
  87.   gpu.fill(x,y+3,1,1,'x')
  88.  
  89.   gpu.setBackground(0x003340)
  90.   gpu.setForeground(0x003340)
  91.   gpu.fill(x+11,y+5,1,1,'x')
  92.   gpu.fill(x+10,y+6,1,1,'x')
  93.   gpu.fill(x+9,y+7,1,1,'x')
  94.   gpu.fill(x+8,y+8,1,1,'x')
  95.   gpu.fill(x+7,y+9,1,1,'x')
  96.   gpu.fill(x+6,y+10,1,1,'x')
  97. end
  98.  
  99. function drawItem_Diamond(x,y)
  100. gpu.setBackground(0);
  101. gpu.setForeground(0);
  102. gpu.fill(x,y,6,1,'x')
  103. gpu.fill(x-1,y+1,1,1,'x');  gpu.fill(x+6,y+1,1,1,'x')
  104. gpu.fill(x-2,y+2,1,1,'x');  gpu.fill(x+7,y+2,1,1,'x')
  105. gpu.fill(x-3,y+3,1,2,'x');  gpu.fill(x+8,y+3,1,2,'x')
  106. gpu.fill(x-4,y+5,1,2,'x');  gpu.fill(x+9,y+5,1,2,'x')
  107. gpu.fill(x-3,y+7,1,1,'x');  gpu.fill(x+8,y+7,1,1,'x')
  108. gpu.fill(x-2,y+8,1,1,'x');  gpu.fill(x+7,y+8,1,1,'x')
  109. gpu.fill(x-1,y+9,8,1,'x')
  110.  
  111. gpu.setBackground(0xFFFFFF)
  112. gpu.setForeground(0xFFFFFF)
  113. gpu.fill(x,y+1,6,1,'x')
  114. gpu.fill(x-1,y+2,1,1,'x');  gpu.fill(x+3,y+3,2,1,'x')
  115. gpu.fill(x-2,y+4,1,1,'x');  gpu.fill(x+1,y+4,1,1,'x')
  116. gpu.fill(x-3,y+5,1,2,'x')
  117.  
  118. gpu.setBackground(0x00B6FF)
  119. gpu.setForeground(0x00B6FF)
  120. gpu.fill(x,y+2,7,1,'x')
  121. gpu.fill(x-2,y+3,5,1,'x');  gpu.fill(x+5,y+3,3,1,'x')
  122. gpu.fill(x-1,y+4,2,1,'x');  gpu.fill(x+2,y+4,6,1,'x')
  123. gpu.fill(x-2,y+5,11,2,'x')
  124. gpu.fill(x-2,y+7,10,1,'x')
  125. gpu.fill(x-1,y+8,8,1,'x')  
  126.  
  127. gpu.setBackground(0x336D80)
  128. gpu.setForeground(0x336D80)
  129. gpu.fill(x+6,y+4,2,1,'x')
  130. gpu.fill(x,y+6,6,1,'x')
  131. gpu.fill(x-1,y+7,1,1,'x');  gpu.fill(x+6,y+7,1,1,'x')
  132.  
  133. gpu.setBackground(0x33B5C0)
  134. gpu.setForeground(0x33B6C0)
  135. gpu.fill(x+5,y+4,1,2,'x')
  136. end
  137.  
  138. function drawItem_Apple(x,y)
  139. gpu.setBackground(0)
  140. gpu.setForeground(0)
  141. gpu.fill(x+5,y,1,2,'x')
  142. gpu.fill(x+4,y+2,1,1,'x')
  143. gpu.fill(x+1,y+3,6,1,'x')
  144. gpu.fill(x-1,y+4,2,1,'x');  gpu.fill(x+7,y+4,2,1,'x')
  145. gpu.fill(x-2,y+5,1,1,'x');  gpu.fill(x+9,y+5,1,1,'x')
  146. gpu.fill(x-3,y+6,1,2,'x');  gpu.fill(x+10,y+6,1,2,'x')
  147. gpu.fill(x-2,y+8,1,1,'x');  gpu.fill(x+9,y+8,1,1,'x')
  148. gpu.fill(x-1,y+9,1,1,'x');  gpu.fill(x+8,y+9,1,1,'x')
  149. gpu.fill(x,y+10,3,1,'x');  gpu.fill(x+5,y+10,3,1,'x')
  150.  
  151. gpu.setBackground(0xFFDB00)
  152. gpu.setForeground(0xFFDB00)
  153. gpu.fill(x+1,y+4,6,1,'x')
  154. gpu.fill(x-1,y+5,10,1,'x')
  155. gpu.fill(x-2,y+6,12,2,'x')
  156. gpu.fill(x-1,y+8,10,1,'x')
  157. gpu.fill(x,y+9,8,1,'x')
  158.  
  159. gpu.setBackground(0xFFB600)
  160. gpu.setForeground(0xFFB600)
  161. gpu.fill(x+6,y+5,3,1,'x')
  162. gpu.fill(x+8,y+6,2,2,'x')
  163. gpu.fill(x-2,y+7,1,1,'x');  gpu.fill(x+7,y+8,2,1,'x')
  164. gpu.fill(x,y+9,3,1,'x');  gpu.fill(x+5,y+9,3,1,'x')
  165.  
  166. gpu.setBackground(0xFFFFFF)
  167. gpu.setForeground(0xFFFFFF)
  168. gpu.fill(x+1,y+5,3,1,'x')
  169. gpu.fill(x,y+6,2,1,'x')
  170.  
  171. gpu.setBackground(0x996D00)
  172. gpu.setForeground(0x996D00)
  173. gpu.fill(x+3,y+4,2,1,'x')
  174. gpu.fill(x+3,y+9,2,1,'x')
  175. end
  176.  
  177. function drawItem_Cake(x,y)
  178. gpu.setForeground(0xFF9240)
  179. gpu.setBackground(0xFF9240)
  180. gpu.fill(x+3,y,5,1,'x')
  181. gpu.fill(x-2,y+1,12,1,'x')
  182. gpu.fill(x-4,y+2,16,1,'x')
  183. gpu.fill(x-5,y+3,18,2,'x')
  184. gpu.fill(x-4,y+5,16,1,'x')
  185. gpu.fill(x-3,y+6,15,1,'x')
  186. gpu.fill(x-2,y+7,13,1,'x')
  187.  
  188. gpu.setForeground(0x994900)
  189. gpu.setBackground(0x994900)
  190. gpu.fill(x,y,3,1,'x')
  191. gpu.fill(x+6,y+1,2,1,'x')
  192. gpu.fill(x-4,y+2,1,1,'x')
  193. gpu.fill(x+1,y+3,2,2,'x'); gpu.fill(x+6,y+3,3,1,'x')
  194. gpu.fill(x-5,y+5,1,1,'x'); gpu.fill(x+11,y+5,2,1,'x')
  195. gpu.fill(x-4,y+6,1,1,'x'); gpu.fill(x+11,y+6,1,1,'x'); gpu.fill(x+5,y+6,3,1,'x')
  196. gpu.fill(x+10,y+7,1,1,'x')
  197. gpu.fill(x,y+8,9,1,'x')
  198. end
  199.  
  200. function clear_log()
  201.   gpu.setBackground(background_color)
  202.   gpu.setForeground(background_color)
  203.   gpu.fill(10,19,25,3,' ')
  204. end
  205.  
  206. function charg_img(id, x, y)
  207.   if id==1 then
  208.     x=x-2
  209.     drawItem_Heart(x,y)
  210.   elseif id==2 then
  211.     x=x-3
  212.     y=y-1
  213.     drawItem_Diamond(x,y)
  214.   elseif id==3 then
  215.     x=x-3
  216.     y=y-1
  217.     drawItem_Apple(x,y)
  218.   elseif id==4 then
  219.     x=x-3
  220.     drawItem_Cake(x,y)
  221.   end
  222. end
  223.  
  224. function play()
  225. gpu.setBackground(background_color)
  226. gpu.setForeground(background_color)
  227. gpu.fill(68,28,80,20,' ')
  228. local mass={1,2,3}
  229. local gift_toggle={0,0,0}
  230.  
  231. if try_count>0 then
  232.      try_count=try_count-1
  233.      imgX=0
  234.      imgY=30
  235.  
  236.    for a=1,3 do
  237.     if a==1 then imgX=75
  238.     elseif a==2 then imgX=105
  239.     else imgX=132
  240.     end
  241.  
  242.      for b=1,3 do
  243.         mass[a]=math.floor( math.random(1,50) )
  244.          gpu.setBackground(background_color)
  245.          gpu.setForeground(background_color)
  246.          local fillX = imgX - 9
  247.          local fillY = imgY - 3
  248.          gpu.fill(fillX,fillY,22,15,' ')
  249.  
  250.          if mass[a]%2==0 then charg_img(1,imgX,imgY); gift_toggle[a]=1
  251.          elseif mass[a]%5==0 then charg_img(3,imgX,imgY); gift_toggle[a]=3
  252.          elseif mass[a]%3==0 then charg_img(2,imgX,imgY); gift_toggle[a]=2
  253.          else
  254.           charg_img(4,imgX,imgY)
  255.           gift_toggle[a]=4
  256.          end
  257.  
  258.          os.sleep(0.5)
  259.      end
  260.      set_str_trycount()
  261.     end
  262.  
  263.      if gift_toggle[1]==gift_toggle[2] and gift_toggle[1]==gift_toggle[3] then
  264.        local var_rnd=0
  265.        if gift_toggle[1]==2 then
  266.           var_rnd=tonumber(math.floor(math.random(1,2)))
  267.           if var_rnd==2 then me_gift.exportItem({id=gift_list[3][2], damage=2},"EAST",1)
  268.           else  me_gift.exportItem({id=gift_list[3][var_rnd]},"EAST",1)
  269.           end
  270.  
  271.        elseif gift_toggle[1]==3 then
  272.           var_rnd=tonumber(math.floor(math.random(1,5)))
  273.           if var_rnd==5 then me_gift.exportItem({id=gift_list[2][5], damage=1},"EAST",1)
  274.           else me_gift.exportItem({id=gift_list[2][var_rnd]},"EAST",1)
  275.           end
  276.  
  277.        elseif gift_toggle[1]==4 then
  278.           var_rnd=nonumber(math.floor(math.random(1,5)))
  279.           if var_rnd==5 then me_gift.exportItem({id=gift_list[1][5], damage=0},"EAST",1)
  280.           else me_gift.exportItem({id=gift_list[1][var_rnd]},"EAST",1)
  281.           end
  282.  
  283.        elseif gift_toggle[1]==1 then
  284.           me_gift.exportItem({id="dwcity:Materia"},"EAST",2)
  285.        end
  286.      end
  287.      gift_toggle[1]=0
  288.      gift_toggle[2]=0
  289.      gift_toggle[3]=0
  290.  
  291. else
  292.   gpu.setForeground(0xFF0000)
  293.   gpu.set(85,28,"ПОСТАЛОСЬ 0 ПОПЫТОК")
  294. end
  295.  
  296. end
  297.  
  298.  tButtons = {
  299.   {
  300.     visible = true,
  301.     X = W-5,
  302.     Y = 2,
  303.     W = 4,
  304.     H = 1,
  305.     color = 0xff0000,
  306.     textColor = 0xffffff,
  307.     text = 'X',
  308.     action = function()
  309.       gpu.setBackground(b_color)
  310.       gpu.setForeground(f_color)
  311.       gpu.fill(1, 1, W, H, ' ')
  312.       os.exit()
  313.   end
  314.   },
  315.   {
  316.     visible = true,
  317.     X = 12.5,
  318.     Y = 35,
  319.     W = 15,
  320.     H = 3,
  321.     color = 0x3324FF,
  322.     textColor = 0xFFFFFF,
  323.     text = 'PLAY',
  324.     action = function()
  325.       computer.beep()
  326.       event.cancel(1)
  327.       timeout=30
  328.       set_str_timeout()
  329.       play()
  330.       event.timer(1, function() check_timeout() end, 31)
  331.     end
  332.   },
  333.   {
  334.     visible=true,
  335.     X=12.5,
  336.     Y=40,
  337.     W=15,
  338.     H=3,
  339.     color= 0x3324FF,
  340.     textColor=0xFFFFFF,
  341.     text = 'Login',
  342.     action = function()
  343.     computer.beep()
  344.  
  345.      clear_log()
  346.  
  347.      gpu.setForeground(0xFFFFFF)
  348.      gpu.set(12.5,20,log_nickname)
  349.  
  350.      toggleVisible(3)
  351.      toggleVisible(2)
  352.      toggleVisible(4)
  353.      toggleVisible(5)
  354.  
  355.      status = computer.addUser(log_nickname)
  356.      set_str_trycount()
  357.  
  358.       event.timer(1,function() check_timeout() end, 31)
  359.     end
  360.   },
  361.   {
  362.     visible=true,
  363.     X=12.5,
  364.     Y=40,
  365.     W=15,
  366.     H=3,
  367.     color=0x3324FF,
  368.     textColor=0xFFFFFF,
  369.     text='Unlogin',
  370.     action = function()
  371.       computer.beep()
  372.       logOut()
  373.     end
  374.   },
  375.   {
  376.     visible=true,
  377.     X=30,
  378.     Y=23,
  379.     W=7,
  380.     H=1,
  381.     color=0x3324FF,
  382.     textColor=0xFFFFFF,
  383.     text='Reload',
  384.     action=function()
  385.       event.cancel(1)
  386.       timeout=30
  387.       set_str_timeout()
  388.       set_str_trycount()
  389.       event.timer(1, function() check_timeout() end, 31)
  390.     end
  391.   }
  392. }
  393.  
  394. function logOut()
  395.   event.cancel(1)
  396.   timeout=30
  397.   clear_log()
  398.   status=computer.removeUser(log_nickname)
  399.   log_nickname=" "  
  400.   trycount=0
  401.  
  402.   toggleVisible(4)
  403.   toggleVisible(3)
  404.   toggleVisible(2)
  405.   toggleVisible(5)
  406. end
  407.  
  408. function check_giftPosition()
  409.  
  410. end
  411.  
  412. function set_str_timeout()
  413. gpu.fill(30,45,5,1,' ')
  414. gpu.setForeground(0xFFFFFF)
  415. gpu.set(30,45,tostring(timeout))
  416. end
  417.  
  418. function set_str_trycount()
  419.    for i=1,25 do
  420.         local inv_item=me_if.getItemsInNetwork()[i]
  421.         if inv_item==nil then
  422.            break
  423.         end
  424.         if inv_item.name=="minecraft:iron_block" then
  425.             try_count = try_count + math.floor(tonumber(inv_item.size)/5)
  426.             local slot=me_if.getAvailableItems()[i]
  427.             me_if.exportItem(slot.fingerprint,'SOUTH',inv_item.size)
  428.         end
  429.     end
  430.  
  431.   gpu.setBackground(background_color)
  432.   gpu.fill(23,23,3,1,' ')
  433.   gpu.setForeground(0xFFFFFF)
  434.   gpu.set(23,23,tostring(try_count))
  435. end
  436.  
  437.  function drawButton(n) -- функция рисования кнопки
  438.   gpu.setBackground(tButtons[n].color) -- задаем цвет кнопки
  439.   gpu.setForeground(tButtons[n].textColor) -- задаем цвет текста
  440.   gpu.fill(tButtons[n].X, tButtons[n].Y, tButtons[n].W, tButtons[n].H, ' ') -- заливаем область
  441.   gpu.set(tButtons[n].X+(tButtons[n].W/2)-(#tButtons[n].text/2), tButtons[n].Y+(tButtons[n].H/2), tButtons[n].text) -- пишем текст по центру
  442. end
  443.  
  444.  function toggleVisible(n) -- переключение видимости кнопки
  445.   if tButtons[n].visible then -- если кнопка видима
  446.     tButtons[n].visible = false -- отключаем
  447.     gpu.setBackground(background_color) -- берем цвет фона, полученный при старте программы
  448.     gpu.fill(tButtons[n].X, tButtons[n].Y, tButtons[n].W, tButtons[n].H, ' ') -- стираем кнопку
  449.   else -- если кнопка не активна
  450.     tButtons[n].visible = true -- активируем
  451.     drawButton(n) -- запускаем отрисовку
  452.   end
  453. end
  454.  
  455. local function blink(n) -- мигание кнопки
  456.   tButtons[n].color, tButtons[n].textColor = tButtons[n].textColor, tButtons[n].color -- меняем местами цвета фона и текста
  457.   drawButton(n) -- отрисовываем кнопку
  458.   os.sleep(0.09) -- делаем задержку
  459.   tButtons[n].color, tButtons[n].textColor = tButtons[n].textColor, tButtons[n].color -- меняем цвета обратно
  460.   drawButton(n) -- перерисовываем кнопку
  461. end
  462. gpu.setBackground(background_color)
  463. gpu.setForeground(background_color)
  464. gpu.fill(1, 1, W, H, ' ') -- очищаем экран
  465.  
  466. for i = 1, #tButtons do
  467.   toggleVisible(i) -- активируем каждую кнопку
  468. end
  469. toggleVisible(3)
  470.  
  471. gpu.setBackground(background_color)
  472. gpu.setForeground(0xFFFFFF)
  473. gpu.fill(1,1,W,1,'=') --горизонтальные черты
  474. gpu.fill(1,H,W,1,'=')
  475. gpu.set(W-30,H,"|-edited by SanyaRamzik-|") --подпись
  476. gpu.set(13,1,'|Warp LEGEND|')
  477.  
  478. --Инфа боковая панель--
  479. gpu.setForeground(0x66B6FF)
  480. gpu.set(10,5,'Ресы не возвращаются')
  481. gpu.set(4,8,'1 попытка - 5 железных блоков')
  482. gpu.set(5,45,'Таймаут, выход через: ')
  483. set_str_timeout()
  484.  
  485. gpu.set(7,23,'Кол-во попыток: ')
  486.  
  487. for i=1,H  do
  488. gpu.set(40,i,"|")  --вертикальная черта
  489. end
  490. --Призы--
  491. gpu.setForeground(0xFFB600)
  492. gpu.set(50,10,'Солнечная панель 4ур')
  493. gpu.set(50,12,'Гравитационный жилет')
  494. gpu.setForeground(0xCC0040)
  495. gpu.set(85,10,'Часть квант сета')
  496. gpu.set(85,12,'Ядро Виверны')
  497. gpu.set(85,14,'Адская звезда')
  498. gpu.set(85,16,'Солнечная панель 3ур')
  499. gpu.setForeground(0x3300FF)
  500. gpu.set(120,10,'Сжатый камень')
  501. gpu.set(120,12,'Иридий')
  502. gpu.set(120,14,'Пробужденный драк. слиток')
  503. gpu.set(120,16,'Улучш. нано жилет')
  504. gpu.set(120,18,'Солнечная панель 2ур')
  505.  
  506. while true do
  507.   local tEvent = {pull_e('touch')} -- ждем клика
  508.   for i = 1, #tButtons do -- перебираем все кнопки
  509.     if tButtons[i].visible then -- если кнопка активна
  510.       if tEvent[3] >= tButtons[i].X and tEvent[3] <= tButtons[i].X+tButtons[i].W and tEvent[4] >= tButtons[i].Y and tEvent[4] <= tButtons[i].Y+tButtons[i].H then -- если клик произведен в пределах кнопки
  511.          local usr={computer.users()}
  512.          log_nickname=tostring(tEvent[6])
  513.         if log_nickname==tostring(usr[1]) and tButtons[3].visible==false then
  514.            blink(i) -- мигнуть кнопкой
  515.            tButtons[i].action() -- выполнить назначенный код
  516.            break
  517.         elseif tButtons[3].visible==true then
  518.            blink(i)
  519.            tButtons[i].action()
  520.            break
  521.         end
  522.       end
  523.     end
  524.   end
  525. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement