game.lisp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. (defvar *sector* NIL)
  2. (defun init-game-state ()
  3. (setq *sector*
  4. (make-instance 'sector
  5. :market (make-instance 'market)
  6. :player-ship-obj
  7. (make-instance 'ship
  8. :weapons (list (make-instance 'weapon
  9. :name "Plamsa"
  10. :shield-dmg 3
  11. :hull-dmg 3
  12. :ammo-cost 5)
  13. (make-instance 'weapon
  14. :name "Mega Bolter"
  15. :shield-dmg 1
  16. :hull-dmg 2
  17. :ammo-cost 1)
  18. (make-instance 'weapon
  19. :name "Beam"
  20. :shield-dmg 1
  21. :hull-dmg 3
  22. :ammo-cost 3))
  23. :crew (make-instance 'crew
  24. :sanity-val 100
  25. :moral-val 100
  26. :crew-members
  27. (loop for x in '(1 2 3 4)
  28. collect (make-instance 'uniq-crew-mem :name (make-name *name-prefixes* *name-values*)
  29. :buff (funcall
  30. (lambda ()
  31. (if (= 1 (+ 1(random 5)))
  32. (get-random-buff *buff-types*)
  33. NIL))))))
  34. :inventory (make-instance 'player-inventory
  35. :petrofuel 20
  36. :gruel 20
  37. :spice 0
  38. :ammo 20
  39. :archeotech 0)))))
  40. (defun new-game ()
  41. (init-game-state)
  42. (game-intro)
  43. (top-level-game-menu))
  44. (defun game-intro ()
  45. (cls)
  46. (format t "In the grim darkness of the far future, there is only COMMERCE...~%")
  47. (sleep 2)
  48. (format t "You embark across a bleak galaxy to ply your wares and discover untold riches!~%")
  49. (sleep 2)
  50. (format t *intro-ship*)
  51. (prompt-read ""))
  52. ;; Options for top level menu
  53. ;; This is the main "gameplay" interface
  54. (defvar *top-level-options-display* "
  55. Actions:
  56. 1 | Sector info | sei
  57. 2 | Ship info | si
  58. 3 | Trade | t
  59. 4 | Scout | s
  60. 5 | Leave sector | l
  61. ")
  62. ;; Use lookup table to handle top level loop arguments
  63. ;; See: https://dnaeon.github.io/common-lisp-lookup-tables-alists-and-plists/
  64. (defparameter *top-level-opt-lookup* (list (cons 'sector-info 'sector-info)
  65. (cons '1 'sector-info)
  66. (cons '2 (lambda ()
  67. (ship-info (player-ship-obj *sector*))))
  68. (cons '3 (lambda ()
  69. (trade-menu *sector*)))
  70. (cons '4 'scout)
  71. (cons '5 'leave)))
  72. (defun top-level-game-menu ()
  73. (format t *top-level-options-display*)
  74. (let ((option (prompt-read "Enter an option: ")))
  75. (format t "~%")
  76. (handle-opt (read-from-string option) *top-level-opt-lookup*))
  77. (top-level-game-menu))