Advertisement
qwertyMAN_rus

OpenClicker

Mar 23rd, 2016 (edited)
902
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.51 KB | None | 0 0
  1. --OpenClicker v0.1
  2. --Автор: qwertyMAN
  3. local term=require('term')
  4. local event=require('event')
  5. local gpu=require('component').gpu
  6. local disp = {gpu.getResolution()}
  7. local quit_cash = false
  8. local quit = false
  9. local width = 80
  10. local height = 25
  11. local timeout = 1
  12. local cash = 0
  13. local speed_cash = 0
  14. local click_cash = 1
  15. local target_cash = 10^12
  16. local worker = {0,0,0,0,0,0,0,0}
  17. local work_cash = {20,200,2*10^3,2*10^4,2*10^5,2*10^6,2*10^7,2*10^8}
  18. local color = {
  19.     back=0x000000,
  20.     foreg=0xffffff,
  21.     cookie=0xffcc33,
  22.     chocolate=0x663300,
  23.     scoreboard=0xaaaaaa,
  24.     work_cash=0x6699ff,
  25.     work=0xffcc33,
  26.     exit=0xff0000,
  27.     reboot=0xffcc33,
  28.     quit_cash_1=0x00ff00,
  29.     quit_cash_2=0xff0000
  30. }
  31.  
  32. local function draw_quit_cash()
  33.     local msg,col
  34.     if quit_cash then
  35.         msg="  on   "
  36.         col=color.quit_cash_1
  37.     else
  38.         msg="  off  "
  39.         col=color.quit_cash_2
  40.     end
  41.     gpu.setBackground(col)
  42.     gpu.setForeground(0x000000)
  43.     gpu.set(14, 24, msg)
  44.     gpu.setBackground(color.back)
  45.     gpu.setForeground(color.foreg)
  46. end
  47.  
  48. local function buy(i)
  49.     local money = tonumber(math.ceil(work_cash[i]*(1.2^worker[i])))
  50.     if cash >= money then
  51.         gpu.setForeground(0x000000)
  52.         worker[i] = worker[i]+1
  53.         cash = cash - money
  54.         speed_cash = 0
  55.         for n=1, #worker do
  56.             speed_cash = speed_cash + math.modf(worker[n]*(work_cash[n]/20)) --пересчитаем прибль
  57.         end
  58.         local size_2 = 5+i*2
  59.         gpu.setBackground(color.work)
  60.         gpu.fill(2, size_2-1, 19, 1, " ")
  61.         gpu.set(3, size_2-1, tostring(worker[i]))
  62.         gpu.setBackground(color.work_cash)
  63.         gpu.fill(2, size_2, 19, 1, " ")
  64.         gpu.set(3, size_2, tostring(math.modf(work_cash[i]*(1.2^worker[i]))).."$")
  65.         gpu.setBackground(color.scoreboard)
  66.         gpu.fill(2, 3, 78, 1, " ")
  67.         gpu.set(3, 3, tostring(speed_cash).."$/sec")
  68.         gpu.setBackground(color.back)
  69.         gpu.setForeground(color.foreg)
  70.     end
  71. end
  72.  
  73. local function draw_cash()
  74.     gpu.setBackground(color.scoreboard)
  75.     gpu.setForeground(0x000000)
  76.     gpu.fill(2, 2, 78, 1, " ")
  77.     gpu.set(3, 2, tostring(cash).."$")
  78.     gpu.setBackground(color.back)
  79.     gpu.setForeground(color.foreg)
  80. end
  81.  
  82. local function draw()
  83.     gpu.setBackground(color.back)
  84.     gpu.setForeground(0x000000)
  85.     term.clear()
  86.     --рисуем печеньку
  87.     gpu.setBackground(color.cookie)
  88.     gpu.fill(61, 6, 19, 10, " ")
  89.     gpu.setBackground(color.chocolate)
  90.     gpu.set(63, 7, "    ")
  91.     gpu.set(63, 8, "   ")
  92.     gpu.set(68, 8, "  ")
  93.     gpu.set(68, 9, "  ")
  94.     gpu.set(74, 11, " ")
  95.     gpu.set(73, 12, "  ")
  96.     gpu.set(65, 10, "  ")
  97.     gpu.set(65, 11, "   ")
  98.     gpu.set(63, 13, "    ")
  99.     gpu.set(65, 14, "   ")
  100.     gpu.set(76, 7, " ")
  101.     gpu.set(76, 8, "  ")
  102.     gpu.set(76, 13, "   ")
  103.     gpu.set(75, 14, "    ")
  104.     --рисуем кнопку выхода
  105.     gpu.setBackground(color.exit)
  106.     gpu.set(2, 24, "exit")
  107.     --рисуем кнопку перезапуска
  108.     gpu.setBackground(color.reboot)
  109.     gpu.set(7, 24, "reboot")
  110.     --рисуем меню покупки
  111.     for n=1, #worker do
  112.         local size = 5+n*2
  113.         gpu.setBackground(color.work)
  114.         gpu.fill(2, size-1, 19, 1, " ")
  115.         gpu.set(3, size-1, tostring(worker[n]))
  116.         gpu.setBackground(color.work_cash)
  117.         gpu.fill(2, size, 19, 1, " ")
  118.         gpu.set(3, size, tostring(math.modf(work_cash[n]*(1.2^worker[n]))).."$")
  119.     end
  120.     --рисуем прибыль
  121.     gpu.setBackground(color.scoreboard)
  122.     gpu.fill(2, 3, 78, 1, " ")
  123.     gpu.set(3, 3, tostring(speed_cash).."$/sec")
  124.     --рисуем кнопку переключателя
  125.     draw_quit_cash()
  126.     --рисуем название игры
  127.     gpu.set(35, 5, "Open clicker")
  128.     --рисуем текущий счёт
  129.     draw_cash()
  130. end
  131.  
  132.  
  133. local function reboot()
  134.     worker = {0,0,0,0,0,0,0,0}
  135.     speed_cash = 0
  136.     cash = 0
  137.     draw()
  138. end
  139.  
  140. local function touch(_,_, x, y)
  141.     if x<21 then
  142.         if x>1 and x<6 and y==24 then
  143.             quit = true
  144.         elseif x>6 and x<13 and y==24 then
  145.             reboot()
  146.         elseif x>13 and x<21 and y==24 then
  147.             quit_cash = not quit_cash
  148.             draw_quit_cash()
  149.         else
  150.             for i=1, #worker do
  151.                 local size = 5+i*2
  152.                 if size-1 == y or size==y then
  153.                     buy(i)
  154.                 end
  155.             end
  156.         end
  157.     elseif x>60 and x<80 and y>5 and y<16 then
  158.         cash = cash + click_cash
  159.         draw_cash()
  160.     end
  161. end
  162.  
  163. local function the_game()
  164.     event.shouldInterrupt = function() return false end --отрубим Alt+Ctrl+C
  165.     event.listen('touch', touch)
  166.     gpu.setResolution(width, height)
  167.     draw()
  168.     while true do
  169.         cash = cash + speed_cash*timeout
  170.         draw_cash()
  171.         os.sleep(timeout)
  172.     if quit or (quit_cash and cash>target_cash) then break end
  173.     end
  174.     term.clear()
  175.     print("Good bye!")
  176.     os.sleep(3)
  177.     gpu.setResolution(disp[1], disp[2])
  178.     term.clear()
  179. end
  180. the_game()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement