Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[ COPYRIGHT MACKAN90096 (Max Thor) ]--
- -- Check stuff --
- w, h = term.getSize()
- local Income = 0
- local money = 100
- inRate = 60
- -- Variables --
- local incomes = {["house"]=10, ["farm"]=20, ["factory"]=50}
- local price = {["house"]=100, ["farm"]=200, ["factory"]=500}
- local buildings = {["house"]=0,["farm"]=0, ["factory"]=0}
- local upgrades = {["Income+"]=5000}
- -- End Variables --
- if not term.isColor() then
- print("Sorry, you need an advanced computer for this")
- return
- end
- function income()
- timer = os.startTimer(inRate)
- end
- function cPrint(str, y)
- term.setCursorPos(math.floor(w-string.len(str))/2,y)
- print(str)
- end
- function shop()
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- term.clear()
- bar1()
- term.setCursorPos(1,2)
- for k,v in pairs(price) do
- print("Buy "..k..": "..v)
- end
- print("[Upgrades]")
- print("[ Save ]")
- print("[ Exit ]")
- end
- function upgrade()
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- term.clear()
- bar1()
- term.setCursorPos(1,2)
- for k,v in pairs(upgrades) do
- print("Buy "..k..": "..v)
- end
- print("[ Exit ]")
- end
- function drawBuilds()
- term.setCursorPos(1,3)
- term.setBackgroundColor(colors.brown)
- term.setTextColor(colors.white)
- print(buildings["house"])
- term.setBackgroundColor(colors.red)
- print(buildings["farm"])
- term.setBackgroundColor(colors.gray)
- print(buildings["factory"])
- end
- function bar1()
- term.setTextColor(colors.black)
- term.setCursorPos(1,1)
- term.clearLine()
- paintutils.drawLine(1,1,w,1, colors.lightBlue)
- term.setCursorPos(1,1)
- print("[Shop] Money: "..money.." Income per "..inRate.." second(s): "..Income)
- end
- function game()
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- term.clear()
- bar1()
- drawBuilds()
- end
- function load2()
- vars = load(".save")
- money = vars[1]
- Income = vars[2]
- inRate = vars[3]
- buildings["house"] = vars[4]
- buildings["farm"] = vars[5]
- buildings["factory"] = vars[6]
- end
- function load(path)
- local tempData = {}
- local file = fs.open(path,"r")
- while true do
- local line = file.readLine()
- if line then
- table.insert(tempData,textutils.unserialize(line))
- else
- file.close()
- break
- end
- end
- return tempData
- end
- function save(path,data)
- local file = fs.open(path,"w")
- for k,v in pairs(data) do
- file.writeLine(textutils.serialize(v))
- end
- file.close()
- end
- function start()
- income()
- slc = 0
- term.setBackgroundColor(colors.lightBlue)
- term.setTextColor(colors.white)
- term.clear()
- cPrint("[Menu]", 1)
- cPrint("[Load]", 3)
- cPrint("[New]", 5)
- end
- function cheat()
- game()
- end
- start()
- while true do
- e,p1,p2,p3 = os.pullEvent()
- if e == "mouse_click" then
- if slc == 0 then
- if p2 >= 22 and p2 <= 27 and p3 == 3 and p1 == 1 then
- load2()
- slc = 2
- game()
- elseif p2 >= 23 and p2 <= 27 and p3 == 5 and p1 == 1 then
- game()
- slc = 2
- end
- elseif slc == 2 then
- if p2 >= 1 and p2 <= 6 and p3 == 1 and p1 == 1 then
- shop()
- slc = 3
- end
- elseif slc == 3 then
- if p2 >= 1 and p2 <= string.len("house") and p3 == 3 and p1 == 1 then
- if money >= price["house"] then
- Income = Income+incomes["house"]
- money = money-price["house"]
- buildings["house"] = buildings["house"]+1
- slc = 2
- game()
- end
- elseif p2 >= 1 and p2 <= string.len("farm") and p3 == 4 and p1 == 1 then
- if money >= price["farm"] then
- Income = Income+incomes["farm"]
- money = money-price["farm"]
- buildings["farm"] = buildings["farm"]+1
- slc = 2
- game()
- end
- elseif p2 >= 1 and p2 <= string.len("factory") and p3 == 2 and p1 == 1 then
- if money >= price["factory"] then
- Income = Income+incomes["factory"]
- money = money-price["factory"]
- buildings["factory"] = buildings["factory"]+1
- slc = 2
- game()
- end
- elseif p2 >= 1 and p2 <= string.len("[Save]") and p3 == 6 and p1 == 1 then
- save(".save",{money,Income,inRate,buildings["house"],buildings["farm"],buildings["factory"]})
- elseif p2 >= 1 and p2 <= string.len("[Exit]") and p3 == 7 and p1 == 1 then
- slc = 2
- game()
- elseif p2 >= 1 and p2 <= string.len("[Upgrades]") and p3 == 5 and p1 == 1 then
- slc = 4
- upgrade()
- end
- elseif slc == 4 then
- if p2 >= 1 and p2 <= string.len("[Exit]") and p3 == 2 and p1 == 3 then
- slc = 2
- game()
- elseif p2 >= 1 and p2 <= string.len(upgrades["Income+"]) and p3 == 2 and p1 == 1 then
- if money >= upgrades["Income+"] then
- if inRate >= 10 then
- minusRate = inRate/10
- inRate2 = inRate-minusRate
- inRate = math.ceil(inRate2)
- money = money - upgrades["Income+"]
- slc = 2
- game()
- end
- else
- slc = 2
- game()
- end
- end
- end
- elseif e == "timer" then
- money = money+Income
- income()
- if slc == 2 or slc == 3 or slc == 4 then
- bar1()
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement