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