mirror of
https://github.com/IgorTimofeev/MineOS.git
synced 2025-12-20 19:19:21 +01:00
Говно всякое
This commit is contained in:
parent
185f16d43d
commit
096158b282
@ -349,6 +349,24 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
----------------------------------------------------- Приложения без ресурсов --------------------------------------------------------------------------
|
----------------------------------------------------- Приложения без ресурсов --------------------------------------------------------------------------
|
||||||
|
{
|
||||||
|
["name"]="MineOS/Applications/FlappyBlock",
|
||||||
|
["url"]="IgorTimofeev/OpenComputers/master/Applications/FlappyBlock/FlappyBlock.lua",
|
||||||
|
["about"]="IgorTimofeev/OpenComputers/master/Applications/FlappyBlock/About.txt",
|
||||||
|
["type"]="Application",
|
||||||
|
["icon"]="IgorTimofeev/OpenComputers/master/Applications/FlappyBlock/Icon.pic",
|
||||||
|
["createShortcut"] = "desktop",
|
||||||
|
["version"]=1.0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
["name"]="MineOS/Applications/MineSweeper",
|
||||||
|
["url"]="IgorTimofeev/OpenComputers/master/Applications/MineSweeper/MineSweeper.lua",
|
||||||
|
["about"]="IgorTimofeev/OpenComputers/master/Applications/MineSweeper/About.txt",
|
||||||
|
["type"]="Application",
|
||||||
|
["icon"]="IgorTimofeev/OpenComputers/master/Applications/MineSweeper/Icon.pic",
|
||||||
|
["createShortcut"] = "desktop",
|
||||||
|
["version"]=1.0,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
["name"]="MineOS/Applications/DanceFloor",
|
["name"]="MineOS/Applications/DanceFloor",
|
||||||
["url"]="IgorTimofeev/OpenComputers/master/Applications/DanceFloor/DanceFloor.lua",
|
["url"]="IgorTimofeev/OpenComputers/master/Applications/DanceFloor/DanceFloor.lua",
|
||||||
|
|||||||
1
Applications/FlappyBlock/About.txt
Normal file
1
Applications/FlappyBlock/About.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
Программа-симулятор популярной игры Flappy Bird, написанная товарищем Newbie с форума ComputerCraft.ru.
|
||||||
303
Applications/FlappyBlock/FlappyBlock.lua
Normal file
303
Applications/FlappyBlock/FlappyBlock.lua
Normal file
@ -0,0 +1,303 @@
|
|||||||
|
--Floppy Block v.0.2
|
||||||
|
--Автор: newbie
|
||||||
|
|
||||||
|
local term = require("term")
|
||||||
|
local event = require("event")
|
||||||
|
local computer = require("computer")
|
||||||
|
local component = require("component")
|
||||||
|
local fs = require("filesystem")
|
||||||
|
local gpu = component.gpu
|
||||||
|
local serialization = require("serialization")
|
||||||
|
local xSize, ySize = gpu.getResolution()
|
||||||
|
local width = 30
|
||||||
|
local height = 22
|
||||||
|
local startXPosPlayer = 8
|
||||||
|
local tempPosPlayer = 10
|
||||||
|
local nicknames
|
||||||
|
local records
|
||||||
|
local name
|
||||||
|
local count = 0
|
||||||
|
local tCount = 0
|
||||||
|
local colors = {
|
||||||
|
player = 0xffea00,
|
||||||
|
bg = 0x71c5cf,
|
||||||
|
floor = 0xddd894,
|
||||||
|
walls = 0x74bf2e,
|
||||||
|
text = 0xefb607,
|
||||||
|
button = 0x000000
|
||||||
|
}
|
||||||
|
local quit = false
|
||||||
|
local game = true
|
||||||
|
local fin = false
|
||||||
|
local function start()
|
||||||
|
term.clear()
|
||||||
|
gpu.setForeground(colors.player)
|
||||||
|
gpu.set(6, 10, "Кликни чтоб начать")
|
||||||
|
gpu.set(5, 11, "Жми кнопки чтоб жить")
|
||||||
|
gpu.setForeground(colors.text)
|
||||||
|
local e = {event.pull("touch")}
|
||||||
|
name = e[6]
|
||||||
|
computer.addUser(name)--Эту строку лучше коментить если игру ставите на личный комп
|
||||||
|
end
|
||||||
|
local function paintWall()
|
||||||
|
local function up() --cлушалка
|
||||||
|
if tempPosPlayer <= 2 then --проверка на удар сверху
|
||||||
|
fin = true
|
||||||
|
game = false
|
||||||
|
event.ignore("key_down", up)
|
||||||
|
end
|
||||||
|
gpu.set(startXPosPlayer, tempPosPlayer, " ")
|
||||||
|
tempPosPlayer = tempPosPlayer - 1
|
||||||
|
gpu.setBackground(colors.player)
|
||||||
|
gpu.set(startXPosPlayer, tempPosPlayer, " ")
|
||||||
|
gpu.setBackground(colors.bg)
|
||||||
|
os.sleep(0.1)
|
||||||
|
end
|
||||||
|
tempPosPlayer = 10
|
||||||
|
while game do
|
||||||
|
gpu.set(2, 3, tostring(tCount))
|
||||||
|
--Делает нам на случайной высоте отвертие в 5 блоков
|
||||||
|
local randomY = math.modf(math.random(2,15))
|
||||||
|
for i = 1, 29 do
|
||||||
|
local a = 29 - i
|
||||||
|
gpu.setBackground(colors.walls)
|
||||||
|
for i=2, randomY do
|
||||||
|
gpu.set(a, i, " ")
|
||||||
|
end
|
||||||
|
for i = randomY + 5, 21 do
|
||||||
|
gpu.set(a, i, " ")
|
||||||
|
end
|
||||||
|
local function checkWall()
|
||||||
|
rand = randomY + 5
|
||||||
|
if startXPosPlayer + 1 == a then --лобовое столкновение сверху
|
||||||
|
if randomY>= tempPosPlayer -1 then
|
||||||
|
tempPosPlayer = 21
|
||||||
|
end
|
||||||
|
elseif startXPosPlayer == a then --удар в верхний угол задним пикселем
|
||||||
|
if randomY>= tempPosPlayer - 1 then
|
||||||
|
tempPosPlayer = 21
|
||||||
|
end
|
||||||
|
elseif startXPosPlayer == a+1 then --совпадение второго пикселя с задним вверху
|
||||||
|
if randomY>= tempPosPlayer-1 then
|
||||||
|
tempPosPlayer = 21
|
||||||
|
end
|
||||||
|
elseif startXPosPlayer == a+2 then --совпадение второго пикселя с задним вверху
|
||||||
|
if randomY>= tempPosPlayer-1 then
|
||||||
|
tempPosPlayer = 21
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if startXPosPlayer + 1 == a then --лобовое столкновение снизу
|
||||||
|
if tempPosPlayer+1 >= rand then
|
||||||
|
tempPosPlayer = 21
|
||||||
|
end
|
||||||
|
elseif startXPosPlayer == a then --удар в нижний угол задним пикселем
|
||||||
|
if tempPosPlayer+1 >= rand then
|
||||||
|
tempPosPlayer = 21
|
||||||
|
end
|
||||||
|
elseif startXPosPlayer == a+1 then --совпадение второго пикселя с задним сверху
|
||||||
|
if tempPosPlayer +1 >= rand then
|
||||||
|
tempPosPlayer = 21
|
||||||
|
end
|
||||||
|
elseif startXPosPlayer == a+2 then --совпадение второго пикселя с задним сверху
|
||||||
|
if tempPosPlayer +1 >= rand then
|
||||||
|
tempPosPlayer = 21
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
checkWall()
|
||||||
|
if tempPosPlayer>=21 then --проверка на удар снизу
|
||||||
|
fin = true
|
||||||
|
game = false
|
||||||
|
event.ignore("key_down", up)
|
||||||
|
break
|
||||||
|
end
|
||||||
|
--отрисовка, перерисовка игрока
|
||||||
|
gpu.setBackground(colors.bg)
|
||||||
|
gpu.set(startXPosPlayer, tempPosPlayer, " ")
|
||||||
|
tempPosPlayer = tempPosPlayer + 1
|
||||||
|
gpu.setBackground(colors.player)
|
||||||
|
gpu.set(startXPosPlayer, tempPosPlayer, " ")
|
||||||
|
gpu.setBackground(colors.bg)
|
||||||
|
os.sleep(0.2)
|
||||||
|
event.listen("key_down", up)
|
||||||
|
if startXPosPlayer == a then
|
||||||
|
tCount = tCount + 1
|
||||||
|
gpu.set(2, 3, tostring(tCount))
|
||||||
|
end
|
||||||
|
gpu.setBackground(colors.bg)
|
||||||
|
for i=2, randomY do
|
||||||
|
gpu.set(a, i, " ")
|
||||||
|
end
|
||||||
|
for i = randomY + 5, 21 do
|
||||||
|
gpu.set(a, i, " ")
|
||||||
|
end
|
||||||
|
if fin then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local pathToRecords = "records.txt" --путь к файлу с рекордами
|
||||||
|
local function saveRecord() --Сохраняем рекорды
|
||||||
|
local file = io.open(pathToRecords, "w")
|
||||||
|
local array = {["nicknames"] = nicknames, ["records"] = records}
|
||||||
|
file:write(serialization.serialize(array))
|
||||||
|
file:close()
|
||||||
|
end
|
||||||
|
local function loadRecord() --Загружаем рекорды
|
||||||
|
if fs.exists(pathToRecords) then
|
||||||
|
local array = {}
|
||||||
|
local file = io.open(pathToRecords, "r")
|
||||||
|
local str = file:read("*a")
|
||||||
|
array = serialization.unserialize(str)
|
||||||
|
file:close()
|
||||||
|
nicknames = array.nicknames
|
||||||
|
records = array.records
|
||||||
|
else --или создаем новые дефолтные пустые таблицы
|
||||||
|
fs.makeDirectory(fs.path(pathToRecords))
|
||||||
|
nicknames = {}
|
||||||
|
records = {}
|
||||||
|
saveRecord()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local function checkName(name) --Проверка на наличие имени в базе
|
||||||
|
for i =1, #nicknames do
|
||||||
|
if name == nicknames[i] then
|
||||||
|
count = records[i]
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
local function addPlayer() --Создаем учетку пользователю если его нет в базе
|
||||||
|
if checkName(name) then
|
||||||
|
table.insert(nicknames, name)
|
||||||
|
table.insert(records, count)
|
||||||
|
saveRecord()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local function gameOver() --Игра окончена
|
||||||
|
gpu.setBackground(colors.bg)
|
||||||
|
term.clear()
|
||||||
|
gpu.setForeground(colors.player)
|
||||||
|
gpu.set(10,11,"GAME OVER!")
|
||||||
|
gpu.set(8,14,"You count: "..tostring(tCount))
|
||||||
|
gpu.setForeground(colors.text)
|
||||||
|
count = 0
|
||||||
|
tCount = 0
|
||||||
|
game = true
|
||||||
|
fin = false
|
||||||
|
computer.removeUser(name) --опять же коментим эту строку если комп не публичный
|
||||||
|
end
|
||||||
|
local function saveCount() --сохраняем наши заработанные очки
|
||||||
|
for i = 1, #nicknames do
|
||||||
|
if name == nicknames[i] then
|
||||||
|
count = records[i]
|
||||||
|
if tCount > count then
|
||||||
|
records[i] = tCount
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
saveRecord()
|
||||||
|
end
|
||||||
|
local function sortTop() --Сортируем Топ игроков
|
||||||
|
for i=1, #records do
|
||||||
|
for j=1, #records-1 do
|
||||||
|
if records[j] < records[j+1] then
|
||||||
|
local r = records[j+1]
|
||||||
|
local n = nicknames[j+1]
|
||||||
|
records[j+1] = records[j]
|
||||||
|
nicknames[j+1] = nicknames[j]
|
||||||
|
records[j] = r
|
||||||
|
nicknames[j] = n
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
saveRecord()
|
||||||
|
end
|
||||||
|
function paintScene() --Рисуем сцену
|
||||||
|
term.clear()
|
||||||
|
gpu.setBackground(colors.floor)
|
||||||
|
gpu.set(0,1," ")
|
||||||
|
gpu.set(0,22," ")
|
||||||
|
gpu.setBackground(colors.bg)
|
||||||
|
end
|
||||||
|
local function printRecords() --Выводим рекорды на экран
|
||||||
|
term.clear()
|
||||||
|
local xPosName = 5
|
||||||
|
local xPosRecord = 20
|
||||||
|
local yPos = 1
|
||||||
|
loadRecord()
|
||||||
|
gpu.setForeground(colors.player)
|
||||||
|
gpu.set(11,1,"Top - 15")
|
||||||
|
if #nicknames <= 15 then
|
||||||
|
for i = 1, #nicknames do
|
||||||
|
yPos= yPos+1
|
||||||
|
gpu.set(xPosName, yPos, nicknames[i] )
|
||||||
|
gpu.set(xPosRecord, yPos, tostring(records[i]))
|
||||||
|
end
|
||||||
|
else
|
||||||
|
for i = 1, 15 do
|
||||||
|
yPos= yPos+1
|
||||||
|
gpu.set(xPosName, yPos, nicknames[i] )
|
||||||
|
gpu.set(xPosRecord, yPos, tostring(records[i]))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
gpu.setForeground(colors.text)
|
||||||
|
os.sleep(10)
|
||||||
|
floppyBlock()
|
||||||
|
end
|
||||||
|
function main()
|
||||||
|
start()
|
||||||
|
addPlayer()
|
||||||
|
paintScene()
|
||||||
|
paintWall()
|
||||||
|
saveCount()
|
||||||
|
gameOver()
|
||||||
|
os.sleep(3)
|
||||||
|
floppyBlock()
|
||||||
|
end
|
||||||
|
function floppyBlock()
|
||||||
|
term.clear()
|
||||||
|
event.shouldInterrupt = function() return false end --Alt+ Ctrl + C не пашет, так же на ваше усмотрение
|
||||||
|
gpu.setResolution(width, height)
|
||||||
|
gpu.setForeground(colors.player)
|
||||||
|
loadRecord()
|
||||||
|
gpu.set(9,5,"Flappy Block")
|
||||||
|
gpu.setBackground(colors.button)
|
||||||
|
gpu.set(12,15," Play ")
|
||||||
|
gpu.set(11,17," Top-15 ")
|
||||||
|
gpu.set(12,20," Quit ")
|
||||||
|
gpu.setBackground(colors.bg)
|
||||||
|
while true do
|
||||||
|
local e = {event.pull("touch")}
|
||||||
|
if e[4] == 15 then
|
||||||
|
if e[3]>12 then
|
||||||
|
if e[3]<18 then main() end
|
||||||
|
end
|
||||||
|
elseif e[4] == 17 then
|
||||||
|
if e[3]>11 then
|
||||||
|
if e[3]<19 then
|
||||||
|
sortTop()
|
||||||
|
printRecords()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
elseif e[4] == 20 then
|
||||||
|
if e[3]>12 then
|
||||||
|
if e[3]<18 then
|
||||||
|
if e[6] == "newbie" then --В эту строку заносим ник того кто может закрыть игру, если ненужно,
|
||||||
|
--коментим ее
|
||||||
|
gpu.setForeground(colors.text)
|
||||||
|
gpu.setResolution(xSize,ySize)
|
||||||
|
term.clear()
|
||||||
|
quit = true
|
||||||
|
break
|
||||||
|
end --и тут
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if quit then break end
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
floppyBlock()
|
||||||
BIN
Applications/FlappyBlock/Resources/Icon.pic
Normal file
BIN
Applications/FlappyBlock/Resources/Icon.pic
Normal file
Binary file not shown.
1
Applications/MineSweeper/About.txt
Normal file
1
Applications/MineSweeper/About.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
Известная игра "Сапер", написанная товарищем QwertyMan с форума ComputerCraft.ru.
|
||||||
216
Applications/MineSweeper/MineSweeper.lua
Normal file
216
Applications/MineSweeper/MineSweeper.lua
Normal file
@ -0,0 +1,216 @@
|
|||||||
|
-- Автор: qwertyMAN
|
||||||
|
-- Версия: 0.1 beta
|
||||||
|
|
||||||
|
local term = require("term")
|
||||||
|
local event = require("event")
|
||||||
|
local component = require("component")
|
||||||
|
local gpu = component.gpu
|
||||||
|
local max_mine = 40 -- число мин на поле
|
||||||
|
local display = {gpu.getResolution()}
|
||||||
|
local border = {0,0} -- отступ, который не используется
|
||||||
|
local marker = {} -- отмечает ПКМ мины
|
||||||
|
local size = {16,16} -- размер игрового поля
|
||||||
|
math.randomseed(os.time())
|
||||||
|
|
||||||
|
local colors={0x0000ff,0x00ff00,0xff0000,0xffff00,0x8800ff,0x88ff00,0x00ffff,0xff00ff}
|
||||||
|
|
||||||
|
local function conv_cord(sx,sy)
|
||||||
|
return sx*2-1+border[1], sy+border[2]
|
||||||
|
end
|
||||||
|
|
||||||
|
-- создаем поле
|
||||||
|
local area={}
|
||||||
|
for x=1, size[1] do
|
||||||
|
area[x]={}
|
||||||
|
for y=1, size[2] do
|
||||||
|
area[x][y]={mine=false, n=0}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- генерируем мины
|
||||||
|
for i=1, max_mine do
|
||||||
|
while true do
|
||||||
|
rand_x, rand_y = math.random(1, size[1]), math.random(1, size[2])
|
||||||
|
if not area[rand_x][rand_y].mine then
|
||||||
|
area[rand_x][rand_y].mine = true
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- генерирем числа на пустых клетках
|
||||||
|
for x=1, size[1] do
|
||||||
|
for y=1, size[2] do
|
||||||
|
if not area[x][y].mine then
|
||||||
|
for i=-1,1 do
|
||||||
|
for j=-1,1 do
|
||||||
|
if x+i>0 and y+j>0 and x+i<size[1]+1 and y+j<size[2]+1 and area[x+i][y+j].mine then
|
||||||
|
area[x][y].n = area[x][y].n+1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
gpu.setBackground(0x000000)
|
||||||
|
gpu.setForeground(0xffffff)
|
||||||
|
|
||||||
|
-- отображение пустого поля
|
||||||
|
term.clear()
|
||||||
|
gpu.setBackground(0xAAAAAA)
|
||||||
|
for i=1, size[1] do
|
||||||
|
for j=1, size[2] do
|
||||||
|
local rezerv = {conv_cord(i,j)}
|
||||||
|
gpu.set(rezerv[1], rezerv[2], " ")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
gpu.setBackground(0x000000)
|
||||||
|
|
||||||
|
local function click(x,y)
|
||||||
|
local x = math.modf((x+1)/2)
|
||||||
|
return x,y
|
||||||
|
end
|
||||||
|
|
||||||
|
local function open(x,y)
|
||||||
|
local not_sorting_tb = {}
|
||||||
|
local sorting_tb = {}
|
||||||
|
not_sorting_tb[1] = {x,y}
|
||||||
|
gpu.setBackground(0xffffff)
|
||||||
|
local rezerv = {conv_cord(x,y)}
|
||||||
|
gpu.set(rezerv[1], rezerv[2], " ")
|
||||||
|
while true do
|
||||||
|
-- выход из цикла
|
||||||
|
if #not_sorting_tb == 0 then
|
||||||
|
gpu.setBackground(0x000000)
|
||||||
|
gpu.setForeground(0xffffff)
|
||||||
|
return
|
||||||
|
else
|
||||||
|
local nx,ny = not_sorting_tb[1][1], not_sorting_tb[1][2]
|
||||||
|
-- смотрим какого вида ячейка
|
||||||
|
if area[nx][ny] then
|
||||||
|
if area[nx][ny].n>0 then -- если не пустая
|
||||||
|
gpu.setForeground(colors[area[nx][ny].n])
|
||||||
|
local rezerv = {conv_cord(nx,ny)}
|
||||||
|
gpu.set(rezerv[1], rezerv[2], " "..area[nx][ny].n)
|
||||||
|
else
|
||||||
|
-- если пустая
|
||||||
|
for i=-1,1 do
|
||||||
|
for j=-1,1 do
|
||||||
|
local mx,my = nx+i, ny+j
|
||||||
|
-- если ячейка существует
|
||||||
|
if mx>=1 and my>=1 and mx<=size[1] and my<=size[2] then
|
||||||
|
local swich = true
|
||||||
|
-- проверяем есть ли она в бд
|
||||||
|
for n=1, #sorting_tb do
|
||||||
|
if mx==sorting_tb[n][1] and my==sorting_tb[n][2] then
|
||||||
|
swich = false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
for n=1, #not_sorting_tb do
|
||||||
|
if mx==not_sorting_tb[n][1] and my==not_sorting_tb[n][2] then
|
||||||
|
swich = false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if swich then
|
||||||
|
local rezerv = {conv_cord(mx,my)}
|
||||||
|
gpu.set(rezerv[1], rezerv[2], " ")
|
||||||
|
not_sorting_tb[#not_sorting_tb+1]={mx,my}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
area[nx][ny]=false
|
||||||
|
end
|
||||||
|
sorting_tb[#sorting_tb+1] = not_sorting_tb[1]
|
||||||
|
table.remove(not_sorting_tb,1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- тело программы
|
||||||
|
while true do
|
||||||
|
local _,_,x,y,key,nick = event.pull("touch")
|
||||||
|
local x,y = click(x,y)
|
||||||
|
if key == 0 then
|
||||||
|
local swich = true
|
||||||
|
for i=1, #marker do
|
||||||
|
if x == marker[i][1] and y == marker[i][2] then
|
||||||
|
swich = false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if area[x][y] and area[x][y].mine and swich then
|
||||||
|
-- покажим мины
|
||||||
|
gpu.setBackground(0xff0000)
|
||||||
|
gpu.setForeground(0x000000)
|
||||||
|
for i=1, size[1] do
|
||||||
|
for j=1, size[2] do
|
||||||
|
if area[i][j] and area[i][j].mine then
|
||||||
|
local rezerv = {conv_cord(i,j)}
|
||||||
|
gpu.set(rezerv[1], rezerv[2], " m")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
gpu.setBackground(0x000000)
|
||||||
|
gpu.setForeground(0xffffff)
|
||||||
|
os.sleep(2)
|
||||||
|
term.clear()
|
||||||
|
print("game over")
|
||||||
|
os.sleep(2)
|
||||||
|
term.clear()
|
||||||
|
return
|
||||||
|
elseif swich then
|
||||||
|
open(x,y)
|
||||||
|
-- проверяем выигрыш
|
||||||
|
local timer = 0
|
||||||
|
for i=1, size[1] do
|
||||||
|
for j=1, size[2] do
|
||||||
|
if area[i][j] then
|
||||||
|
timer = timer+1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if timer==max_mine then
|
||||||
|
-- покажим мины
|
||||||
|
gpu.setBackground(0xff0000)
|
||||||
|
gpu.setForeground(0x000000)
|
||||||
|
for i=1, size[1] do
|
||||||
|
for j=1, size[2] do
|
||||||
|
if area[i][j] and area[i][j].mine then
|
||||||
|
local rezerv = {conv_cord(i,j)}
|
||||||
|
gpu.set(rezerv[1], rezerv[2], " m")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
gpu.setBackground(0x000000)
|
||||||
|
gpu.setForeground(0xffffff)
|
||||||
|
-- поздравления
|
||||||
|
os.sleep(2)
|
||||||
|
term.clear()
|
||||||
|
print("You win!")
|
||||||
|
os.sleep(2)
|
||||||
|
term.clear()
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
elseif key == 1 then
|
||||||
|
local swich = true
|
||||||
|
for i=#marker, 1, -1 do
|
||||||
|
if x == marker[i][1] and y == marker[i][2] then
|
||||||
|
table.remove(marker,i)
|
||||||
|
gpu.setBackground(0xAAAAAA)
|
||||||
|
local rezerv = {conv_cord(x,y)}
|
||||||
|
gpu.set(rezerv[1], rezerv[2], " ")
|
||||||
|
swich = false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if swich and area[x][y] then
|
||||||
|
marker[#marker+1]={x,y}
|
||||||
|
gpu.setBackground(0xffaa00)
|
||||||
|
local rezerv = {conv_cord(x,y)}
|
||||||
|
gpu.set(rezerv[1], rezerv[2], " ")
|
||||||
|
end
|
||||||
|
gpu.setBackground(0x000000)
|
||||||
|
end
|
||||||
|
end
|
||||||
BIN
Applications/MineSweeper/Resources/Icon.pic
Normal file
BIN
Applications/MineSweeper/Resources/Icon.pic
Normal file
Binary file not shown.
186
lib/untitled.lua
Normal file
186
lib/untitled.lua
Normal file
@ -0,0 +1,186 @@
|
|||||||
|
local ecs = require("ECSAPI")
|
||||||
|
local xml = require("xmlParser")
|
||||||
|
local image = require("image")
|
||||||
|
local event = require("event")
|
||||||
|
local unicode = require("unicode")
|
||||||
|
local fs = require("filesystem")
|
||||||
|
local gpu = require("component").gpu
|
||||||
|
|
||||||
|
------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
local config = {
|
||||||
|
scale = 0.63,
|
||||||
|
leftBarWidth = 20,
|
||||||
|
scrollSpeed = 6,
|
||||||
|
pathToInfoPanelFolder = "MineOS/System/InfoPanel/",
|
||||||
|
colors = {
|
||||||
|
leftBar = 0x262626,
|
||||||
|
leftBarText = 0xFFFFFF,
|
||||||
|
leftBarSelection = 0x7b1fa2,
|
||||||
|
leftBarSelectionText = 0xFFFFFF,
|
||||||
|
scrollbarBack = 0x7b1fa2,
|
||||||
|
scrollbarPipe = 0x7b1fa2,
|
||||||
|
background = 0x222222,
|
||||||
|
text = 0xdddddd,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
local xOld, yOld = gpu.getResolution()
|
||||||
|
ecs.setScale(config.scale)
|
||||||
|
local xSize, ySize = gpu.getResolution()
|
||||||
|
|
||||||
|
fs.makeDirectory(config.pathToInfoPanelFolder)
|
||||||
|
local currentFile = 1
|
||||||
|
local fileList
|
||||||
|
local stroki = {}
|
||||||
|
local currentString = 1
|
||||||
|
local stringsHeightLimit = ySize - 2
|
||||||
|
local stringsWidthLimit = xSize - config.leftBarWidth - 4
|
||||||
|
|
||||||
|
------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
local obj = {}
|
||||||
|
local function newObj(class, name, ...)
|
||||||
|
obj[class] = obj[class] or {}
|
||||||
|
obj[class][name] = {...}
|
||||||
|
end
|
||||||
|
|
||||||
|
local function drawLeftBar()
|
||||||
|
--ecs.square(1, 1, config.leftBarWidth, ySize, config.colors.leftBar)
|
||||||
|
fileList = ecs.getFileList(config.pathToInfoPanelFolder)
|
||||||
|
obj["Files"] = {}
|
||||||
|
local yPos = 1, 1
|
||||||
|
for i = 1, #fileList do
|
||||||
|
if i == currentFile then
|
||||||
|
newObj("Files", i, ecs.drawButton(1, yPos, config.leftBarWidth, 3, ecs.hideFileFormat(fileList[i]), config.colors.leftBarSelection, config.colors.leftBarSelectionText))
|
||||||
|
else
|
||||||
|
if i % 2 == 0 then
|
||||||
|
newObj("Files", i, ecs.drawButton(1, yPos, config.leftBarWidth, 3, ecs.stringLimit("end", fileList[i], config.leftBarWidth - 2), config.colors.leftBar, config.colors.leftBarText))
|
||||||
|
else
|
||||||
|
newObj("Files", i, ecs.drawButton(1, yPos, config.leftBarWidth, 3, ecs.stringLimit("end", fileList[i], config.leftBarWidth - 2), config.colors.leftBar - 0x111111, config.colors.leftBarText))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
yPos = yPos + 3
|
||||||
|
end
|
||||||
|
ecs.square(1, yPos, config.leftBarWidth, ySize - yPos + 1, config.colors.leftBar)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function loadFile()
|
||||||
|
currentString = 1
|
||||||
|
stroki = {}
|
||||||
|
local file = io.open(config.pathToInfoPanelFolder .. fileList[currentFile], "r")
|
||||||
|
for line in file:lines() do table.insert(stroki, xml.collect(line)) end
|
||||||
|
file:close()
|
||||||
|
end
|
||||||
|
|
||||||
|
local function drawMain()
|
||||||
|
local x, y = config.leftBarWidth + 1, 1
|
||||||
|
local xPos, yPos = x, y
|
||||||
|
|
||||||
|
ecs.square(xPos, yPos, xSize - config.leftBarWidth - 3, ySize, config.colors.background)
|
||||||
|
gpu.setForeground(config.colors.text)
|
||||||
|
xPos = xPos + 2
|
||||||
|
|
||||||
|
for line = currentString, (stringsHeightLimit + currentString - 1) do
|
||||||
|
if stroki[line] then
|
||||||
|
for i = 1, #stroki[line] do
|
||||||
|
if type(stroki[line][i]) == "table" then
|
||||||
|
if stroki[line][i].label == "color" then
|
||||||
|
gpu.setForeground(tonumber(stroki[line][i][1]))
|
||||||
|
elseif stroki[line][i].label == "image" then
|
||||||
|
local bg, fg = gpu.getBackground(), gpu.getForeground()
|
||||||
|
local picture = image.load(stroki[line][i][1])
|
||||||
|
image.draw(xPos, yPos, picture)
|
||||||
|
yPos = yPos + picture.height - 1
|
||||||
|
gpu.setForeground(fg)
|
||||||
|
gpu.setBackground(bg)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
gpu.set(xPos, yPos, stroki[line][i])
|
||||||
|
xPos = xPos + unicode.len(stroki[line][i])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
yPos = yPos + 1
|
||||||
|
xPos = x + 2
|
||||||
|
else
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
local function drawScrollBar()
|
||||||
|
local name
|
||||||
|
name = "⬆"; newObj("Scroll", name, ecs.drawButton(xSize - 2, 1, 3, 3, name, config.colors.leftBarSelection, config.colors.leftBarSelectionText))
|
||||||
|
name = "⬇"; newObj("Scroll", name, ecs.drawButton(xSize - 2, ySize - 2, 3, 3, name, config.colors.leftBarSelection, config.colors.leftBarSelectionText))
|
||||||
|
|
||||||
|
ecs.srollBar(xSize - 2, 4, 3, ySize - 6, #stroki, currentString, config.colors.scrollbarBack, config.colors.scrollbarPipe)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function dro4er()
|
||||||
|
if currentString < (#stroki) then
|
||||||
|
currentString = currentString + 1
|
||||||
|
else
|
||||||
|
currentString = 1
|
||||||
|
end
|
||||||
|
drawMain()
|
||||||
|
drawScrollBar()
|
||||||
|
end
|
||||||
|
|
||||||
|
------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
ecs.prepareToExit()
|
||||||
|
drawLeftBar()
|
||||||
|
loadFile()
|
||||||
|
drawMain()
|
||||||
|
drawScrollBar()
|
||||||
|
|
||||||
|
local timerID = event.timer(0.5, dro4er)
|
||||||
|
|
||||||
|
while true do
|
||||||
|
local e = {event.pull()}
|
||||||
|
if e[1] == "touch" then
|
||||||
|
for key in pairs(obj["Files"]) do
|
||||||
|
if ecs.clickedAtArea(e[3], e[4], obj["Files"][key][1], obj["Files"][key][2], obj["Files"][key][3], obj["Files"][key][4]) then
|
||||||
|
currentFile = key
|
||||||
|
loadFile()
|
||||||
|
drawLeftBar()
|
||||||
|
drawMain()
|
||||||
|
drawScrollBar()
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
for key in pairs(obj["Scroll"]) do
|
||||||
|
if ecs.clickedAtArea(e[3], e[4], obj["Scroll"][key][1], obj["Scroll"][key][2], obj["Scroll"][key][3], obj["Scroll"][key][4]) then
|
||||||
|
ecs.drawButton(obj["Scroll"][key][1], obj["Scroll"][key][2], 3, 3, key, config.colors.leftBarSelectionText, config.colors.leftBarSelection)
|
||||||
|
os.sleep(0.2)
|
||||||
|
ecs.drawButton(obj["Scroll"][key][1], obj["Scroll"][key][2], 3, 3, key, config.colors.leftBarSelection, config.colors.leftBarSelectionText)
|
||||||
|
|
||||||
|
if key == "⬆" then
|
||||||
|
if currentString > config.scrollSpeed then
|
||||||
|
currentString = currentString - config.scrollSpeed
|
||||||
|
drawMain()
|
||||||
|
drawScrollBar()
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if currentString < (#stroki - config.scrollSpeed + 1) then
|
||||||
|
currentString = currentString + config.scrollSpeed
|
||||||
|
drawMain()
|
||||||
|
drawScrollBar()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
elseif e[1] == "key_down" then
|
||||||
|
if e[4] == 28 then
|
||||||
|
gpu.setResolution(xOld, yOld)
|
||||||
|
ecs.prepareToExit()
|
||||||
|
event.cancel(timerID)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Loading…
x
Reference in New Issue
Block a user