Mackan90096

Investor version 1.1

Sep 17th, 2013
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.10 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. -- Minigames --
  23. function minigame()
  24. term.clear()
  25. term.setCursorPos(1,1)
  26. print("Dice")
  27. end
  28.  
  29. function dice()
  30. dnum = math.random(1,6)
  31. term.clear()
  32. cPrint("Money: "..money, 2)
  33. cWrite("Bet> ",4)
  34. bet = read()
  35. cWrite("Number> ",6)
  36. num = read()
  37. cPrint("Rolled: "..dnum,8)
  38. if tonumber(num) == tonumber(dnum) then
  39.     add = bet*2
  40.     money = money+add
  41.     cPrint("You won!",10)
  42.     sleep(1)
  43.     slc = 2
  44.     game()
  45. else
  46.     money = money-bet
  47.     cPrint("You lost", 10)
  48.     sleep(1)
  49.     slc = 2
  50.     game()
  51. end
  52. end
  53.  
  54. -- End Minigames --
  55.  
  56. function income()
  57.     timer = os.startTimer(inRate)
  58. end
  59.  
  60. function cPrint(str, y)
  61. term.setCursorPos(math.floor(w-string.len(str))/2,y)
  62. print(str)
  63. end
  64.  
  65. function cWrite(str, y)
  66. term.setCursorPos(math.floor(w-string.len(str))/2,y)
  67. write(str)
  68. end
  69.  
  70. function shop()
  71. term.setBackgroundColor(colors.white)
  72. term.setTextColor(colors.black)
  73. term.clear()
  74. bar1()
  75. term.setCursorPos(1,2)
  76.     for k,v in pairs(price) do
  77.     print("Buy "..k..": "..v)
  78.     end
  79.     print("[Upgrades]")
  80.     print("[  Save  ]")
  81.     print("[Minigame]")
  82.     print("[  Exit  ]")
  83. end
  84.  
  85. function upgrade()
  86. term.setBackgroundColor(colors.white)
  87. term.setTextColor(colors.black)
  88. term.clear()
  89. bar1()
  90. term.setCursorPos(1,2)
  91.     for k,v in pairs(upgrades) do
  92.     print("Buy "..k..": "..v)
  93.     end
  94.     print("[  Exit  ]")
  95. end
  96.  
  97. function drawBuilds()
  98. term.setCursorPos(1,3)
  99. term.setBackgroundColor(colors.brown)
  100. term.setTextColor(colors.white)
  101. print(buildings["house"].." Houses")
  102. term.setBackgroundColor(colors.red)
  103. print(buildings["farm"].." Farms")
  104. term.setBackgroundColor(colors.gray)
  105. print(buildings["factory"].." Factories")
  106. end
  107.  
  108. function bar1()
  109. term.setTextColor(colors.black)
  110. term.setCursorPos(1,1)
  111. term.clearLine()
  112. paintutils.drawLine(1,1,w,1, colors.lightBlue)
  113. term.setCursorPos(1,1)
  114. print("[Shop] Money: "..money.." Income per "..inRate.." second(s): "..Income)
  115. end
  116.  
  117. function game()
  118. term.setBackgroundColor(colors.white)
  119. term.setTextColor(colors.black)
  120. term.clear()
  121. bar1()
  122. drawBuilds()
  123. end
  124.  
  125. function load2()
  126. vars = load(".save")
  127.     money = vars[1]
  128.     Income = vars[2]
  129.     inRate = vars[3]
  130.     buildings["house"] = vars[4]
  131.     buildings["farm"] = vars[5]
  132.     buildings["factory"] = vars[6]
  133. end
  134.  
  135. function load(path)
  136.     local tempData = {}
  137.     local file = fs.open(path,"r")
  138.     while true do
  139.         local line = file.readLine()
  140.         if line then
  141.             table.insert(tempData,textutils.unserialize(line))
  142.         else
  143.             file.close()
  144.             break
  145.         end
  146.     end
  147.     return tempData
  148. end
  149.  
  150. function save(path,data)
  151.     local file = fs.open(path,"w")
  152.     for k,v in pairs(data) do
  153.         file.writeLine(textutils.serialize(v))
  154.     end
  155.     file.close()
  156. end
  157.  
  158. function start()
  159. income()
  160. slc = 0
  161. term.setBackgroundColor(colors.lightBlue)
  162. term.setTextColor(colors.white)
  163. term.clear()
  164. cPrint("[Menu]", 1)
  165. cPrint("[Load]", 3)
  166. cPrint("[New]", 5)
  167. end
  168.  
  169. function cheat()
  170. game()
  171. end
  172.  
  173. start()
  174. while true do
  175. e,p1,p2,p3 = os.pullEvent()
  176. if e == "mouse_click" then
  177.     if slc == 0 then
  178.         if p2 >= 22 and p2 <= 27 and p3 == 3 and p1 == 1 then
  179.         load2()
  180.         slc = 2
  181.         game()
  182.     elseif p2 >= 23 and p2 <= 27 and p3 == 5 and p1 == 1 then
  183.         game()
  184.         slc = 2
  185.         end
  186.     elseif slc == 2 then
  187.         if p2 >= 1 and p2 <= 6 and p3 == 1 and p1 == 1 then
  188.         shop()
  189.         slc = 3
  190.         end
  191.     elseif slc == 3 then
  192.         if p2 >= 1 and p2 <= string.len("house") and p3 == 3 and p1 == 1 then
  193.             if money >= price["house"] then
  194.             Income = Income+incomes["house"]
  195.             money = money-price["house"]
  196.             buildings["house"] = buildings["house"]+1
  197.             slc = 2
  198.             game()
  199.             else
  200.             cPrint("You dont have enough money",5)
  201.             slc = 2
  202.             sleep(1)
  203.             game()
  204.             end
  205.         elseif p2 >= 1 and p2 <= string.len("farm") and p3 == 4 and p1 == 1 then
  206.             if money >= price["farm"] then
  207.             Income = Income+incomes["farm"]
  208.             money = money-price["farm"]
  209.             buildings["farm"] = buildings["farm"]+1
  210.             slc = 2
  211.             game()
  212.             else
  213.             cPrint("You dont have enough money",5)
  214.             slc = 2
  215.             sleep(1)
  216.             game()
  217.             end
  218.         elseif p2 >= 1 and p2 <= string.len("factory") and p3 == 2 and p1 == 1 then
  219.             if money >= price["factory"] then
  220.             Income = Income+incomes["factory"]
  221.             money = money-price["factory"]
  222.             buildings["factory"] = buildings["factory"]+1
  223.             slc = 2
  224.             game()
  225.             else
  226.             cPrint("You dont have enough money",5)
  227.             slc = 2
  228.             sleep(1)
  229.             game()
  230.             end
  231.         elseif p2 >= 1 and p2 <= string.len("[Save]") and p3 == 6 and p1 == 1 then
  232.             save(".save",{money,Income,inRate,buildings["house"],buildings["farm"],buildings["factory"]})
  233.             cPrint("Saved!",5)
  234.             slc = 2
  235.             sleep(1)
  236.             game()
  237.         elseif p2 >= 1 and p2 <= string.len("[Minigame]") and p3 == 7 and p1 == 1 then
  238.             slc = 6
  239.             minigame()
  240.         elseif p2 >= 1 and p2 <= string.len("[Exit]") and p3 == 8 and p1 == 1 then
  241.             slc = 2
  242.             game()
  243.         elseif p2 >= 1 and p2 <= string.len("[Upgrades]") and p3 == 5 and p1 == 1 then
  244.             slc = 4
  245.             upgrade()
  246.         end
  247.     elseif slc == 4 then
  248.         if p2 >= 1 and p2 <= string.len("[Exit]") and p3 == 2 and p1 == 3 then
  249.             slc = 2
  250.             game()
  251.         elseif p2 >= 1 and p2 <= string.len(upgrades["Income+"]) and p3 == 2 and p1 == 1 then
  252.             if money >= upgrades["Income+"] then
  253.                 if inRate >= 10 then
  254.                 minusRate = inRate/10
  255.                 inRate2 = inRate-minusRate
  256.                 inRate = math.ceil(inRate2)
  257.                 money = money - upgrades["Income+"]
  258.                 slc = 2
  259.                 game()
  260.                 end
  261.             else
  262.                 cPrint("You dont have enough money",5)
  263.                 sleep(1)
  264.                 slc = 2
  265.                 game()
  266.             end
  267.         end
  268.     elseif slc == 6 then
  269.         if p2 >= 1 and p2 <= string.len("Dice") and p3 == 1 and p1 == 1 then
  270.             dice()
  271.         end
  272.     end
  273. elseif e == "timer" then
  274. money = money+Income
  275. income()
  276.     if slc == 2 or slc == 3 or slc == 4 then
  277.     bar1()
  278.     end
  279.  
  280. end
  281. end
Advertisement
Add Comment
Please, Sign In to add comment