Merge from emacs--rel--22
[bpt/emacs.git] / lisp / play / bubbles.el
CommitLineData
a79b55e5
TTN
1;;; bubbles.el --- Puzzle game for Emacs.
2
dcb8ac09 3;; Copyright (C) 2007, 2008 Free Software Foundation, Inc.
a79b55e5 4
a79b55e5 5;; Author: Ulf Jasper <ulf.jasper@web.de>
a79b55e5
TTN
6;; URL: http://ulf.epplejasper.de/
7;; Created: 5. Feb. 2007
2f123a54 8;; Keywords: games
a79b55e5 9
2f123a54 10;; This file is part of GNU Emacs.
a79b55e5 11
2f123a54 12;; GNU Emacs is free software; you can redistribute it and/or modify
a79b55e5 13;; it under the terms of the GNU General Public License as published by
2f123a54
TTN
14;; the Free Software Foundation; either version 3, or (at your option)
15;; any later version.
a79b55e5 16
2f123a54
TTN
17;; GNU Emacs is distributed in the hope that it will be useful,
18;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20;; GNU General Public License for more details.
a79b55e5
TTN
21
22;; You should have received a copy of the GNU General Public License
2f123a54
TTN
23;; along with GNU Emacs; see the file COPYING. If not, write to the
24;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25;; Boston, MA 02110-1301, USA.
a79b55e5
TTN
26
27;;; Commentary:
28
29;; Bubbles is a puzzle game. Its goal is to remove as many bubbles as
30;; possible in as few moves as possible.
31
32;; Bubbles is an implementation of the "Same Game", similar to "Same
2f123a54 33;; GNOME" and many others, see <http://en.wikipedia.org/wiki/SameGame>.
a79b55e5
TTN
34
35;; Installation
36;; ------------
37
38;; Add the following lines to your Emacs startup file (`~/.emacs').
39;; (add-to-list 'load-path "/path/to/bubbles/")
40;; (autoload 'bubbles "bubbles" "Play Bubbles" t)
41
42;; ======================================================================
43
44;;; History:
45
a4fcacde
TTN
46;; 0.5 (2007-09-14)
47;; - Minor bugfixes.
48
a79b55e5
TTN
49;; 0.4 (2007-08-27)
50;; - Allow for undoing last move.
51;; - Bonus for removing all bubbles.
52;; - Speed improvements.
53;; - Animation enhancements.
54;; - Added `bubbles-mode-hook'.
55;; - Fixes: Don't move point.
56;; - New URL.
57
58;; 0.3 (2007-03-11)
59;; - Renamed shift modes and thus names of score files. All
60;; highscores are lost, unless you rename the score files from
61;; bubbles-shift-... to bubbles-...!
62;; - Bugfixes: Check for successful image creation.
63;; Disable menus and counter when game is over.
64;; Tested with GNU Emacs 22.0.93
65
66;; 0.2 (2007-02-24)
67;; - Introduced game themes.
68;; - Introduced graphics themes (changeable while playing).
69;; - Added menu.
70;; - Customization: grid size, colors, chars, shift mode.
71;; - More keybindings.
72;; - Changed shift direction from to-right to to-left.
73;; - Bugfixes: Don't remove single-bubble regions;
74;; Animation glitches fixed.
75;; Tested with GNU Emacs 22.0.93 and 21.4.1.
76
77;; 0.1 (2007-02-11)
78;; Initial release. Tested with GNU Emacs 22.0.93 and 21.4.1.
79
80;; ======================================================================
81
82;;; Code:
83
a4fcacde 84(defconst bubbles-version "0.5" "Version number of bubbles.el.")
2f123a54 85
a79b55e5
TTN
86(require 'gamegrid)
87(require 'cl)
88
89;; User options
90
91;; Careful with that axe, Eugene! Order does matter in the custom
92;; section below.
93
94(defcustom bubbles-game-theme
95 'easy
96 "Overall game theme.
97The overall game theme specifies a grid size, a set of colors,
98and a shift mode."
99 :type '(radio (const :tag "Easy" easy)
100 (const :tag "Medium" medium)
101 (const :tag "Difficult" difficult)
102 (const :tag "Hard" hard)
103 (const :tag "User defined" user-defined))
104 :group 'bubbles)
105
106(defun bubbles-set-game-easy ()
107 "Set game theme to 'easy'."
108 (interactive)
109 (setq bubbles-game-theme 'easy)
110 (bubbles))
111
112(defun bubbles-set-game-medium ()
113 "Set game theme to 'medium'."
114 (interactive)
115 (setq bubbles-game-theme 'medium)
116 (bubbles))
117
118(defun bubbles-set-game-difficult ()
119 "Set game theme to 'difficult'."
120 (interactive)
121 (setq bubbles-game-theme 'difficult)
122 (bubbles))
123
124(defun bubbles-set-game-hard ()
125 "Set game theme to 'hard'."
126 (interactive)
127 (setq bubbles-game-theme 'hard)
128 (bubbles))
129
130(defun bubbles-set-game-userdefined ()
131 "Set game theme to 'user-defined'."
132 (interactive)
133 (setq bubbles-game-theme 'user-defined)
134 (bubbles))
135
136(defgroup bubbles nil
137 "Bubbles, a puzzle game."
138 :group 'games)
139
140(defcustom bubbles-graphics-theme
141 'circles
142 "Graphics theme.
143It is safe to choose a graphical theme. If Emacs cannot display
144images the `ascii' theme will be used."
145 :type '(radio (const :tag "Circles" circles)
146 (const :tag "Squares" squares)
147 (const :tag "Diamonds" diamonds)
148 (const :tag "Balls" balls)
149 (const :tag "Emacs" emacs)
150 (const :tag "ASCII (no images)" ascii))
151 :group 'bubbles)
152
153(defconst bubbles--grid-small '(10 . 10)
154 "Predefined small bubbles grid.")
155
156(defconst bubbles--grid-medium '(15 . 10)
157 "Predefined medium bubbles grid.")
158
159(defconst bubbles--grid-large '(20 . 15)
160 "Predefined large bubbles grid.")
161
162(defconst bubbles--grid-huge '(30 . 20)
163 "Predefined huge bubbles grid.")
164
165(defcustom bubbles-grid-size
166 bubbles--grid-medium
167 "Size of bubbles grid."
168 :type `(radio (const :tag "Small" ,bubbles--grid-small)
169 (const :tag "Medium" ,bubbles--grid-medium)
170 (const :tag "Large" ,bubbles--grid-large)
171 (const :tag "Huge" ,bubbles--grid-huge)
172 (cons :tag "User defined"
173 (integer :tag "Width")
174 (integer :tag "Height")))
175 :group 'bubbles)
176
177(defconst bubbles--colors-2 '("orange" "violet")
178 "Predefined bubbles color list with two colors.")
179
180(defconst bubbles--colors-3 '("lightblue" "palegreen" "pink")
181 "Predefined bubbles color list with three colors.")
182
183(defconst bubbles--colors-4 '("firebrick" "sea green" "steel blue" "chocolate")
184 "Predefined bubbles color list with four colors.")
185
186(defconst bubbles--colors-5 '("firebrick" "sea green" "steel blue"
187 "sandy brown" "bisque3")
188 "Predefined bubbles color list with five colors.")
189
190(defcustom bubbles-colors
191 bubbles--colors-3
192 "List of bubble colors.
193The length of this list determines how many different bubble
194types are present."
195 :type `(radio (const :tag "Red, darkgreen" ,bubbles--colors-2)
196 (const :tag "Red, darkgreen, blue" ,bubbles--colors-3)
197 (const :tag "Red, darkgreen, blue, orange" ,bubbles--colors-4)
198 (const :tag "Red, darkgreen, blue, orange, violet"
199 ,bubbles--colors-5)
200 (repeat :tag "User defined" color))
201 :group 'bubbles)
202
203(defcustom bubbles-chars
204