game.lisp 2.6 KB

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