Advertisement
Mackan90096

Investor version 1.0

Sep 13th, 2013
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.85 KB | None | 0 0
  1. --[ COPYRIGHT MACKAN90096 (Max Thor) ]--
  2.  
  3.  
  4. -- Check stuff --
  5. w, h = term.getSize()
  6. local Income = 0
  7. local money = 100
  8. inRate = 60
  9. -- Variables --
  10.  
  11. local incomes = {["house"]=10, ["farm"]=20, ["factory"]=50}
  12. local price = {["house"]=100, ["farm"]=200, ["factory"]=500}
  13. local buildings = {["house"]=0,["farm"]=0, ["factory"]=0}
  14. local upgrades = {["Income+"]=5000}
  15. -- End Variables --
  16.  
  17. if not term.isColor() then
  18. print("Sorry, you need an advanced computer for this")
  19. return
  20. end
  21.  
  22. function income()
  23.     timer = os.startTimer(inRate)
  24. end
  25.  
  26. function cPrint(str, y)
  27. term.setCursorPos(math.floor(w-string.len(str))/2,y)
  28. print(str)
  29. end
  30.  
  31. function shop()
  32. term.setBackgroundColor(colors.white)
  33. term.setTextColor(colors.black)
  34. term.clear()
  35. bar1()
  36. term.setCursorPos(1,2)
  37.     for k,v in pairs(price) do
  38.     print("Buy "..k..": "..v)
  39.     end
  40.     print("[Upgrades]")
  41.     print("[  Save  ]")
  42.     print("[  Exit  ]")
  43. end
  44.  
  45. function upgrade()
  46. term.setBackgroundColor(colors.white)
  47. term.setTextColor(colors.black)
  48. term.clear()
  49. bar1()
  50. term.setCursorPos(1,2)
  51.     for k,v in pairs(upgrades) do
  52.     print("Buy "..k..": "..v)
  53.     end
  54.     print("[  Exit  ]")
  55. end
  56.  
  57. function drawBuilds()
  58. term.setCursorPos(1,3)
  59. term.setBackgroundColor(colors.brown)
  60. term.setTextColor(colors.white)
  61. print(buildings["house"])
  62. term.setBackgroundColor(colors.red)
  63. print(buildings["farm"])
  64. term.setBackgroundColor(colors.gray)
  65. print(buildings["factory"])
  66. end
  67.  
  68. function bar1()
  69. term.setTextColor(colors.black)
  70. term.setCursorPos(1,1)
  71. term.clearLine()
  72. paintutils.drawLine(1,1,w,1, colors.lightBlue)
  73. term.setCursorPos(1,1)
  74. print("[Shop] Money: "..money.." Income per "..inRate.." second(s): "..Income)
  75. end
  76.  
  77. function game()
  78. term.setBackgroundColor(colors.white)
  79. term.setTextColor(colors.black)
  80. term.clear()
  81. bar1()
  82. drawBuilds()
  83. end
  84.  
  85. function load2()
  86. vars = load(".save")
  87.     money = vars[1]
  88.     Income = vars[2]
  89.     inRate = vars[3]
  90.     buildings["house"] = vars[4]
  91.     buildings["farm"] = vars[5]
  92.     buildings["factory"] = vars[6]
  93. end
  94.  
  95. function load(path)
  96.     local tempData = {}
  97.     local file = fs.open(path,"r")
  98.     while true do
  99.         local line = file.readLine()
  100.         if line then
  101.             table.insert(tempData,textutils.unserialize(line))
  102.         else
  103.             file.close()
  104.             break
  105.         end
  106.     end
  107.     return tempData
  108. end
  109.  
  110. function save(path,data)
  111.     local file = fs.open(path,"w")
  112.     for k,v in pairs(data) do
  113.         file.writeLine(textutils.serialize(v))
  114.     end
  115.     file.close()
  116. end
  117.  
  118. function start()
  119. income()
  120. slc = 0
  121. term.setBackgroundColor(colors.lightBlue)
  122. term.setTextColor(colors.white)
  123. term.clear()
  124. cPrint("[Menu]", 1)
  125. cPrint("[Load]", 3)
  126. cPrint("[New]", 5)
  127. end
  128.  
  129. function cheat()
  130. game()
  131. end
  132.  
  133. start()
  134. while true do
  135. e,p1,p2,p3 = os.pullEvent()
  136. if e == "mouse_click" then
  137.     if slc == 0 then
  138.         if p2 >= 22 and p2 <= 27 and p3 == 3 and p1 == 1 then
  139.         load2()
  140.         slc = 2
  141.         game()
  142.     elseif p2 >= 23 and p2 <= 27 and p3 == 5 and p1 == 1 then
  143.         game()
  144.         slc = 2
  145.         end
  146.     elseif slc == 2 then
  147.         if p2 >= 1 and p2 <= 6 and p3 == 1 and p1 == 1 then
  148.         shop()
  149.         slc = 3
  150.         end
  151.     elseif slc == 3 then
  152.         if p2 >= 1 and p2 <= string.len("house") and p3 == 3 and p1 == 1 then
  153.             if money >= price["house"] then
  154.             Income = Income+incomes["house"]
  155.             money = money-price["house"]
  156.             buildings["house"] = buildings["house"]+1
  157.             slc = 2
  158.             game()
  159.             end
  160.         elseif p2 >= 1 and p2 <= string.len("farm") and p3 == 4 and p1 == 1 then
  161.             if money >= price["farm"] then
  162.             Income = Income+incomes["farm"]
  163.             money = money-price["farm"]
  164.             buildings["farm"] = buildings["farm"]+1
  165.             slc = 2
  166.             game()
  167.             end
  168.         elseif p2 >= 1 and p2 <= string.len("factory") and p3 == 2 and p1 == 1 then
  169.             if money >= price["factory"] then
  170.             Income = Income+incomes["factory"]
  171.             money = money-price["factory"]
  172.             buildings["factory"] = buildings["factory"]+1
  173.             slc = 2
  174.             game()
  175.             end
  176.         elseif p2 >= 1 and p2 <= string.len("[Save]") and p3 == 6 and p1 == 1 then
  177.             save(".save",{money,Income,inRate,buildings["house"],buildings["farm"],buildings["factory"]})
  178.             elseif p2 >= 1 and p2 <= string.len("[Exit]") and p3 == 7 and p1 == 1 then
  179.             slc = 2
  180.             game()
  181.         elseif p2 >= 1 and p2 <= string.len("[Upgrades]") and p3 == 5 and p1 == 1 then
  182.             slc = 4
  183.             upgrade()
  184.         end
  185.     elseif slc == 4 then
  186.         if p2 >= 1 and p2 <= string.len("[Exit]") and p3 == 2 and p1 == 3 then
  187.             slc = 2
  188.             game()
  189.         elseif p2 >= 1 and p2 <= string.len(upgrades["Income+"]) and p3 == 2 and p1 == 1 then
  190.             if money >= upgrades["Income+"] then
  191.                 if inRate >= 10 then
  192.                 minusRate = inRate/10
  193.                 inRate2 = inRate-minusRate
  194.                 inRate = math.ceil(inRate2)
  195.                 money = money - upgrades["Income+"]
  196.                 slc = 2
  197.                 game()
  198.                 end
  199.             else
  200.                 slc = 2
  201.                 game()
  202.             end
  203.         end
  204.     end
  205. elseif e == "timer" then
  206. money = money+Income
  207. income()
  208.     if slc == 2 or slc == 3 or slc == 4 then
  209.     bar1()
  210.     end
  211.  
  212. end
  213. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement