Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function clr()
- scr.clear()
- scr.setCursorPos(1,1)
- end
- function getYourThings()
- local luck = math.random(inventory.tool.luck,100)
- if luck == 100 then
- inventory.diamond = inventory.diamond+1
- elseif luck >= 90 then
- inventory.tin = inventory.tin+1
- elseif luck >= 80 then
- inventory.copper = inventory.copper+1
- elseif luck >= 70 then
- inventory.iron = inventory.iron+1
- else
- inventory.stone = inventory.stone+1
- end
- displayUpdate()
- end
- function console(text)
- if sConsole then
- print(tostring(text))
- end
- end
- function printStuff()
- print("Stuff")
- end
- function fileRead(dir)
- local file = fs.open(dir, "r")
- if file == nil then return end
- local text = file.readAll()
- file.close()
- return text
- end
- function save(name)
- local serial = textutils.serialize(inventory)
- local file = fs.open("savegames/"..name, "w")
- file.write(serial)
- file.close()
- end
- function renderFile(dir)
- if fs.exists(dir) then
- local file = fs.open(dir, "r")
- local x,y = scr.getCursorPos()
- local line = ""
- while line ~= nil do
- scr.setCursorPos(x,y)
- line = file.readLine()
- scr.write(line)
- y=y+1
- end
- file.close()
- return true
- else
- return false
- end
- end
- function displayUpdate()
- -- Displaying minerals in the inventory
- scr.setCursorPos(1,1)
- scr.clearLine()
- scr.setTextColor(colors.gray)
- scr.write("S:"..inventory.stone)
- term.setTextColor(colors.lightGray)
- scr.setCursorPos(0.2*scr.x,1)
- scr.write("I:"..inventory.iron)
- term.setTextColor(colors.orange)
- scr.setCursorPos(0.4*scr.x,1)
- scr.write("C:"..inventory.copper)
- term.setTextColor(colors.white)
- scr.setCursorPos(0.6*scr.x,1)
- scr.write("T:"..inventory.tin)
- term.setTextColor(colors.lightBlue)
- scr.setCursorPos(0.8*scr.x,1)
- scr.write("D:"..inventory.diamond)
- term.setTextColor(colors.white)
- -- Displaying dwarves
- for i=1,inventory.dwarves.mining do
- if i<=#dwarvesX then
- scr.setCursorPos(dwarvesX[i], dwarvesY[i])
- renderFile("res/dwarfMining.txt")
- end
- end
- for i=inventory.dwarves.mining,#dwarvesX do
- scr.setCursorPos(dwarvesX[i], dwarvesY[i])
- renderFile("res/dwarfGone.txt")
- end
- scr.setCursorPos(1, scr.x)
- scr.clearLine()
- scr.write("Dwarves: "..inventory.dwarves.mining)
- end
- function getKeys()
- while true do
- local event, param1, param2, param3, param4 = os.pullEvent()
- if event == "key" then
- local key = param1
- local char = keys.getName(key)
- if char == "up" then
- inventory.dwarves.mining = inventory.dwarves.mining+1
- elseif char == "down" then
- inventory.dwarves.mining = inventory.dwarves.mining-1
- end
- end
- end
- end
- function newGame(name)
- inventory.stone = 0
- inventory.iron = 0
- inventory.copper = 0
- inventory.tin = 0
- inventory.diamond = 0
- inventory.dwarves.mining = 1
- inventory.tool.name = "hand"
- inventory.tool.speed = 1
- inventory.tool.luck = 1
- end
- function load(name)
- local file = fs.open("savegames/"..name, "r")
- if file ~= nil then
- local save = file.readAll()
- file.close()
- inventory = textutils.unserialize(save)
- end
- end
- function runEvery(delay, sFunc, param1)
- if isInteger(tick/delay) then
- sFunc(param1)
- end
- end
- function isInteger(x)
- return math.floor(x)==x
- end
- function main()
- tick=tick+1
- sleep(0.05) -- 1/20
- runEvery(30, save, player) --30s
- runEvery(20/inventory.dwarves.mining, getYourThings) --add new items -1s*dwarves
- end
- scr = term
- scr.x, scr.y = scr.getSize()
- tick = 1
- sid = {}
- inventory = {}
- inventory.tool = {}
- inventory.dwarves = {}
- sConsole = true
- dwarvesX = {29,36,38,40,42,44,46,48,50,31}
- dwarvesY = {18,07,07,07,07,07,07,07,07,05}
- clr()
- scr.setCursorPos(1,10)
- print("Please identify")
- print(" yourself")
- scr.setCursorPos(18,1)
- renderFile("res/sidOpen.txt")
- event, player = os.pullEvent("player")
- if fs.exists("savegames/"..player) then
- load(player)
- else
- newGame(player)
- save(player)
- end
- print("")
- if sConsole then
- print("Player "..player.." was loaded successfully !")
- else
- textutils.slowPrint("Player "..player.." was loaded successfully ! ", 80)
- end
- clr()
- scr.setCursorPos(20,2)
- renderFile("res/mountain.txt")
- while true do
- parallel.waitForAny(main, getKeys)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement