Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --OpenClicker v0.1
- --Автор: qwertyMAN
- local term=require('term')
- local event=require('event')
- local gpu=require('component').gpu
- local disp = {gpu.getResolution()}
- local quit_cash = false
- local quit = false
- local width = 80
- local height = 25
- local timeout = 1
- local cash = 0
- local speed_cash = 0
- local click_cash = 1
- local target_cash = 10^12
- local worker = {0,0,0,0,0,0,0,0}
- local work_cash = {20,200,2*10^3,2*10^4,2*10^5,2*10^6,2*10^7,2*10^8}
- local color = {
- back=0x000000,
- foreg=0xffffff,
- cookie=0xffcc33,
- chocolate=0x663300,
- scoreboard=0xaaaaaa,
- work_cash=0x6699ff,
- work=0xffcc33,
- exit=0xff0000,
- reboot=0xffcc33,
- quit_cash_1=0x00ff00,
- quit_cash_2=0xff0000
- }
- local function draw_quit_cash()
- local msg,col
- if quit_cash then
- msg=" on "
- col=color.quit_cash_1
- else
- msg=" off "
- col=color.quit_cash_2
- end
- gpu.setBackground(col)
- gpu.setForeground(0x000000)
- gpu.set(14, 24, msg)
- gpu.setBackground(color.back)
- gpu.setForeground(color.foreg)
- end
- local function buy(i)
- local money = tonumber(math.ceil(work_cash[i]*(1.2^worker[i])))
- if cash >= money then
- gpu.setForeground(0x000000)
- worker[i] = worker[i]+1
- cash = cash - money
- speed_cash = 0
- for n=1, #worker do
- speed_cash = speed_cash + math.modf(worker[n]*(work_cash[n]/20)) --пересчитаем прибль
- end
- local size_2 = 5+i*2
- gpu.setBackground(color.work)
- gpu.fill(2, size_2-1, 19, 1, " ")
- gpu.set(3, size_2-1, tostring(worker[i]))
- gpu.setBackground(color.work_cash)
- gpu.fill(2, size_2, 19, 1, " ")
- gpu.set(3, size_2, tostring(math.modf(work_cash[i]*(1.2^worker[i]))).."$")
- gpu.setBackground(color.scoreboard)
- gpu.fill(2, 3, 78, 1, " ")
- gpu.set(3, 3, tostring(speed_cash).."$/sec")
- gpu.setBackground(color.back)
- gpu.setForeground(color.foreg)
- end
- end
- local function draw_cash()
- gpu.setBackground(color.scoreboard)
- gpu.setForeground(0x000000)
- gpu.fill(2, 2, 78, 1, " ")
- gpu.set(3, 2, tostring(cash).."$")
- gpu.setBackground(color.back)
- gpu.setForeground(color.foreg)
- end
- local function draw()
- gpu.setBackground(color.back)
- gpu.setForeground(0x000000)
- term.clear()
- --рисуем печеньку
- gpu.setBackground(color.cookie)
- gpu.fill(61, 6, 19, 10, " ")
- gpu.setBackground(color.chocolate)
- gpu.set(63, 7, " ")
- gpu.set(63, 8, " ")
- gpu.set(68, 8, " ")
- gpu.set(68, 9, " ")
- gpu.set(74, 11, " ")
- gpu.set(73, 12, " ")
- gpu.set(65, 10, " ")
- gpu.set(65, 11, " ")
- gpu.set(63, 13, " ")
- gpu.set(65, 14, " ")
- gpu.set(76, 7, " ")
- gpu.set(76, 8, " ")
- gpu.set(76, 13, " ")
- gpu.set(75, 14, " ")
- --рисуем кнопку выхода
- gpu.setBackground(color.exit)
- gpu.set(2, 24, "exit")
- --рисуем кнопку перезапуска
- gpu.setBackground(color.reboot)
- gpu.set(7, 24, "reboot")
- --рисуем меню покупки
- for n=1, #worker do
- local size = 5+n*2
- gpu.setBackground(color.work)
- gpu.fill(2, size-1, 19, 1, " ")
- gpu.set(3, size-1, tostring(worker[n]))
- gpu.setBackground(color.work_cash)
- gpu.fill(2, size, 19, 1, " ")
- gpu.set(3, size, tostring(math.modf(work_cash[n]*(1.2^worker[n]))).."$")
- end
- --рисуем прибыль
- gpu.setBackground(color.scoreboard)
- gpu.fill(2, 3, 78, 1, " ")
- gpu.set(3, 3, tostring(speed_cash).."$/sec")
- --рисуем кнопку переключателя
- draw_quit_cash()
- --рисуем название игры
- gpu.set(35, 5, "Open clicker")
- --рисуем текущий счёт
- draw_cash()
- end
- local function reboot()
- worker = {0,0,0,0,0,0,0,0}
- speed_cash = 0
- cash = 0
- draw()
- end
- local function touch(_,_, x, y)
- if x<21 then
- if x>1 and x<6 and y==24 then
- quit = true
- elseif x>6 and x<13 and y==24 then
- reboot()
- elseif x>13 and x<21 and y==24 then
- quit_cash = not quit_cash
- draw_quit_cash()
- else
- for i=1, #worker do
- local size = 5+i*2
- if size-1 == y or size==y then
- buy(i)
- end
- end
- end
- elseif x>60 and x<80 and y>5 and y<16 then
- cash = cash + click_cash
- draw_cash()
- end
- end
- local function the_game()
- event.shouldInterrupt = function() return false end --отрубим Alt+Ctrl+C
- event.listen('touch', touch)
- gpu.setResolution(width, height)
- draw()
- while true do
- cash = cash + speed_cash*timeout
- draw_cash()
- os.sleep(timeout)
- if quit or (quit_cash and cash>target_cash) then break end
- end
- term.clear()
- print("Good bye!")
- os.sleep(3)
- gpu.setResolution(disp[1], disp[2])
- term.clear()
- end
- the_game()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement