game.lisp 2.5 KB

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