summaryrefslogtreecommitdiff
path: root/lisp/play
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/play')
-rw-r--r--lisp/play/animate.el10
-rw-r--r--lisp/play/fortune.el13
-rw-r--r--lisp/play/snake.el23
3 files changed, 34 insertions, 12 deletions
diff --git a/lisp/play/animate.el b/lisp/play/animate.el
index fb01fccea8b..d074a741b69 100644
--- a/lisp/play/animate.el
+++ b/lisp/play/animate.el
@@ -44,6 +44,11 @@
;;; in the string when the whole string finally reaches its
;;; specified position.
+(defgroup animate nil
+ "Make text dance."
+ :group 'games
+ :prefix "animate-")
+
(defun animate-initialize (string vpos hpos)
(let ((characters nil))
(dotimes (i (length string))
@@ -88,8 +93,9 @@
(unless (eolp) (delete-char 1))
(insert-char char 1))
-(defvar animate-n-steps 10
-"*Number of steps `animate-string' will place a char before its last position.")
+(defcustom animate-n-steps 10
+ "Number of steps `animate-string' will place a char before its last position."
+ :type 'integer)
(defvar animation-buffer-name nil
"String naming the default buffer for animations.
diff --git a/lisp/play/fortune.el b/lisp/play/fortune.el
index 361e8ee8acc..7b60465788a 100644
--- a/lisp/play/fortune.el
+++ b/lisp/play/fortune.el
@@ -303,6 +303,19 @@ specifies the file to choose the fortune from."
fortune-program-options) (list fort-file)))))))
;;;###autoload
+(defun fortune-message (&optional file)
+ "Display a fortune cookie to the mini-buffer.
+If called with a prefix, it has the same behavior as `fortune'.
+Optional FILE is a fortune file from which a cookie will be selected."
+ (interactive (list (if current-prefix-arg
+ (fortune-ask-file)
+ fortune-file)))
+ (with-temp-buffer
+ (let ((fortune-buffer-name (current-buffer)))
+ (fortune-in-buffer t file)
+ (message "%s" (buffer-string)))))
+
+;;;###autoload
(defun fortune (&optional file)
"Display a fortune cookie.
If called with a prefix asks for the FILE to choose the fortune from,
diff --git a/lisp/play/snake.el b/lisp/play/snake.el
index 4b0b4a4e469..d5904a48f42 100644
--- a/lisp/play/snake.el
+++ b/lisp/play/snake.el
@@ -144,7 +144,6 @@
(defvar snake-velocity-x 1)
(defvar snake-velocity-y 0)
(defvar snake-positions nil)
-(defvar snake-cycle 0)
(defvar snake-score 0)
(defvar snake-paused nil)
(defvar snake-moved-p nil)
@@ -164,7 +163,6 @@ and then start moving it leftwards.")
(make-variable-buffer-local 'snake-velocity-x)
(make-variable-buffer-local 'snake-velocity-y)
(make-variable-buffer-local 'snake-positions)
-(make-variable-buffer-local 'snake-cycle)
(make-variable-buffer-local 'snake-score)
(make-variable-buffer-local 'snake-paused)
(make-variable-buffer-local 'snake-moved-p)
@@ -237,7 +235,6 @@ and then start moving it leftwards.")
snake-velocity-x snake-initial-velocity-x
snake-velocity-y snake-initial-velocity-y
snake-positions nil
- snake-cycle 1
snake-score 0
snake-paused nil
snake-moved-p nil
@@ -251,6 +248,14 @@ and then start moving it leftwards.")
(cl-incf y snake-velocity-y)))
(snake-update-score))
+(defun snake-set-dot ()
+ (let ((x (random snake-width))
+ (y (random snake-height)))
+ (while (not (= (gamegrid-get-cell x y) snake-blank))
+ (setq x (random snake-width))
+ (setq y (random snake-height)))
+ (gamegrid-set-cell x y snake-dot)))
+
(defun snake-update-game (snake-buffer)
"Called on each clock tick.
Advances the snake one square, testing for collision.
@@ -268,23 +273,20 @@ Argument SNAKE-BUFFER is the name of the buffer."
(cond ((= c snake-dot)
(cl-incf snake-length)
(cl-incf snake-score)
- (snake-update-score))
+ (snake-update-score)
+ (snake-set-dot))
(t
(let* ((last-cons (nthcdr (- snake-length 2)
snake-positions))
(tail-pos (cadr last-cons))
(x0 (aref tail-pos 0))
(y0 (aref tail-pos 1)))
- (gamegrid-set-cell x0 y0
- (if (= (% snake-cycle 5) 0)
- snake-dot
- snake-blank))
- (cl-incf snake-cycle)
+ (gamegrid-set-cell x0 y0 snake-blank)
(setcdr last-cons nil))))
(gamegrid-set-cell x y snake-snake)
(setq snake-positions
(cons (vector x y) snake-positions))
- (setq snake-moved-p nil)))))
+ (setq snake-moved-p nil)))))
(defun snake-update-velocity ()
(unless snake-moved-p
@@ -339,6 +341,7 @@ Argument SNAKE-BUFFER is the name of the buffer."
"Start a new game of Snake."
(interactive)
(snake-reset-game)
+ (snake-set-dot)
(use-local-map snake-mode-map)
(gamegrid-start-timer snake-tick-period 'snake-update-game))