* bug#6749: Snake.el enhancements
@ 2010-07-28 14:48 Stuart Hacking
2012-04-12 19:09 ` Lars Magne Ingebrigtsen
0 siblings, 1 reply; 4+ messages in thread
From: Stuart Hacking @ 2010-07-28 14:48 UTC (permalink / raw)
To: 6749
[-- Attachment #1.1: Type: text/plain, Size: 381 bytes --]
Package: emacs
Severity: wishlist
Tags: patch
I have made the following small enhancements to snake.el:
- Primarily, that apples are now, by default, placed at random in the game
grid. The original behaviour can be restored by toggling a customization
variable.
- Some other variables are now customizable
- Added some extra doc strings to keep Checkdoc happy.
Regards,
--smh
[-- Attachment #1.2: Type: text/html, Size: 995 bytes --]
[-- Attachment #2: snake_randomize.el.diff --]
[-- Type: application/octet-stream, Size: 5352 bytes --]
--- C:\Dev\emacs-23.1\lisp\play\snake.el 2009-06-21 12:38:02.000000000 +0100
+++ C:\emacs-23.1\lisp\play\snake.el 2010-07-28 14:20:00.852191800 +0100
@@ -1,7 +1,7 @@
;;; snake.el --- implementation of Snake for Emacs
;; Copyright (C) 1997, 2001, 2002, 2003, 2004, 2005,
-;; 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
+;; 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
;; Author: Glynn Clements <glynn@sensei.co.uk>
;; Created: 1997-09-10
@@ -32,6 +32,34 @@
(require 'gamegrid)
;; ;;;;;;;;;;;;; customization variables ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+(defgroup snake nil
+ "Classic game of Snake (or Nibbles)."
+ :prefix "snake-"
+ :group 'games)
+
+(defcustom snake-buffer-name "*Snake*"
+ "Name used for Snake buffer."
+ :group 'snake :type 'string)
+
+(defcustom snake-initial-length 5
+ "Initial length of snake."
+ :group 'snake :type 'integer)
+
+(defcustom snake-spawn-rate 5
+ "Rate at which new apples will be desposited."
+ :group 'snake :type 'integer)
+
+(defcustom snake-score-file "snake-scores"
+ "File for holding high scores.
+It is not safe to put this in /tmp.
+Someone could make a symlink in /tmp
+pointing to a file you don't want to clobber."
+ :group 'snake :type 'file)
+
+(defcustom snake-randomize-apples t
+ "If non-nil, apples will be deposited at random.
+If nil, then apples will be dropped behind the snake."
+ :group 'snake :type 'boolean)
(defvar snake-use-glyphs-flag t
"Non-nil means use glyphs when available.")
@@ -39,9 +67,6 @@
(defvar snake-use-color-flag t
"Non-nil means use color when available.")
-(defvar snake-buffer-name "*Snake*"
- "Name used for Snake buffer.")
-
(defvar snake-buffer-width 30
"Width of used portion of buffer.")
@@ -54,9 +79,6 @@
(defvar snake-height 20
"Height of playing area.")
-(defvar snake-initial-length 5
- "Initial length of snake.")
-
(defvar snake-initial-x 10
"Initial X position of snake.")
@@ -81,12 +103,6 @@
(defvar snake-score-y snake-height
"Y position of score.")
-;; It is not safe to put this in /tmp.
-;; Someone could make a symlink in /tmp
-;; pointing to a file you don't want to clobber.
-(defvar snake-score-file "snake-scores"
- "File for holding high scores.")
-
;; ;;;;;;;;;;;;; display options ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defvar snake-blank-options
@@ -194,6 +210,7 @@
;; ;;;;;;;;;;;;;;;; game functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun snake-display-options ()
+ "Set snake buffer display options."
(let ((options (make-vector 256 nil)))
(loop for c from 0 to 255 do
(aset options c
@@ -212,6 +229,7 @@
options))
(defun snake-update-score ()
+ "Update the score string."
(let* ((string (format "Score: %05d" snake-score))
(len (length string)))
(loop for x from 0 to (1- len) do
@@ -220,6 +238,7 @@
(aref string x)))))
(defun snake-init-buffer ()
+ "Initialize snake buffer."
(gamegrid-init-buffer snake-buffer-width
snake-buffer-height
snake-space)
@@ -232,6 +251,7 @@
(gamegrid-set-cell x y snake-blank)))))
(defun snake-reset-game ()
+ "Reset snake game."
(gamegrid-kill-timer)
(snake-init-buffer)
(setq snake-length snake-initial-length
@@ -276,10 +296,12 @@
(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))
+ (gamegrid-set-cell x0 y0 snake-blank)
+ (if (= (% snake-cycle snake-spawn-rate) 0)
+ ; Maintain existing behaviour as customizable variable.
+ (if snake-randomize-apples
+ (snake-put-apple)
+ (gamegrid-set-cell x0 y0 snake-dot)))
(incf snake-cycle)
(setcdr last-cons nil))))
(gamegrid-set-cell x y snake-snake)
@@ -287,7 +309,15 @@
(cons (vector x y) snake-positions))
(setq snake-moved-p nil)))))
+(defun snake-put-apple ()
+ "Deposit an apple at a random location."
+ (let ((x (1+ (random (- snake-width 2))))
+ (y (1+ (random (- snake-height 2)))))
+ (if (= (gamegrid-get-cell x y) snake-blank)
+ (gamegrid-set-cell x y snake-dot))))
+
(defun snake-update-velocity ()
+ "Update the snake's velocity."
(unless snake-moved-p
(if snake-velocity-queue
(let ((new-vel (car (last snake-velocity-queue))))
@@ -350,6 +380,7 @@
(message (and snake-paused "Game paused (press p to resume)")))
(defun snake-active-p ()
+ "Is snake the active mode check."
(eq (current-local-map) snake-mode-map))
(put 'snake-mode 'mode-class 'special)
@@ -358,8 +389,7 @@
"A mode for playing Snake.
Snake mode keybindings:
- \\{snake-mode-map}
-"
+ \\{snake-mode-map}"
(kill-all-local-variables)
(add-hook 'kill-buffer-hook 'gamegrid-kill-timer nil t)
^ permalink raw reply [flat|nested] 4+ messages in thread
* bug#6749: Snake.el enhancements
2010-07-28 14:48 bug#6749: Snake.el enhancements Stuart Hacking
@ 2012-04-12 19:09 ` Lars Magne Ingebrigtsen
2012-04-17 14:06 ` Stuart Hacking
0 siblings, 1 reply; 4+ messages in thread
From: Lars Magne Ingebrigtsen @ 2012-04-12 19:09 UTC (permalink / raw)
To: Stuart Hacking; +Cc: 6749
Stuart Hacking <stuhacking@gmail.com> writes:
> I have made the following small enhancements to snake.el:
>
> - Primarily, that apples are now, by default, placed at random in the
> game grid. The original behaviour can be restored by toggling a
> customization variable.
>
> - Some other variables are now customizable
>
> - Added some extra doc strings to keep Checkdoc happy.
Looks good.
This is a rather large patch, so the FSF needs copyright assignment
papers before installing. If you haven't already, would you be willing
to sign such paperwork?
---------
Please email the following information to assign@gnu.org, and we
will send you the assignment form for your past and future changes.
Please use your full legal name (in ASCII characters) as the subject
line of the message.
----------------------------------------------------------------------
REQUEST: SEND FORM FOR PAST AND FUTURE CHANGES
[What is the name of the program or package you're contributing to?]
Emacs
[Did you copy any files or text written by someone else in these changes?
Even if that material is free software, we need to know about it.]
[Do you have an employer who might have a basis to claim to own
your changes? Do you attend a school which might make such a claim?]
[For the copyright registration, what country are you a citizen of?]
[What year were you born?]
[Please write your email address here.]
[Please write your postal address here.]
[Which files have you changed so far, and which new files have you written
so far?]
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog http://lars.ingebrigtsen.no/
^ permalink raw reply [flat|nested] 4+ messages in thread
* bug#6749: Snake.el enhancements
2012-04-12 19:09 ` Lars Magne Ingebrigtsen
@ 2012-04-17 14:06 ` Stuart Hacking
2016-02-23 9:24 ` Lars Ingebrigtsen
0 siblings, 1 reply; 4+ messages in thread
From: Stuart Hacking @ 2012-04-17 14:06 UTC (permalink / raw)
To: Lars Magne Ingebrigtsen; +Cc: 6749
[-- Attachment #1: Type: text/plain, Size: 387 bytes --]
On 12 April 2012 20:09, Lars Magne Ingebrigtsen <larsi@gnus.org> wrote:
> [snip...]
> This is a rather large patch, so the FSF needs copyright assignment
> papers before installing. If you haven't already, would you be willing
> to sign such paperwork?
>
>
Oh, for sure. I'll send that request now. To be honest this had slipped
from my
mind, surprised to hear about it again. :-)
S.
[-- Attachment #2: Type: text/html, Size: 706 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* bug#6749: Snake.el enhancements
2012-04-17 14:06 ` Stuart Hacking
@ 2016-02-23 9:24 ` Lars Ingebrigtsen
0 siblings, 0 replies; 4+ messages in thread
From: Lars Ingebrigtsen @ 2016-02-23 9:24 UTC (permalink / raw)
To: Stuart Hacking; +Cc: 6749
Stuart Hacking <stuhacking@gmail.com> writes:
> Oh, for sure. I'll send that request now. To be honest this had slipped from my
> mind, surprised to hear about it again. :-)
It doesn't look like the paperwork arrived or something, and meanwhile
somebody else seems to have fixed this in a different way, so I'm
closing this bug report.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-02-23 9:24 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-28 14:48 bug#6749: Snake.el enhancements Stuart Hacking
2012-04-12 19:09 ` Lars Magne Ingebrigtsen
2012-04-17 14:06 ` Stuart Hacking
2016-02-23 9:24 ` Lars Ingebrigtsen
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.