diff options
| author | Mark Oteiza | 2017-01-17 22:05:48 -0500 |
|---|---|---|
| committer | Mark Oteiza | 2017-02-19 08:25:41 -0500 |
| commit | 44931dafa95ed0e00a639168712fbabeb35569f4 (patch) | |
| tree | ad8e35d2a96174a6f85cb996d001a9f261daf6e5 | |
| parent | 48cb4a96f3f3c9195d0e1286a0325e7625f13e39 (diff) | |
| download | emacs-44931dafa95ed0e00a639168712fbabeb35569f4.tar.gz emacs-44931dafa95ed0e00a639168712fbabeb35569f4.zip | |
Replace movement variables with an alist and accessor
* lisp/play/dunnet.el (north, south, east, west, northeast, southeast):
(northwest, southwest, up, down, in, out): Remove.
(dun-movement-alist): New constant.
(dun-movement): New function.
(dun-n, dun-s, dun-e, dun-w, dun-ne, dun-se, dun-nw, dun-sw, dun-up):
(dun-down, dun-in, dun-out): Use a symbol for indicating movement.
(dun-move, dun-special-move): Translate movement symbol to an
enumeration.
| -rw-r--r-- | lisp/play/dunnet.el | 66 |
1 files changed, 38 insertions, 28 deletions
diff --git a/lisp/play/dunnet.el b/lisp/play/dunnet.el index b6392c12e7c..95a9e9ce7d0 100644 --- a/lisp/play/dunnet.el +++ b/lisp/play/dunnet.el | |||
| @@ -644,18 +644,20 @@ A hole leads north." | |||
| 644 | (defvar dun-mode 'moby) | 644 | (defvar dun-mode 'moby) |
| 645 | (defvar dun-sauna-level 0) | 645 | (defvar dun-sauna-level 0) |
| 646 | 646 | ||
| 647 | (defconst north 0) | 647 | (defconst dun-movement-alist |
| 648 | (defconst south 1) | 648 | '((north . 0) |
| 649 | (defconst east 2) | 649 | (south . 1) |
| 650 | (defconst west 3) | 650 | (east . 2) |
| 651 | (defconst northeast 4) | 651 | (west . 3) |
| 652 | (defconst southeast 5) | 652 | (northeast . 4) |
| 653 | (defconst northwest 6) | 653 | (southeast . 5) |
| 654 | (defconst southwest 7) | 654 | (northwest . 6) |
| 655 | (defconst up 8) | 655 | (southwest . 7) |
| 656 | (defconst down 9) | 656 | (up . 8) |
| 657 | (defconst in 10) | 657 | (down . 9) |
| 658 | (defconst out 11) | 658 | (in . 10) |
| 659 | (out . 11)) | ||
| 660 | "Alist enumerating movement directions.") | ||
| 659 | 661 | ||
| 660 | (defconst dungeon-map | 662 | (defconst dungeon-map |
| 661 | ;; no so ea we ne se nw sw up do in ot | 663 | ;; no so ea we ne se nw sw up do in ot |
| @@ -1645,41 +1647,45 @@ just try dropping it.") | |||
| 1645 | 1647 | ||
| 1646 | ;;; Various movement directions | 1648 | ;;; Various movement directions |
| 1647 | 1649 | ||
| 1650 | (defun dun-movement (dir) | ||
| 1651 | "Return enumeral of movement symbol DIR." | ||
| 1652 | (cdr (assq dir dun-movement-alist))) | ||
| 1653 | |||
| 1648 | (defun dun-n (_args) | 1654 | (defun dun-n (_args) |
| 1649 | (dun-move north)) | 1655 | (dun-move 'north)) |
| 1650 | 1656 | ||
| 1651 | (defun dun-s (_args) | 1657 | (defun dun-s (_args) |
| 1652 | (dun-move south)) | 1658 | (dun-move 'south)) |
| 1653 | 1659 | ||
| 1654 | (defun dun-e (_args) | 1660 | (defun dun-e (_args) |
| 1655 | (dun-move east)) | 1661 | (dun-move 'east)) |
| 1656 | 1662 | ||
| 1657 | (defun dun-w (_args) | 1663 | (defun dun-w (_args) |
| 1658 | (dun-move west)) | 1664 | (dun-move 'west)) |
| 1659 | 1665 | ||
| 1660 | (defun dun-ne (_args) | 1666 | (defun dun-ne (_args) |
| 1661 | (dun-move northeast)) | 1667 | (dun-move 'northeast)) |
| 1662 | 1668 | ||
| 1663 | (defun dun-se (_args) | 1669 | (defun dun-se (_args) |
| 1664 | (dun-move southeast)) | 1670 | (dun-move 'southeast)) |
| 1665 | 1671 | ||
| 1666 | (defun dun-nw (_args) | 1672 | (defun dun-nw (_args) |
| 1667 | (dun-move northwest)) | 1673 | (dun-move 'northwest)) |
| 1668 | 1674 | ||
| 1669 | (defun dun-sw (_args) | 1675 | (defun dun-sw (_args) |
| 1670 | (dun-move southwest)) | 1676 | (dun-move 'southwest)) |
| 1671 | 1677 | ||
| 1672 | (defun dun-up (_args) | 1678 | (defun dun-up (_args) |
| 1673 | (dun-move up)) | 1679 | (dun-move 'up)) |
| 1674 | 1680 | ||
| 1675 | (defun dun-down (_args) | 1681 | (defun dun-down (_args) |
| 1676 | (dun-move down)) | 1682 | (dun-move 'down)) |
| 1677 | 1683 | ||
| 1678 | (defun dun-in (_args) | 1684 | (defun dun-in (_args) |
| 1679 | (dun-move in)) | 1685 | (dun-move 'in)) |
| 1680 | 1686 | ||
| 1681 | (defun dun-out (_args) | 1687 | (defun dun-out (_args) |
| 1682 | (dun-move out)) | 1688 | (dun-move 'out)) |
| 1683 | 1689 | ||
| 1684 | (defun dun-go (args) | 1690 | (defun dun-go (args) |
| 1685 | (if (or (not (car args)) | 1691 | (if (or (not (car args)) |
| @@ -1701,6 +1707,7 @@ just try dropping it.") | |||
| 1701 | "You trip over a grue and fall into a pit and break every bone in your | 1707 | "You trip over a grue and fall into a pit and break every bone in your |
| 1702 | body.") | 1708 | body.") |
| 1703 | (dun-die "a grue")) | 1709 | (dun-die "a grue")) |
| 1710 | (setq dir (dun-movement dir)) | ||
| 1704 | (let (newroom) | 1711 | (let (newroom) |
| 1705 | (setq newroom (nth dir (nth dun-current-room dungeon-map))) | 1712 | (setq newroom (nth dir (nth dun-current-room dungeon-map))) |
| 1706 | (if (eq newroom -1) | 1713 | (if (eq newroom -1) |
| @@ -1776,12 +1783,14 @@ force throws you out. The train speeds away.\n") | |||
| 1776 | (setq dun-current-room meadow) | 1783 | (setq dun-current-room meadow) |
| 1777 | (dun-mprincl "You don't have a key that can open this door."))) | 1784 | (dun-mprincl "You don't have a key that can open this door."))) |
| 1778 | 1785 | ||
| 1779 | (if (and (= dun-current-room maze-button-room) (= dir northwest)) | 1786 | (if (and (= dun-current-room maze-button-room) |
| 1787 | (= dir (dun-movement 'northwest))) | ||
| 1780 | (if (member obj-weight (nth maze-button-room dun-room-objects)) | 1788 | (if (member obj-weight (nth maze-button-room dun-room-objects)) |
| 1781 | (setq dun-current-room 18) | 1789 | (setq dun-current-room 18) |
| 1782 | (dun-mprincl "You can't go that way."))) | 1790 | (dun-mprincl "You can't go that way."))) |
| 1783 | 1791 | ||
| 1784 | (if (and (= dun-current-room maze-button-room) (= dir up)) | 1792 | (if (and (= dun-current-room maze-button-room) |
| 1793 | (= dir (dun-movement 'up))) | ||
| 1785 | (if (member obj-weight (nth maze-button-room dun-room-objects)) | 1794 | (if (member obj-weight (nth maze-button-room dun-room-objects)) |
| 1786 | (dun-mprincl "You can't go that way.") | 1795 | (dun-mprincl "You can't go that way.") |
| 1787 | (setq dun-current-room weight-room))) | 1796 | (setq dun-current-room weight-room))) |
| @@ -1807,11 +1816,12 @@ engulf you, and you burn to death.") | |||
| 1807 | (setq dun-current-room long-n-s-hallway) | 1816 | (setq dun-current-room long-n-s-hallway) |
| 1808 | (dun-mprincl "You can't go that way."))) | 1817 | (dun-mprincl "You can't go that way."))) |
| 1809 | 1818 | ||
| 1810 | (if (and (> dir down) (> dun-current-room gamma-computing-center) | 1819 | (if (and (> dir (dun-movement 'down)) |
| 1820 | (> dun-current-room gamma-computing-center) | ||
| 1811 | (< dun-current-room museum-lobby)) | 1821 | (< dun-current-room museum-lobby)) |
| 1812 | (if (not (member obj-bus (nth dun-current-room dun-room-objects))) | 1822 | (if (not (member obj-bus (nth dun-current-room dun-room-objects))) |
| 1813 | (dun-mprincl "You can't go that way.") | 1823 | (dun-mprincl "You can't go that way.") |
| 1814 | (if (= dir in) | 1824 | (if (= dir (dun-movement 'in)) |
| 1815 | (if dun-inbus | 1825 | (if dun-inbus |
| 1816 | (dun-mprincl | 1826 | (dun-mprincl |
| 1817 | "You are already in the bus!") | 1827 | "You are already in the bus!") |