Add 2010 to copyright years.
[bpt/emacs.git] / lisp / play / bubbles.el
index b4997ce..91968b0 100644 (file)
@@ -1,6 +1,6 @@
 ;;; bubbles.el --- Puzzle game for Emacs.
 
-;; Copyright (C) 2007, 2008  Free Software Foundation, Inc.
+;; Copyright (C) 2007, 2008, 2009, 2010  Free Software Foundation, Inc.
 
 ;; Author:      Ulf Jasper <ulf.jasper@web.de>
 ;; URL:         http://ulf.epplejasper.de/
@@ -9,10 +9,10 @@
 
 ;; This file is part of GNU Emacs.
 
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; 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.
+;; the Free Software Foundation, either version 3 of the License, 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
@@ -20,9 +20,7 @@
 ;; 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.
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;; Commentary:
 
@@ -84,7 +82,7 @@
 (defconst bubbles-version "0.5" "Version number of bubbles.el.")
 
 (require 'gamegrid)
-(require 'cl)
+(eval-when-compile (require 'cl))       ; for 'case
 
 ;; User options
 
@@ -211,7 +209,7 @@ the number of colors, see `bubbles-colors'."
 (defcustom bubbles-shift-mode
   'default
   "Shift mode.
-Available modes are `shift-default' and`shift-always'."
+Available modes are `shift-default' and `shift-always'."
   :type '(radio (const :tag "Default" default)
                 (const :tag "Shifter" always)
                 ;;(const :tag "Mega Shifter" 'mega)
@@ -235,7 +233,7 @@ Available modes are `shift-default' and`shift-always'."
   "Current Bubbles score.")
 
 (defvar bubbles--neighbourhood-score 0
-  "Score of active bubbles neighbourhood.")
+  "Score of active bubbles neighborhood.")
 
 (defvar bubbles--faces nil
   "List of currently used faces.")
@@ -784,7 +782,7 @@ static char * dot3d_xpm[] = {
 
 (defsubst bubbles--empty-char ()
   "The character used for removed bubbles (empty grid cells)."
-  ? )
+  ?\s)
 
 (defun bubbles-set-graphics-theme-ascii ()
   "Set graphics theme to `ascii'."
@@ -920,24 +918,29 @@ static char * dot3d_xpm[] = {
     map)
   "Mode map for bubbles.")
 
-(defun bubbles-mode ()
+(define-derived-mode bubbles-mode nil "Bubbles"
   "Major mode for playing bubbles.
 \\{bubbles-mode-map}"
-  (kill-all-local-variables)
-  (use-local-map bubbles-mode-map)
-  (setq major-mode 'bubbles-mode)
-  (setq mode-name "Bubbles")
   (setq buffer-read-only t)
   (buffer-disable-undo)
-  (setq buffer-undo-list t)
   (force-mode-line-update)
   (redisplay)
-  (add-hook 'post-command-hook 'bubbles--mark-neighbourhood t t)
-  (run-hooks 'bubbles-mode-hook))
+  (add-hook 'post-command-hook 'bubbles--mark-neighbourhood t t))
 
 ;;;###autoload
 (defun bubbles ()
-  "Play Bubbles game."
+  "Play Bubbles game.
+\\<bubbles-mode-map>
+The goal is to remove all bubbles with as few moves as possible.
+\\[bubbles-plop] on a bubble removes that bubble and all
+connected bubbles of the same color.  Unsupported bubbles fall
+down, and columns that do not contain any bubbles suck the
+columns on its right towards the left.
+
+\\[bubbles-set-game-easy] sets the difficulty to easy.
+\\[bubbles-set-game-medium] sets the difficulty to medium.
+\\[bubbles-set-game-difficult] sets the difficulty to difficult.
+\\[bubbles-set-game-hard] sets the difficulty to hard."
   (interactive)
   (switch-to-buffer (get-buffer-create "*bubbles*"))
   (when (or (not bubbles--playing)
@@ -952,6 +955,8 @@ static char * dot3d_xpm[] = {
   (message "bubbles-quit")
   (bury-buffer))
 
+(declare-function image-size "image.c" (spec &optional pixels frame))
+
 (defun bubbles--compute-offsets ()
   "Update horizontal and vertical offsets for centering the bubbles grid.
 Set `bubbles--col-offset' and `bubbles--row-offset'."
@@ -1083,7 +1088,7 @@ Set `bubbles--col-offset' and `bubbles--row-offset'."
       nil)))
 
 (defun bubbles--mark-direct-neighbours (row col char)
-  "Mark direct neighbours of bubble at ROW COL with same CHAR."
+  "Mark direct neighbors of bubble at ROW COL with same CHAR."
   (save-excursion
     (let ((count 0))
       (when (and (bubbles--goto row col)
@@ -1099,7 +1104,7 @@ Set `bubbles--col-offset' and `bubbles--row-offset'."
       count)))
 
 (defun bubbles--mark-neighbourhood (&optional pos)
-  "Mark neighbourhood of point.
+  "Mark neighborhood of point.
 Use optional parameter POS instead of point if given."
   (when bubbles--playing
     (unless pos (setq pos (point)))
@@ -1124,7 +1129,7 @@ Use optional parameter POS instead of point if given."
       (error (message "Bubbles: Internal error %s" err)))))
 
 (defun bubbles--neighbourhood-available ()
-  "Return t if another valid neighbourhood is available."
+  "Return t if another valid neighborhood is available."
   (catch 'found
     (save-excursion
       (dotimes (i (bubbles--grid-height))
@@ -1154,12 +1159,12 @@ Use optional parameter POS instead of point if given."
   (bubbles--update-score))
 
 (defun bubbles--update-score ()
-  "Calculate and display new bubble score."
+  "Calculate and display new bubbles score."
   (setq bubbles--score (+ bubbles--score bubbles--neighbourhood-score))
   (bubbles--show-scores))
 
 (defun bubbles--update-neighbourhood-score (size)
-  "Calculate and display score of active neighbourhood from its SIZE."
+  "Calculate and display score of active neighborhood from its SIZE."
   (if (> size 1)
       (setq bubbles--neighbourhood-score (expt (- size 1) 2))
     (setq bubbles--neighbourhood-score 0))