Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Made by Jay5476
- -- Credit To:
- -- Version 0.1
- -- Important values
- local w,h = term.getSize()
- local nBuildingScroll = 0
- local sGameDir = "Idle"
- local tLocalFiles = {["SAVES"] = false}
- local tPasteBinFiles = {["API"] = "CodeHere"}
- tBuildingsDisplay = {
- [1] = 1,
- [2] = 2,
- [3] = 3,
- [4] = 4,
- [5] = 5,
- [6] = 6,
- [7] = 7,
- [8] = 8,
- [9] = 9,
- [10] = 10,
- [11] = 11,
- [12] = 12,
- [13] = 13,
- [14] = 14,
- [15] = 15,
- [16] = 16,
- [17] = 17,
- [18] = 18
- }
- local tGameValues = {
- ["TotalAutoCPS"] = 0,
- ["AutoCPSValue"] = 1,
- ["TotalClicks"] = 0,
- ["ClickValue"] = 1,
- ["Coins"] = 0,
- ["B1"] = {
- ["Value"] = 10,
- ["StartPrice"] = 100,
- ["Price"] = 100,
- ["Owned"] = 0
- },
- ["B2"] = {
- ["Value"] = 15,
- ["StartPrice"] = 300,
- ["Price"] = 300,
- ["Owned"] = 0
- },
- ["B3"] = {
- ["Value"] = 50,
- ["Price"] = 1000,
- ["Owned"] = 0
- },
- [""] = 0,
- } -- Add buildings
- local sGameValues = textutils.serialize(tGameValues)
- -- Base Functions
- local function clear() -- Clears Screen
- term.clear()
- term.setCursorPos(1,1)
- end
- local function cPrint(str) -- Print to centre
- local _, y = term.getCursorPos()
- term.setCursorPos(math.floor((w-#str)/2),y)
- print(str)
- end
- local function tNumber(tab)
- i = 0
- for k,v in pairs(tab) do
- i = i + 1
- end
- return i
- end
- local function Counter()
- tBuildingsDisplay = {
- [1] = 1,
- [2] = 2,
- [3] = 3,
- [4] = 4,
- [5] = 5,
- [6] = 6,
- [7] = 7,
- [8] = 8,
- [9] = 9,
- [10] = 10,
- [11] = 11,
- [12] = 12,
- [13] = 13,
- [14] = 14,
- [15] = 15,
- [16] = 16,
- [17] = 17,
- [18] = 18
- }
- clear()
- cPrint("Coins: "..math.floor(tGameValues.Coins).." (+"..math.floor(tGameValues.ClickValue).." Per Click)")
- cPrint("Auto Coins: "..math.floor(tGameValues.AutoCPSValue).." Per 1s")
- --cPrint("Total Clicks: "..tGameValues.TotalClicks)
- for i = 1, w do
- term.write("-")
- end
- for building = 1, 4 do -- Show for buildings at a time
- for i = 1, 3 do
- term.setCursorPos(1,i+4*building-1)
- print(tBuildingsDisplay[i+3*building-3+(nBuildingScroll*3)] or "Coming Soon")
- end
- for x = 1, 20 do
- term.setCursorPos(x,3+4*building)
- term.write("-")
- term.setCursorPos(x,h)
- term.write("-")
- end
- end
- end
- -- Debug Functions/values
- bDebug = false
- local function dPrint(str, reason)
- reason = reason or "Debugging"
- str = str or ""
- if bDebug then
- local sColor = term.getTextColor()
- term.setTextColor(colors.green)
- print("Debug Text\n"..reason..": ")
- term.setTextColor(colors.red)
- print(str.."\nPress any key to continue")
- term.setTextColor(sColor)
- os.pullEvent("key")
- end
- end
- -- Game Save/load
- local function intFiles()
- local bFirstTime = true
- if fs.exists(sGameDir) then
- bFirstTime = false
- dPrint("True", "Checking Directory Return")
- for k,v in pairs(tLocalFiles) do
- if fs.exists(sGameDir.."/"..k) then
- tLocalFiles[k] = true
- end
- if not tLocalFiles[k] then
- print(k.." Doesnt Exist, Creating")
- local file = fs.open(sGameDir.."/"..k, "a")
- file.write(sGameValues,a)
- file.close()
- end
- end
- else
- print("Creating Directory")
- fs.makeDir(sGameDir)
- for k,v in pairs(tLocalFiles) do
- local file = fs.open(sGameDir.."/"..k, "w")
- file.write(sGameValues)
- file.close()
- print("Created "..k)
- end
- end
- end
- local function loadSaves()
- local file = fs.open(sGameDir.."/SAVES", "r")
- sLoadGameValues = file.readAll()
- tLoadGameValues = textutils.unserialize(sLoadGameValues)
- file.close()
- clear()
- print("Loaded game values..")
- for k, v in pairs(tLoadGameValues) do -- Get all loaded values and put into current
- if tGameValues[k] then
- tGameValues[k] = v
- end
- end
- for k,v in pairs(tGameValues) do
- if type(v)=="table" then
- for k1, v1 in pairs(v) do
- print("Playing with "..k..k1..": "..v1)
- end
- else
- print("Playing With "..k..": "..v)
- end
- end
- print("Press any key to continue")
- os.pullEvent("key")
- end
- local function saveFile()
- local tSaveGameValues = tGameValues -- Grab current values
- sSaveGameValues = textutils.serialize(tSaveGameValues) -- Store to string
- local file = fs.open(sGameDir.."/SAVES", "w") -- Open save file
- file.write(sSaveGameValues) -- Overwrite save
- file.close()
- end
- -- Game functions/code
- local function buyBuilding(building)
- local tBuilding = tGameValues[building]
- if tBuilding and type(tBuilding) == "table" then
- if tGameValues.Coins > tBuilding.Price then
- tBuilding.Owned = tBuilding.Owned + 1
- tGameValues.Coins = tGameValues.Coins - tBuilding.Price
- tBuilding.Price = tBuilding.Price * 1.15
- else
- dPrint("Not enough","Building not bought")
- return
- end
- else
- dPrint("Doesn't exist","Building not bought")
- return
- end
- end
- local function playerClick()
- tGameValues.TotalClicks = tGameValues.TotalClicks + 1
- tGameValues.Coins = tGameValues.ClickValue + tGameValues.Coins
- tGameValues.ClickValue = 1 + (0.01 * tGameValues.TotalClicks)
- end
- local function autoCPS()
- tGameValues.TotalAutoCPS = tGameValues.TotalAutoCPS + 1
- tGameValues.Coins = tGameValues.AutoCPSValue + tGameValues.Coins
- buyBuilding("B1")
- buyBuilding("B2")
- buyBuilding("B3")
- tGameValues.AutoCPSValue =
- 1 + tGameValues.B1.Owned * tGameValues.B1.Value
- + tGameValues.B2.Owned * tGameValues.B2.Value
- + tGameValues.B3.Owned * tGameValues.B3.Value
- end
- clear()
- intFiles()
- loadSaves()
- clear()
- os.startTimer(1)
- while true do
- Counter()
- e, p1, p2, p3 = os.pullEvent()
- -- Event, Button, X, Y for mouseclick
- term.setCursorPos(30,10)
- if e == "mouse_click" then
- if p2 >21 then
- playerClick()
- end
- elseif e == "timer" then
- os.startTimer(1)
- autoCPS()
- elseif e == "key" or "key_up" then
- if p1 == 200 and nBuildingScroll > 0 then
- nBuildingScroll = nBuildingScroll -1
- elseif p1 == 208 and nBuildingScroll < ((#tBuildingsDisplay/3) - 4) then
- nBuildingScroll = nBuildingScroll + 1
- end
- term.write(nBuildingScroll.."|")
- term.write(#tBuildingsDisplay/3)
- term.write("|"..e.."|"..p1)
- sleep(1)
- end
- saveFile()
- end
Advertisement
Add Comment
Please, Sign In to add comment