A code base (no slides) presentation on lisp flavored erlang for http://www.meetup.com/Arch-Lisp/

game.lfe 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. (defmodule game
  2. (export all))
  3. ;; Creates:
  4. ;; make-exit
  5. ;; exit-direction
  6. ;; exit-object
  7. ;; exit-destination
  8. ;; set-exit
  9. ;; set-exit-direction
  10. ;; set-exit-object
  11. ;; set-exit-destination
  12. ;; match-exit
  13. ;; ...
  14. (defrecord exit
  15. direction
  16. object
  17. destination)
  18. (defrecord place
  19. name
  20. description
  21. exits)
  22. (defrecord object
  23. name
  24. location)
  25. (defrecord goal
  26. name
  27. achieved?)
  28. (defrecord state
  29. objects
  30. places
  31. player-location
  32. goals)
  33. (set objects
  34. (list (make-object name 'whiskey-bottle location 'living-room)
  35. (make-object name 'bucket location 'living-room)
  36. (make-object name 'frog location 'garden)
  37. (make-object name 'chain location 'garden)))
  38. (set living-room
  39. (make-place
  40. name 'living-room
  41. description (++ "You are in the living-room of a wizard's house. "
  42. "There is a wizard snoring loudly on the couch.")
  43. exits (list
  44. (make-exit
  45. direction "west"
  46. object "door"
  47. destination 'garden)
  48. (make-exit
  49. direction "upstairs"
  50. object "stairway"
  51. destination 'attic))))
  52. (set garden
  53. (make-place
  54. name 'garden
  55. description (++ "You are in a beautiful garden. "
  56. "There is a well in front of you.")
  57. exits (list
  58. (make-exit
  59. direction "east"
  60. object "door"
  61. destination 'living-room))))
  62. (set attic
  63. (make-place
  64. name 'attic
  65. description (++ "You are in the attic of the wizard's house. "
  66. "There is a giant welding torch in the corner.")
  67. exits (list
  68. (make-exit
  69. direction "downstairs"
  70. object "stairway"
  71. destination 'living-room))))
  72. (set netherworld
  73. (make-place
  74. name 'netherworld
  75. description (++ "Everything is misty and vague. "
  76. "You seem to be in the netherworld.\n"
  77. "There are no exits.\n"
  78. "You could be here for a long, long time ...")
  79. exits '()))
  80. (set goals
  81. (list (make-goal name 'weld-chain achieved? 'false)
  82. (make-goal name 'dunk-bucket achieved? 'false)
  83. (make-goal name 'splash-wizard achieved? 'false)))
  84. (set state (make-state
  85. objects objects
  86. places (list living-room garden attic netherworld)
  87. player-location 'living-room
  88. goals goals))
  89. (defun here?
  90. ((loc (match-place name place-name)) (when (== loc place-name))
  91. 'true)
  92. ((_ _)
  93. 'false))
  94. (defun get-here
  95. (((match-state player-location player-loc places locs))
  96. (car (lists:filter
  97. (lambda (loc)
  98. (here? player-loc loc))
  99. locs))))
  100. (defun describe-location (game-state)
  101. (++ (place-description (get-here game-state)) "\n"))
  102. (defun describe-exit
  103. (((match-exit object obj direction dir))
  104. (++ "There is a " obj " going " dir " from here.")))
  105. (defun describe-exits (game-state)
  106. (string:join
  107. (lists:map
  108. #'describe-exit/1
  109. (place-exits (get-here game-state)))
  110. " "))