Mercurial > emacs
view lisp/play/snake.el @ 92870:8f17f65dd575
* textmodes/org.el (org-ctrl-c-star): Implement a missing branch
in the decision tree.
(org-select-remember-template): Cleaned the code.
(org-prepare-dblock): Added the extra :content parameter.
(org-write-agenda): New output type ".ics" files.
(org-write-agenda): Call `org-icalendar-verify-function', both for
time stamps and for TODO entries.
(org-agenda-collect-markers, org-create-marker-find-array)
(org-check-agenda-marker-table): New functions.
(org-agenda-marker-table): New variable.
(org-export-as-html): Revert the change that killed the html
buffer. Side effects first need to be studied carefully.
(org-get-tags-at): Fix the structure of the condition-case
statement.
(org-ts-regexp0, org-repeat-re, org-display-custom-time)
(org-timestamp-change): Fix regulear expressions to swallow the
extra character for repeat-shift control.
(org-auto-repeat-maybe): Implement the new repeater mechanisms.
(org-get-legal-level): Aliased to `org-get-valid-level'.
(org-dblock-write:clocktable): Added a :link parameter, linking
headlines to their location in the Org agenda files.
(org-get-tags-at): Bugfix: prevent `org-back-to-heading' from
throwing an error when getting tags before headlines.
(org-timestamp-change, org-modify-ts-extra)
(org-ts-regexp1): Fix timestamp editing.
(org-agenda-custom-commands-local-options): New constant.
(org-agenda-custom-commands): Use
`org-agenda-custom-commands-local-options' to improve customize
type. "htmlize": Removed hack to fix face problem with htmlize,
it no longer seem necessary.
(org-follow-link-hook): New hook.
(org-agenda-custom-commands): Added "Component" as a tag for each
item in a command serie.
(org-open-at-point): Run `org-follow-link-hook'.
(org-agenda-schedule): Bugfix: don't display marker type when it
is `nil'.
(org-store-link): org-irc required.
(org-set-regexps-and-options): Parse the new logging options.
(org-extract-log-state-settings): New function.
(org-todo): Handle the new ways of recording state change stuff.
(org-local-logging): New function.
(org-columns-open-link): Fixed bug with opening link in column
view.
(org-local-logging): New function
(org-todo): Make sure that LOGGING properties are honoured.
(org-todo-keywords): Improve docstring.
(org-startup-options): Cleanup startup options.
(org-set-regexps-and-options): Process the "!" markers.
(org-todo): Respect the new logging stuff.
(org-log-note-how): New variable.
(org-add-log-maybe): New parameter HOW that defines how logging
should be done and also overrides PURPOSE. Add a docstring.
(org-add-log-note): Check if we really need to ask for a note.
(org-get-current-options): Digest the new keyword.
(org-agenda-reset-markers): Renamed from
`org-agenda-maybe-reset-markers'. FORCE argument removed.
(org-diary, org-agenda-quit, org-prepare-agenda): Call the renamed
function, without force argument.
(org-buffer-property-keys): Bind local variables s and p.
(org-make-tags-matcher): Allow "" to match an empty or
non-existent property value.
(org-export-as-html): Join unsorted lists when they directly
follow each other. Such lists may be created by headlines that
are converted to lists.
(org-nofm-to-completion): New function.
(org-export-as-html): Use :html-extension instead of
org-export-html-extension.
(org-store-link): Support for links from `rmail-summary-mode'.
(org-columns-new, org-complete, org-set-property): Set the
`include-columns' argument in the call to
`org-buffer-property-keys'.
(org-buffer-property-keys): New argument `include-columns', to
include properties expected by any of the COLUMS formats in the
current buffer.
(org-cleaned-string-for-export): Get rid of drawers first, so that
they will be removed also in the text before the first headline.
(org-clock-report): Show the clocktable when found.
(org-refile): Fix positioning bug when `org-reverse-note-order' is
nil.
(org-version): With prefix argument, insert `org-version' at
point.
(org-agenda-goto): Recenter the window after finding the target
location, to make sure the correct position will be displayed.
(org-agenda-get-deadlines): Don't scale priority with the warning
period.
(org-insert-heading): Don't break line in the middle of the line.
(org-agenda-get-deadlines): Allow `org-deadline-warning-days' to
be 0.
(org-update-checkbox-count): Revamped to deal with hierarchical
beckboxes. This was a patch from Miguel A. Figueroa-Villanueva.
(org-remove-timestamp-with-keyword): New function.
(org-schedule, org-deadline): Use
`org-remove-timestamp-with-keyword' to make sure all such time
stamps are removed.
(org-mode): Support for `align'.
(org-agenda-get-deadlines): Make sure priorities increase as the
due date approaches and is passed.
(org-remember-apply-template): Fixed problem with tags that
contain "_" or "@".
(org-make-link-regexps): Improve the regular expression for plain
links.
(org-agenda-get-closed): List each clocking entry.
(org-set-tags): Only tabify before tags if indent-tabs-mode is t.
(org-special-ctrl-k): New option.
(org-kill-line): New function.
(org-archive-all-done): Fixed incorrect number of stars in regexp.
(org-refile-get-location): New function.
(org-refile-goto-last-stored): New function.
(org-global-tags-completion-table): Add the value of org-tag-alist
in each buffer, to make sure that also unused tags will be
available for completion.
(org-columns-edit-value)
(org-columns-next-allowed-value): Only update if not in agenda.
(org-clocktable-steps): New function.
(org-dblock-write:clocktable): Call `org-clocktable-steps'.
(org-archive-subtree): Add the outline tree context as a property.
(org-closest-date): New optional argument `prefer'.
(org-goto-auto-isearch): New option.
(org-goto-map, org-get-location): Implement auto-isearch.
(org-goto-local-auto-isearch-map): New variable.
(org-goto-local-search-forward-headings)
(org-goto-local-auto-isearch): New functions
author | Carsten Dominik <dominik@science.uva.nl> |
---|---|
date | Thu, 13 Mar 2008 08:54:11 +0000 |
parents | 54006a859bcc |
children | 606f2d163a64 1e3a407766b9 |
line wrap: on
line source
;;; snake.el --- implementation of Snake for Emacs ;; Copyright (C) 1997, 2001, 2002, 2003, 2004, 2005, ;; 2006, 2007, 2008 Free Software Foundation, Inc. ;; Author: Glynn Clements <glynn@sensei.co.uk> ;; Created: 1997-09-10 ;; Keywords: games ;; This file is part of GNU Emacs. ;; GNU Emacs is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation; either version 3, or (at your option) ;; any later version. ;; GNU Emacs is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs; see the file COPYING. If not, write to the ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, ;; Boston, MA 02110-1301, USA. ;;; Commentary: ;;; Code: (eval-when-compile (require 'cl)) (require 'gamegrid) ;; ;;;;;;;;;;;;; customization variables ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defvar snake-use-glyphs-flag t "Non-nil means use glyphs when available.") (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.") (defvar snake-buffer-height 22 "Height of used portion of buffer.") (defvar snake-width 30 "Width of playing area.") (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.") (defvar snake-initial-y 10 "Initial Y position of snake.") (defvar snake-initial-velocity-x 1 "Initial X velocity of snake.") (defvar snake-initial-velocity-y 0 "Initial Y velocity of snake.") (defvar snake-tick-period 0.2 "The default time taken for the snake to advance one square.") (defvar snake-mode-hook nil "Hook run upon starting Snake.") (defvar snake-score-x 0 "X position of score.") (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 '(((glyph colorize) (t ?\040)) ((color-x color-x) (mono-x grid-x) (color-tty color-tty)) (((glyph color-x) [0 0 0]) (color-tty "black")))) (defvar snake-snake-options '(((glyph colorize) (emacs-tty ?O) (t ?\040)) ((color-x color-x) (mono-x mono-x) (color-tty color-tty) (mono-tty mono-tty)) (((glyph color-x) [1 1 0]) (color-tty "yellow")))) (defvar snake-dot-options '(((glyph colorize) (t ?\*)) ((color-x color-x) (mono-x grid-x) (color-tty color-tty)) (((glyph color-x) [1 0 0]) (color-tty "red")))) (defvar snake-border-options '(((glyph colorize) (t ?\+)) ((color-x color-x) (mono-x grid-x) (color-tty color-tty)) (((glyph color-x) [0.5 0.5 0.5]) (color-tty "white")))) (defvar snake-space-options '(((t ?\040)) nil nil)) ;; ;;;;;;;;;;;;; constants ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defconst snake-blank 0) (defconst snake-snake 1) (defconst snake-dot 2) (defconst snake-border 3) (defconst snake-space 4) ;; ;;;;;;;;;;;;; variables ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defvar snake-length 0) (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) (defvar snake-velocity-queue nil "This queue stores the velocities requested too quickly by user. They will take effect one at a time at each clock-interval. This is necessary for proper behavior. For instance, if you are moving right, you press up and then left, you want the snake to move up just once before starting to move left. If we implemented all your keystrokes immediately, the snake would effectively never move up. Thus, we need to move it up for one turn and then start moving it leftwards.") (make-variable-buffer-local 'snake-length) (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) (make-variable-buffer-local 'snake-velocity-queue) ;; ;;;;;;;;;;;;; keymaps ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defvar snake-mode-map (make-sparse-keymap 'snake-mode-map)) (define-key snake-mode-map "n" 'snake-start-game) (define-key snake-mode-map "q" 'snake-end-game) (define-key snake-mode-map "p" 'snake-pause-game) (define-key snake-mode-map [left] 'snake-move-left) (define-key snake-mode-map [right] 'snake-move-right) (define-key snake-mode-map [up] 'snake-move-up) (define-key snake-mode-map [down] 'snake-move-down) (defvar snake-null-map (make-sparse-keymap 'snake-null-map)) (define-key snake-null-map "n" 'snake-start-game) ;; ;;;;;;;;;;;;;;;; game functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun snake-display-options () (let ((options (make-vector 256 nil))) (loop for c from 0 to 255 do (aset options c (cond ((= c snake-blank) snake-blank-options) ((= c snake-snake) snake-snake-options) ((= c snake-dot) snake-dot-options) ((= c snake-border) snake-border-options) ((= c snake-space) snake-space-options) (t '(nil nil nil))))) options)) (defun snake-update-score () (let* ((string (format "Score: %05d" snake-score)) (len (length string))) (loop for x from 0 to (1- len) do (gamegrid-set-cell (+ snake-score-x x) snake-score-y (aref string x))))) (defun snake-init-buffer () (gamegrid-init-buffer snake-buffer-width snake-buffer-height snake-space) (let ((buffer-read-only nil)) (loop for y from 0 to (1- snake-height) do (loop for x from 0 to (1- snake-width) do (gamegrid-set-cell x y snake-border))) (loop for y from 1 to (- snake-height 2) do (loop for x from 1 to (- snake-width 2) do (gamegrid-set-cell x y snake-blank))))) (defun snake-reset-game () (gamegrid-kill-timer) (snake-init-buffer) (setq snake-length snake-initial-length 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 snake-velocity-queue nil) (let ((x snake-initial-x) (y snake-initial-y)) (dotimes (i snake-length) (gamegrid-set-cell x y snake-snake) (setq snake-positions (cons (vector x y) snake-positions)) (incf x snake-velocity-x) (incf y snake-velocity-y))) (snake-update-score)) (defun snake-update-game (snake-buffer) "Called on each clock tick. Advances the snake one square, testing for collision. Argument SNAKE-BUFFER is the name of the buffer." (when (and (not snake-paused) (eq (current-buffer) snake-buffer)) (snake-update-velocity) (let* ((pos (car snake-positions)) (x (+ (aref pos 0) snake-velocity-x)) (y (+ (aref pos 1) snake-velocity-y)) (c (gamegrid-get-cell x y))) (if (or (= c snake-border) (= c snake-snake)) (snake-end-game) (cond ((= c snake-dot) (incf snake-length) (incf snake-score) (snake-update-score)) (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)) (incf snake-cycle) (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))))) (defun snake-update-velocity () (unless snake-moved-p (if snake-velocity-queue (let ((new-vel (car (last snake-velocity-queue)))) (setq snake-velocity-x (car new-vel) snake-velocity-y (cadr new-vel)) (setq snake-velocity-queue (nreverse (cdr (nreverse snake-velocity-queue)))))) (setq snake-moved-p t))) (defun snake-final-x-velocity () (or (caar snake-velocity-queue) snake-velocity-x)) (defun snake-final-y-velocity () (or (cadr (car snake-velocity-queue)) snake-velocity-y)) (defun snake-move-left () "Make the snake move left." (interactive) (when (zerop (snake-final-x-velocity)) (push '(-1 0) snake-velocity-queue))) (defun snake-move-right () "Make the snake move right." (interactive) (when (zerop (snake-final-x-velocity)) (push '(1 0) snake-velocity-queue))) (defun snake-move-up () "Make the snake move up." (interactive) (when (zerop (snake-final-y-velocity)) (push '(0 -1) snake-velocity-queue))) (defun snake-move-down () "Make the snake move down." (interactive) (when (zerop (snake-final-y-velocity)) (push '(0 1) snake-velocity-queue))) (defun snake-end-game () "Terminate the current game." (interactive) (gamegrid-kill-timer) (use-local-map snake-null-map) (gamegrid-add-score snake-score-file snake-score)) (defun snake-start-game () "Start a new game of Snake." (interactive) (snake-reset-game) (use-local-map snake-mode-map) (gamegrid-start-timer snake-tick-period 'snake-update-game)) (defun snake-pause-game () "Pause (or resume) the current game." (interactive) (setq snake-paused (not snake-paused)) (message (and snake-paused "Game paused (press p to resume)"))) (defun snake-active-p () (eq (current-local-map) snake-mode-map)) (put 'snake-mode 'mode-class 'special) (defun snake-mode () "A mode for playing Snake. Snake mode keybindings: \\{snake-mode-map} " (kill-all-local-variables) (add-hook 'kill-buffer-hook 'gamegrid-kill-timer nil t) (use-local-map snake-null-map) (setq major-mode 'snake-mode) (setq mode-name "Snake") (unless (featurep 'emacs) (setq mode-popup-menu '("Snake Commands" ["Start new game" snake-start-game] ["End game" snake-end-game (snake-active-p)] ["Pause" snake-pause-game (and (snake-active-p) (not snake-paused))] ["Resume" snake-pause-game (and (snake-active-p) snake-paused)]))) (setq gamegrid-use-glyphs snake-use-glyphs-flag) (setq gamegrid-use-color snake-use-color-flag) (gamegrid-init (snake-display-options)) (run-mode-hooks 'snake-mode-hook)) ;;;###autoload (defun snake () "Play the Snake game. Move the snake around without colliding with its tail or with the border. Eating dots causes the snake to get longer. Snake mode keybindings: \\<snake-mode-map> \\[snake-start-game] Starts a new game of Snake \\[snake-end-game] Terminates the current game \\[snake-pause-game] Pauses (or resumes) the current game \\[snake-move-left] Makes the snake move left \\[snake-move-right] Makes the snake move right \\[snake-move-up] Makes the snake move up \\[snake-move-down] Makes the snake move down" (interactive) (switch-to-buffer snake-buffer-name) (gamegrid-kill-timer) (snake-mode) (snake-start-game)) (provide 'snake) ;;; arch-tag: 512ffc92-cfac-4287-9a4e-92890701a5c8 ;;; snake.el ends here