cli-io.lua 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. function saveHighScores()
  2. print("High scores saved!")
  3. end
  4. function printCursor(page)
  5. local maxOptions = #page.options
  6. for i=maxOptions, 1, -1 do
  7. local optionList = page.options[i]
  8. if (i == page.level) then
  9. io.write("O < ")
  10. else
  11. io.write(" < ")
  12. end
  13. io.write(optionList[page.selections[i]])
  14. print(" >")
  15. end
  16. end
  17. function renderPlanetShipyardScreen()
  18. local shipId = getSelection(page, 3)
  19. local cost = shipList[shipId].cost
  20. local tradeInCredit = shipResaleFactor * player.ship.cost
  21. print("Current ship: " .. player.ship.model)
  22. print("Current ship trade-in credit: " .. string.format("%d", tradeInCredit))
  23. print("New ship cost: " .. string.format("%d", cost))
  24. if (tradeInCredit - cost <= 0) then
  25. print("Total cost: " .. string.format("%d", cost - tradeInCredit))
  26. else
  27. print("Total credit: " .. string.format("%d", tradeInCredit - cost))
  28. end
  29. print("Credits: " .. player.credits)
  30. end
  31. function renderPlanetServicesScreen()
  32. local serviceId = getSelection(page, 2)
  33. local serviceCost = serviceList[serviceId].cost
  34. print("Hull Condition: " .. string.format("%d", math.floor(100 * player.ship.hullHealth / player.ship.hullStrength)) .. "%")
  35. print("Fuel: " .. tostring(player.ship.fuel) .. " / " .. tostring(player.ship.maxFuel))
  36. print("Service Cost: " .. tostring(serviceCost))
  37. print("Credits: " .. player.credits)
  38. end
  39. function renderPlanetPlanetsScreen()
  40. local id = getSelection(page, 3)
  41. local targetPlanet = planetList[id]
  42. local distance = calculatePlanetDistance(player.planet, targetPlanet)
  43. print("Distance: " .. tostring(distance) .. " Miles")
  44. end
  45. function renderPlanetBuyScreen()
  46. local commodityId = getSelection(page, 3)
  47. local commodity = commodityList[commodityId]
  48. print("Stock: " .. player.planet.commodities[commodityId])
  49. print("Unit Cost: " .. math.floor(player.planet.commodityRates[commodityId] * commodity.baseCost))
  50. print("In Inventory: " .. player.commodities[commodityId])
  51. print("Credits: " .. player.credits)
  52. end
  53. function processInput()
  54. if (not gameLoaded) then
  55. newGame()
  56. gameLoaded = true
  57. end
  58. if (warp == nil and player ~= nil and player.planet ~= nil) then
  59. print(player.planet.name)
  60. print("===")
  61. end
  62. if (popUps ~= nil and #popUps > 0) then
  63. for i, popUp in ipairs(popUps) do
  64. for j, lineItem in ipairs(popUp) do
  65. print(lineItem)
  66. end
  67. end
  68. print("Press A to close pop up")
  69. end
  70. if (page == nil) then
  71. return
  72. elseif (page.id == "Commodities") then
  73. renderPlanetBuyScreen()
  74. elseif (page.id == "Planets") then
  75. renderPlanetPlanetsScreen()
  76. elseif (page.id == "Services") then
  77. renderPlanetServicesScreen()
  78. elseif (page.id == "Shipyard") then
  79. renderPlanetShipyardScreen()
  80. end
  81. printCursor(page)
  82. io.write("> ")
  83. local inputCommand = io.read()
  84. onButtonPress(inputCommand)
  85. end
  86. repeat
  87. if (warp ~= nil and page == nil) then
  88. continueWarp(false)
  89. else
  90. processInput()
  91. end
  92. until (exitGame)