annotate lisp/games/xmine.el @ 125:8b0638b347ec

Added tag r20-1b15 for changeset 9b50b4588a93
author cvs
date Mon, 13 Aug 2007 09:26:41 +0200
parents 9b50b4588a93
children 6608ceec7cf8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
1 ;;; xmine.el --- Mine game for XEmacs
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
2
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
3 ;; Author: Jens Lautenbacher <jens@lemming0.lem.uni-karlsruhe.de>
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
4 ;; Keywords: games
124
9b50b4588a93 Import from CVS: tag r20-1b15
cvs
parents: 120
diff changeset
5 ;; Version: 1.7
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
6
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
7 ;; This file is part of XEmacs.
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
8
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
9 ;; XEmacs is free software; you can redistribute it and/or modify
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
10 ;; it under the terms of the GNU General Public License as published by
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
11 ;; the Free Software Foundation; either version 2, or (at your option)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
12 ;; any later version.
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
13
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
14 ;; XEmacs is distributed in the hope that it will be useful,
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
17 ;; GNU General Public License for more details.
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
18
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
19 ;; You should have received a copy of the GNU General Public License
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
20 ;; along with XEmacs; see the file COPYING. If not, write to the
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
22 ;; Boston, MA 02111-1307, USA.
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
23
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
24 ;; Commentary: This is a complete reimplementation of the classical
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
25 ;; mine searching game known from various OS/GUIs under names like
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
26 ;; xmine, minesweeper etc.
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
27
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
28 ;; The idea to implement this in elisp is from
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
29 ;; Jacques Duthen <duthen@cegelec-red.fr>,
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
30 ;; the author of the original mine game for GNU Emacs. This version
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
31 ;; has to the best of my knowledge no code in common with his version,
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
32 ;; but cudos go to him for first starting this...
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
33 ;;
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
34 ;; I mainly wrote this as an example how graphics handling in XEmacs
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
35 ;; is possible. I think I did it the right way, using an extension to
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
36 ;; the annotation mechanism and via extensive use of `slots' (realized
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
37 ;; as properties of extents) to hold the data in the object itself.
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
38 ;; (Of course this is not true. The keyboard handling is controlled from
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
39 ;; the "outside" of the objects. But at one time during development
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
40 ;; before hacking the keyboard controls the code really _was_ nice...
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
41 ;; now it's a bad messing with slots and controls from the outside)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
42 ;;
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
43 ;; Code:
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
44 ;;
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
45 ;;; First of all we'll define the needed varibles.
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
46
124
9b50b4588a93 Import from CVS: tag r20-1b15
cvs
parents: 120
diff changeset
47 (defconst xmine-version-number "1.7" "XEmacs Mine version number.")
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
48 (defconst xmine-version (format "XEmacs Mine v%s by Jens Lautenbacher © 1997"
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
49 xmine-version-number)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
50 "Full XEmacs Mine version number.")
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
51
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
52 (defgroup xmine nil
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
53 "The well known mine searching game."
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
54 :group 'games)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
55
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
56 (defcustom xmine-width 25
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
57 "The width of the mine field"
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
58 :group 'xmine
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
59 :type 'integer)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
60
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
61 (defcustom xmine-height 20
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
62 "The height of the mine field"
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
63 :group 'xmine
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
64 :type 'integer)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
65
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
66 (defcustom xmine-glyph-dir (concat data-directory "mine/")
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
67 "The directory where the mine glyphs reside"
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
68 :group 'xmine
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
69 :type 'directory)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
70
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
71 (defface xmine-hidden-face
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
72 '((t
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
73 (:background "blue")))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
74 "The face used for hidden tiles on ttys"
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
75 :group 'xmine)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
76
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
77 (defface xmine-flagged-face
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
78 '((t
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
79 (:background "red")))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
80 "The face used for flagged tiles on ttys"
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
81 :group 'xmine)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
82
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
83 (defface xmine-number-face
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
84 '((t
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
85 (:background "green")))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
86 "The face used for unhidden, numbered tiles on ttys"
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
87 :group 'xmine)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
88
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
89
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
90 (defvar xmine-pad-glyph
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
91 (make-glyph
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
92 (if (and (eq window-system 'x) (featurep 'xpm))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
93 (concat xmine-glyph-dir "pad.xpm")
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
94 " ")))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
95
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
96 (defvar xmine-title-glyph
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
97 (make-glyph
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
98 (if (and (eq window-system 'x) (featurep 'xpm))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
99 (concat xmine-glyph-dir "splash.xpm")
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
100 "------------------ XEmacs XMine ------------------")))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
101
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
102 (defvar xmine-glyph-production-list
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
103 '(("xmine-new-up" "new_up.gif" "new" nil )
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
104 ("xmine-new-down" "new_down.gif" "NEW" nil )
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
105 ("xmine-quit-up" "quit_up.gif" "quit" nil )
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
106 ("xmine-quit-down" "quit_down.gif" "QUIT" nil )
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
107 ("xmine-up-glyph" "empty_16_up.gif" "@ " xmine-hidden-face )
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
108 ("xmine-up-sel-glyph" "empty_16_up_sel.gif" "@<" xmine-hidden-face )
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
109 ("xmine-down-glyph" "empty_16_down.gif" "? " nil )
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
110 ("xmine-flagged-glyph" "flagged_16_up.gif" "! " xmine-flagged-face)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
111 ("xmine-flagged-sel-glyph" "flagged_16_up_sel.gif" "!<" xmine-flagged-face)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
112 ("xmine-mine-glyph" "bomb_16_flat.gif" "* " nil )
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
113 ("xmine-mine-sel-glyph" "bomb_16_flat.gif" "*<" nil )
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
114 ("xmine-trapped-glyph" "bomb_trapped_16_flat.gif" "X " nil )
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
115 ("xmine-0-glyph" "empty_16_flat.gif" ". " nil )
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
116 ("xmine-0-sel-glyph" "empty_16_flat_sel.gif" ".<" nil )
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
117 ("xmine-1-glyph" "1_16_flat.gif" "1 " xmine-number-face )
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
118 ("xmine-1-sel-glyph" "1_16_flat_sel.gif" "1<" xmine-number-face )
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
119 ("xmine-2-glyph" "2_16_flat.gif" "2 " xmine-number-face )
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
120 ("xmine-2-sel-glyph" "2_16_flat_sel.gif" "2<" xmine-number-face )
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
121 ("xmine-3-glyph" "3_16_flat.gif" "3 " xmine-number-face )
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
122 ("xmine-3-sel-glyph" "3_16_flat_sel.gif" "3<" xmine-number-face )
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
123 ("xmine-4-glyph" "4_16_flat.gif" "4 " xmine-number-face )
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
124 ("xmine-4-sel-glyph" "4_16_flat_sel.gif" "4<" xmine-number-face )
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
125 ("xmine-5-glyph" "5_16_flat.gif" "5 " xmine-number-face )
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
126 ("xmine-5-sel-glyph" "5_16_flat_sel.gif" "5<" xmine-number-face )
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
127 ("xmine-6-glyph" "6_16_flat.gif" "6 " xmine-number-face )
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
128 ("xmine-6-sel-glyph" "6_16_flat_sel.gif" "6<" xmine-number-face )
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
129 ("xmine-7-glyph" "7_16_flat.gif" "7 " xmine-number-face )
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
130 ("xmine-7-sel-glyph" "7_16_flat_sel.gif" "7<" xmine-number-face )
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
131 ("xmine-8-glyph" "8_16_flat.gif" "8 " xmine-number-face )
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
132 ("xmine-8-sel-glyph" "8_16_flat_sel.gif" "8<" xmine-number-face )))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
133
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
134 (defun xmine-generate-glyphs ()
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
135 (let ((list xmine-glyph-production-list)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
136 elem var gif text face)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
137 (while (setq elem (pop list))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
138 (setq var (car elem)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
139 gif (cadr elem)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
140 text (caddr elem)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
141 face (cadddr elem))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
142 (set (intern var)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
143 (make-glyph (if (eq window-system 'x)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
144 (concat xmine-glyph-dir gif)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
145 text)))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
146 (if face
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
147 (set-glyph-face (eval (intern-soft var)) face)))))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
148
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
149 (xmine-generate-glyphs)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
150
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
151 (defvar xmine-key-sel-button nil)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
152
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
153 (defun xmine-up-glyph (ext)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
154 (if (equal ext xmine-key-sel-button)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
155 (progn
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
156 (set-extent-property ext 'xmine-non-selected-glyph xmine-up-glyph)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
157 xmine-up-sel-glyph)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
158 xmine-up-glyph))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
159
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
160 (defun xmine-flagged-glyph (ext)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
161 (if (equal ext xmine-key-sel-button)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
162 (progn
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
163 (set-extent-property ext 'xmine-non-selected-glyph xmine-flagged-glyph)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
164 xmine-flagged-sel-glyph)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
165 xmine-flagged-glyph))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
166
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
167 (defcustom xmine-%-of-mines 12
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
168 "The percentage of tiles that should be mines."
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
169 :group 'xmine
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
170 :type 'integer)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
171
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
172 (defcustom xmine-balloon-list (list "What are you waiting for?"
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
173 "Push me!"
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
174 "Come on. Don't sleep."
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
175 "Are you sure?"
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
176 "Are you sleeping?"
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
177 "Yes! Do it!"
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
178 "I'm getting bored."
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
179 "You will NEVER beat me.")
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
180 "(Random) texts for the balloon-help property of the tiles"
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
181 :group 'xmine
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
182 :type '(repeat (string)))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
183
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
184 (defcustom xmine-background "white"
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
185 "The background color of XMine's buffer.
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
186 Many colors will not blend nicely with the logo. Shades of light grey are
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
187 preferred if you don't want to use white."
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
188 :group 'xmine
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
189 :type 'color)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
190
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
191 (defvar xmine-keymap nil)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
192
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
193 (if xmine-keymap ()
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
194 (setq xmine-keymap (make-sparse-keymap))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
195 (suppress-keymap xmine-keymap)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
196 (define-key xmine-keymap [up] 'xmine-key-up)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
197 (define-key xmine-keymap [down] 'xmine-key-down)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
198 (define-key xmine-keymap [right] 'xmine-key-right)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
199 (define-key xmine-keymap [left] 'xmine-key-left)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
200 (define-key xmine-keymap "e" 'xmine-key-up)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
201 (define-key xmine-keymap "c" 'xmine-key-down)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
202 (define-key xmine-keymap "f" 'xmine-key-right)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
203 (define-key xmine-keymap "s" 'xmine-key-left)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
204 (define-key xmine-keymap "w" 'xmine-key-up-left)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
205 (define-key xmine-keymap "x" 'xmine-key-down-left)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
206 (define-key xmine-keymap "r" 'xmine-key-up-right)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
207 (define-key xmine-keymap "v" 'xmine-key-down-right)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
208 (define-key xmine-keymap [return] 'xmine-key-action3)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
209 (define-key xmine-keymap "d" 'xmine-key-action3)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
210 (define-key xmine-keymap [(shift space)] 'xmine-key-action2)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
211 (define-key xmine-keymap "a" 'xmine-key-action2)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
212 (define-key xmine-keymap [space] 'xmine-key-action1)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
213 (define-key xmine-keymap [Q] 'xmine-key-quit)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
214 (define-key xmine-keymap [N] 'xmine-key-new))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
215
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
216 (defvar xmine-number-of-flagged 0)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
217
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
218 (defvar xmine-number-of-opened 0)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
219
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
220 (defvar xmine-number-of-mines 0)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
221
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
222 (defvar xmine-field nil)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
223
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
224 (defvar xmine-buffer nil)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
225
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
226 (defvar xmine-quit-ann nil)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
227
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
228 (defvar xmine-new-ann nil)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
229
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
230 (defvar xmine-count-ann nil)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
231
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
232 (defvar xmine-count-glyph (make-glyph "Mines: 00"))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
233
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
234 (defvar xmine-mode-hook nil
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
235 "*Hook called by `xmine-mode-hook'.")
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
236
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
237 ;; the next function is more or less stolen from annotation.el and
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
238 ;; modified to fit in our scheme were all three buttons should trigger
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
239 ;; actions
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
240
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
241 (defun xmine-activate-function-button (event)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
242 (interactive "e")
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
243 (let* ((extent (event-glyph-extent event))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
244 (button (event-button event))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
245 (action (intern (concat "action" (number-to-string button))))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
246 (mouse-down t)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
247 (up-glyph nil))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
248 ;; make the glyph look pressed
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
249 (cond ((annotation-down-glyph extent)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
250 (setq up-glyph (annotation-glyph extent))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
251 (set-annotation-glyph extent (annotation-down-glyph extent))))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
252 (while mouse-down
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
253 (setq event (next-event event))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
254 (if (button-release-event-p event)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
255 (setq mouse-down nil)))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
256 ;; make the glyph look released
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
257 (cond ((annotation-down-glyph extent)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
258 (set-annotation-glyph extent up-glyph)))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
259 (if (eq extent (event-glyph-extent event))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
260 (if (extent-property extent action)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
261 (funcall (extent-property extent action) extent)))))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
262
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
263 ;;; Here we define the button object's constructor function
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
264
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
265 (defun xmine-button-create (x y type)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
266 (let ((ext (make-annotation
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
267 xmine-up-glyph nil 'text nil nil xmine-down-glyph nil)))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
268 (set-extent-property ext 'action1 'xmine-action1)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
269 (set-extent-property ext 'action2 'xmine-beep)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
270 (set-extent-property ext 'action3 'xmine-action3)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
271 (set-extent-property ext 'xmine-glyph (xmine-type-to-glyph type))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
272 (set-extent-property ext 'xmine-sel-glyph (xmine-type-to-sel-glyph type))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
273 (set-extent-property ext 'xmine-type type)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
274 (set-extent-property ext 'xmine-x x)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
275 (set-extent-property ext 'xmine-y y)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
276 (set-extent-property ext 'xmine-flagged nil)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
277 (set-extent-property ext 'xmine-hidden t)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
278 (set-extent-property ext 'end-open t)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
279 (set-extent-property ext 'balloon-help (xmine-balloon-text))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
280 (aset xmine-field (+ (* (1- y) xmine-width) (1- x)) ext)))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
281
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
282 ;;; ...and this is the second global function to change a
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
283 ;;; button object. It is only needed during creation of the board.
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
284
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
285 (defun xmine-button-change-type (ext type)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
286 (set-extent-property ext 'xmine-glyph (xmine-type-to-glyph type))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
287 (set-extent-property ext 'xmine-sel-glyph (xmine-type-to-sel-glyph type))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
288 (set-extent-property ext 'xmine-type type))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
289
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
290 ;;; some needed predicates.
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
291
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
292 (defun xmine-flat-button-p (ext)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
293 (and ext
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
294 (not (extent-property ext 'xmine-hidden))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
295 (equal "0" (extent-property ext 'xmine-type))))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
296
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
297 (defun xmine-mine-button-p (ext)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
298 (and ext
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
299 (equal "mine" (extent-property ext 'xmine-type))))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
300
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
301 ;;; the next three functions are helper functions used inside a button
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
302 ;;; object.
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
303
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
304 (defun xmine-balloon-text ()
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
305 (nth (random (length xmine-balloon-list)) xmine-balloon-list))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
306
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
307 (defun xmine-beep (&rest forget)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
308 (beep))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
309
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
310 (defun xmine-type-to-glyph (type)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
311 (eval (intern-soft (concat "xmine-" type "-glyph"))))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
312
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
313 (defun xmine-type-to-sel-glyph (type)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
314 (eval (intern-soft (concat "xmine-" type "-sel-glyph"))))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
315
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
316 ;;; the next three functions are the main functions that are used
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
317 ;;; inside the button objects and which are bound to the 'action1,
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
318 ;;; 'action2 and 'action3 slots respectively
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
319
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
320 (defun xmine-action1 (ext &optional no-repaint force)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
321 "This unhides a hidden button"
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
322 (if (or force
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
323 (not (extent-property ext 'xmine-flagged)))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
324 (progn
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
325 (if (and (not force)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
326 (extent-property ext 'xmine-hidden))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
327 (setq xmine-number-of-opened (1+ xmine-number-of-opened)))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
328 (set-extent-property ext 'xmine-hidden nil)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
329 (set-annotation-glyph ext (if (equal ext xmine-key-sel-button)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
330 (progn
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
331 (set-extent-property
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
332 ext 'xmine-non-selected-glyph
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
333 (extent-property ext 'xmine-glyph))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
334 (extent-property ext 'xmine-sel-glyph))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
335 (extent-property ext 'xmine-glyph)))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
336 (set-extent-property ext 'action3 nil)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
337 (set-extent-property ext 'action1 nil)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
338 (set-extent-property ext 'balloon-help nil)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
339 (set-extent-property ext 'action2 'xmine-action2)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
340 (if (not no-repaint)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
341 (progn
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
342 (xmine-unhide-sound)
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
343 (xmine-field-repaint ext)
124
9b50b4588a93 Import from CVS: tag r20-1b15
cvs
parents: 120
diff changeset
344 (if (and (xmine-game-solved-p)
9b50b4588a93 Import from CVS: tag r20-1b15
cvs
parents: 120
diff changeset
345 (not (xmine-mine-button-p ext)))
9b50b4588a93 Import from CVS: tag r20-1b15
cvs
parents: 120
diff changeset
346 (xmine-end-game)))))))
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
347
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
348 (defun xmine-action2 (ext)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
349 "This unhides all hidden neighbours of a button.
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
350 It is meant as convenience function you can use if you're sure that
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
351 you've marked all mines around the button correctly (or you're sure
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
352 there isn't one)"
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
353 (let ((list (xmine-get-neighbours ext))
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
354 (xmine-no-unhide-sound t)
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
355 next)
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
356 (if list (xmine-unhide-many-sound))
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
357 (while (setq next (pop list))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
358 (if (not (xmine-flat-button-p next)) (xmine-action1 next)))))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
359
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
360 (defun xmine-action3 (ext)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
361 "This toggles the flagged status of a button.
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
362 You flag a button if you know - or think - that there's a mine under it"
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
363 (if (extent-property ext 'xmine-flagged)
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
364 (progn
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
365 (set-annotation-glyph ext (xmine-up-glyph ext))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
366 (set-extent-property ext 'action1 'xmine-action1)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
367 (set-extent-property ext 'xmine-flagged nil)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
368 (setq xmine-number-of-flagged (1- xmine-number-of-flagged))
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
369 (xmine-flag-sound)
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
370 (set-annotation-glyph xmine-count-ann
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
371 (make-glyph
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
372 (format "Mines: %2d"
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
373 (- xmine-number-of-mines
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
374 xmine-number-of-flagged)))))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
375 (if (= xmine-number-of-flagged xmine-number-of-mines)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
376 (progn
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
377 (beep)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
378 (message
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
379 "Impossible. You seem to have marked too many tiles as mines?"))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
380 (set-annotation-glyph ext (xmine-flagged-glyph ext))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
381 (set-extent-property ext 'action1 nil)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
382 (set-extent-property ext 'xmine-flagged t)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
383 (setq xmine-number-of-flagged (1+ xmine-number-of-flagged))
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
384 (xmine-flag-sound)
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
385 (if (xmine-game-solved-p) (xmine-end-game)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
386 (set-annotation-glyph xmine-count-ann
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
387 (make-glyph
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
388 (format "Mines: %2d"
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
389 (- xmine-number-of-mines
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
390 xmine-number-of-flagged))))))))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
391
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
392
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
393 ;;; the sounds...
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
394 (defcustom xmine-play-sounds nil
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
395 "If XMine should play some sounds for various events to happen."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
396 :group 'xmine
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
397 :type 'boolean)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
398
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
399 (defun xmine-play-sounds-p ()
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
400 (and xmine-play-sounds
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
401 (or (featurep 'native-sound)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
402 (featurep 'nas-sound))
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
403 (or (device-sound-enabled-p)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
404 (and (featurep 'native-sound)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
405 (not native-sound-only-on-console)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
406 (eq (device-type) 'x)))))
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
407
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
408
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
409 (defcustom xmine-flag-sound (concat data-directory "sounds/click.au")
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
410 "The sound played when flagging/un-flagging a tile"
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
411 :group 'xmine
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
412 :type 'file)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
413
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
414 (defcustom xmine-unhide-sound (concat data-directory "sounds/drip.au")
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
415 "The sound played when unhiding a tile"
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
416 :group 'xmine
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
417 :type 'file)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
418
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
419 (defcustom xmine-unhide-many-sound (concat data-directory "sounds/boing.au")
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
420 "The sound played when unhiding all neighbours of a tile"
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
421 :group 'xmine
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
422 :type 'file)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
423
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
424 (defcustom xmine-explode-sound (concat xmine-glyph-dir "explosion3.au")
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
425 "The sound played when you unhide a mine"
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
426 :group 'xmine
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
427 :type 'file)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
428
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
429 (defcustom xmine-solved-sound (concat data-directory "sounds/im_so_happy.au")
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
430 "The sound played if you managed to win the game."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
431 :group 'xmine
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
432 :type 'file)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
433
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
434 (defun xmine-flag-sound ()
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
435 (if (xmine-play-sounds-p)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
436 (play-sound-file xmine-flag-sound)))
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
437
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
438 (defvar xmine-no-unhide-sound nil)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
439
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
440 (defun xmine-unhide-sound ()
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
441 (if (and (xmine-play-sounds-p)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
442 (not xmine-no-unhide-sound))
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
443 (play-sound-file xmine-unhide-sound)))
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
444
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
445 (defun xmine-unhide-many-sound ()
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
446 (if (xmine-play-sounds-p)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
447 (play-sound-file xmine-unhide-many-sound)))
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
448
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
449 (defun xmine-explode-sound ()
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
450 (if (xmine-play-sounds-p)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
451 (play-sound-file xmine-explode-sound)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
452 (beep)))
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
453
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
454 (defun xmine-solved-sound ()
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
455 (if (xmine-play-sounds-p)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
456 (play-sound-file xmine-solved-sound)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
457 (beep)))
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
458
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
459
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
460 ;;; what to do after a button is unhidden: We (maybe) have to repaint
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
461 ;;; parts of the board. This is done here recursively.
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
462
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
463 (defun xmine-field-repaint (ext)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
464 (let* ((flatp (xmine-flat-button-p ext))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
465 (minep (xmine-mine-button-p ext))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
466 (neighbours (xmine-get-neighbours ext))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
467 (max-lisp-eval-depth (* 8 xmine-width xmine-height))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
468 next-ext ext-list)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
469 (cond (flatp
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
470 (while (setq next-ext (pop neighbours))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
471 (if (extent-property next-ext 'xmine-hidden)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
472 (progn
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
473 (xmine-action1 next-ext 'no-repaint)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
474 (and (equal "0" (extent-property next-ext 'xmine-type))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
475 (push next-ext ext-list)))))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
476 (while ext-list
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
477 (setq next-ext (pop ext-list))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
478 (xmine-field-repaint next-ext)))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
479 (minep
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
480 (set-extent-property ext 'xmine-glyph xmine-trapped-glyph)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
481 (set-extent-property ext 'xmine-sel-glyph xmine-trapped-glyph)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
482 (xmine-show-all)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
483 (xmine-end-game-trapped)))))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
484
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
485
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
486 (defun xmine-get-neighbours (ext)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
487 "This gives back a list of all neighbours of a button, correctly
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
488 handling buttons at the side or corner of course"
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
489 (let* ((x (extent-property ext 'xmine-x))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
490 (y (extent-property ext 'xmine-y))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
491 next-coord next list
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
492 (neighbours (list (list (1- x) (1+ y))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
493 (list x (1+ y))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
494 (list (1+ x) (1+ y))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
495 (list (1- x) (1- y))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
496 (list x (1- y))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
497 (list (1+ x) (1- y))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
498 (list (1+ x) y)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
499 (list (1- x) y))))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
500 (while (setq next-coord (pop neighbours))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
501 (if (setq next (xmine-field-button-at (car next-coord)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
502 (cadr next-coord)))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
503 (push next list)))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
504 list))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
505
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
506
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
507 ;;; the next four functions are used to know if we're at the end of
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
508 ;;; the game (either successfully or exploded) and do the approbate
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
509 ;;; action
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
510
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
511 (defun xmine-game-solved-p ()
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
512 "You have solved the game successfully if the number of flagged
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
513 mines plus the number of unhidden buttons equals width*height of the field"
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
514 (equal (+ xmine-number-of-flagged xmine-number-of-opened)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
515 (* xmine-width xmine-height)))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
516
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
517 (defun xmine-end-game ()
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
518 (set-annotation-glyph xmine-count-ann
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
519 (make-glyph " Solved. "))
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
520 (sit-for 0)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
521 (xmine-solved-sound))
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
522
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
523 (defun xmine-end-game-trapped ()
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
524 (xmine-explode-sound)
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
525 (set-annotation-glyph xmine-count-ann
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
526 (make-glyph "++ RIP ++")))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
527
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
528 (defun xmine-show-all ()
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
529 (let ((list (append xmine-field nil))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
530 next)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
531 (while (setq next (pop list))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
532 (xmine-action1 next 'no-repaint 'force))))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
533
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
534
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
535 (defun xmine-field-button-at (x y)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
536 "This function gives back the button at a given coordinate pair (x y)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
537 It is only used during creation of the board and when getting the
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
538 neighbours of a button (and for keyboard handling...), as we don't
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
539 want to use coordinates in the main loop, only the button object
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
540 itself should be referenced. Of course the use of this function could
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
541 be avoided in xmine-get-neighbours by storing the neighbour buttons
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
542 directly in the button, but this seems to be a bit oversized for this
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
543 little game."
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
544 (if (or (> x xmine-width) (< x 1)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
545 (> y xmine-height) (< y 1)) nil
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
546 (aref xmine-field (+ (* (1- y) xmine-width) (1- x)))))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
547
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
548 ;;;###autoload
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
549 (defun xmine-mode ()
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
550 "A mode for playing the well known mine searching game.
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
551
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
552 `\\<annotation-local-map-default>\\[xmine-activate-function-button1]' or `\\<xmine-keymap>\\[xmine-key-action1]' unhides a tile,
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
553 `\\<annotation-local-map-default>\\[xmine-activate-function-button2]' or `\\<xmine-keymap>\\[xmine-key-action2]' unhides all neighbours of a tile,
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
554 `\\<annotation-local-map-default>\\[xmine-activate-function-button3]' or `\\<xmine-keymap>\\[xmine-key-action3]' (un)flagges a tile to hold a mine.
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
555
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
556 `\\[xmine-key-new]' starts a new game.
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
557 `\\[xmine-key-quit]' ends a game.
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
558
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
559 All keybindings (with alternatives) currently in effect:
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
560 \\{xmine-keymap}
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
561
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
562 The rules are quite easy: You start by unhiding (random) tiles. An unhidden
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
563 tile showing a number tells you something about the number of mines in it's
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
564 neighborhood, where the neighborhood are all 8 tiles (or less if it's
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
565 at a border) around the tile.
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
566
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
567 E.g. a \"1\" shows you that there is only one mine in the neighborhood of
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
568 this tile. Empty tiles have no mines around them, and empty tiles in
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
569 the neighborhood of another empty tile are all automatically unhidden
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
570 if you unhide one of them. You need to find a strategy to use the
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
571 information you have from the numbers to \"flag\" the tiles with mines
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
572 under them and unhide all other tiles. If you correctly made this
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
573 without accidently unhiding a mine, you've won.
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
574
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
575 If you are sure you have correctly flagged all mines around a unhidden tile,
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
576 you can use Button-2 or \\[xmine-key-action2] on it to unhide all it's
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
577 neighbors. But beware: If you made a mistake by flagging the wrong mines,
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
578 you'll blow up!
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
579
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
580 Have Fun."
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
581 (interactive)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
582 (xmine-field-create))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
583
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
584 ;;;###autoload
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
585 (fset 'xmine 'xmine-mode)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
586
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
587 (defun xmine-field-create ()
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
588 "We create the playing board here."
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
589 (let ((width 1)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
590 (height 1)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
591 (pop-up-windows nil)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
592 total)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
593 (xmine-buffer-init)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
594 (pop-to-buffer xmine-buffer)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
595 (setq total (* xmine-height xmine-width))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
596 (setq xmine-field (make-vector total nil))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
597 (xmine-init-mines
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
598 (setq xmine-number-of-mines
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
599 (min 99 (round (* (/ (float xmine-%-of-mines) 100) total)))))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
600 (insert "\n ")
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
601 (set-extent-end-glyph (make-extent (point) (point)) xmine-title-glyph)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
602 (insert "\n\n")
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
603 (while (<= height xmine-height)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
604 (insert " ")
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
605 (while (<= width xmine-width)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
606 (if (xmine-field-button-at width height)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
607 (xmine-button-create width height "mine")
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
608 (xmine-button-create width height "0"))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
609 (setq width (+ width 1)))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
610 (insert " \n")
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
611 (setq width 1)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
612 (setq height (+ height 1)))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
613 (insert "\n ")
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
614 (set-extent-begin-glyph (make-extent (point) (point)) xmine-pad-glyph)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
615 (setq xmine-new-ann
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
616 (make-annotation xmine-new-up nil
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
617 'text nil nil xmine-new-down nil))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
618 (set-extent-property xmine-new-ann 'action1 '(lambda (&rest egal)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
619 (xmine-field-create)))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
620 (set-extent-property xmine-new-ann 'action2 nil)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
621 (set-extent-property xmine-new-ann 'action3 nil)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
622 (set-extent-property xmine-new-ann 'end-open t)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
623 (set-extent-begin-glyph (make-extent (point) (point)) xmine-pad-glyph)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
624 (setq xmine-count-ann
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
625 (make-annotation xmine-count-glyph nil
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
626 'text nil nil nil nil))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
627 (set-extent-begin-glyph (make-extent (point) (point)) xmine-pad-glyph)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
628 (setq xmine-quit-ann
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
629 (make-annotation xmine-quit-up nil
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
630 'text nil nil xmine-quit-down nil))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
631 (set-extent-property xmine-quit-ann 'action1
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
632 '(lambda (&rest egal)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
633 (kill-buffer (current-buffer))))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
634 (set-extent-property xmine-quit-ann 'action2 nil)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
635 (set-extent-property xmine-quit-ann 'action3 nil)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
636 (set-extent-property xmine-quit-ann 'end-open t)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
637 (xmine-attach-numbers)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
638 (setq xmine-number-of-flagged 0)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
639 (setq xmine-number-of-opened 0)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
640 (set-annotation-glyph xmine-count-ann
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
641 (make-glyph
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
642 (format "Mines: %2d" xmine-number-of-mines)))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
643 (goto-char (point-min))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
644 (setq buffer-read-only 't)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
645 (if (eq window-system 'x)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
646 (set-specifier (face-background 'default)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
647 xmine-background xmine-buffer))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
648 (set-specifier (face-background 'text-cursor)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
649 xmine-background xmine-buffer)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
650 (setq xmine-key-sel-button nil)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
651 (xmine-select-button (xmine-field-button-at (/ xmine-width 2)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
652 (/ xmine-height 2)))))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
653
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
654
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
655 (defun xmine-init-mines (num)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
656 "A subroutine for xmine-field create.
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
657 We randomly set a part of the nil-filled board vector with t to
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
658 indicate the places where mines should reside."
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
659 (let (x y elem)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
660 (random t)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
661 (while (> num 0)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
662 (setq x (1+ (random xmine-width)))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
663 (setq y (1+ (random xmine-height)))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
664 (setq elem (xmine-field-button-at x y))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
665 (if (not elem)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
666 (progn
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
667 (aset xmine-field (+ (* (1- y) xmine-width) (1- x)) t)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
668 (setq num (1- num)))))))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
669
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
670 (defun xmine-attach-numbers ()
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
671 "A subroutine for xmine-field-create.
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
672 The board is populated by now with empty buttons and mines. Here we
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
673 change the correct empty buttons to \"numbered\" buttons"
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
674 (let
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
675 ((buttons (append xmine-field nil))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
676 ext)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
677 (while (setq ext (pop buttons))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
678 (let ((num 0)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
679 (minep (xmine-mine-button-p ext))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
680 (neighbours (xmine-get-neighbours ext))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
681 next)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
682 (if (not minep)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
683 (progn
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
684 (while (setq next (pop neighbours))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
685 (if (xmine-mine-button-p next) (setq num (1+ num))))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
686 (if (> num 0)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
687 (xmine-button-change-type ext (number-to-string num)))))))))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
688
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
689
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
690 (defun xmine-buffer-init ()
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
691 "A subroutine for xmine-create-field.
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
692 We set up the XMine buffer, set up the keymap and so on."
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
693 (if xmine-buffer (kill-buffer xmine-buffer))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
694 (setq xmine-buffer (get-buffer-create "XEmacs Mine"))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
695 (save-excursion
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
696 (set-buffer xmine-buffer)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
697 (kill-all-local-variables)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
698 (make-local-variable 'annotation-local-map-default)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
699 (setq truncate-lines 't)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
700 (setq major-mode 'xmine-mode)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
701 (setq mode-name "XMine")
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
702 (put 'xmine-mode 'mode-class 'special)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
703 (use-local-map xmine-keymap)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
704 (buffer-disable-undo (current-buffer))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
705 (setq annotation-local-map-default
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
706 (let ((map (make-sparse-keymap)))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
707 (set-keymap-name map 'annotation-local-map)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
708 (define-key map 'button1 'xmine-activate-function-button)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
709 (define-key map 'button2 'xmine-activate-function-button)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
710 (define-key map 'button3 'xmine-activate-function-button)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
711 map))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
712 (run-hooks 'xmine-mode-hook)))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
713
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
714 ;;; The keyboard navigation.
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
715
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
716 (defun xmine-select-button (ext)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
717 (let ((flagged (extent-property ext 'xmine-flagged))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
718 (hidden (extent-property ext 'xmine-hidden))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
719 sel-glyph)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
720 (setq sel-glyph (if hidden
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
721 (if flagged xmine-flagged-sel-glyph
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
722 xmine-up-sel-glyph)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
723 (extent-property ext 'xmine-sel-glyph)))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
724 (if xmine-key-sel-button
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
725 (set-annotation-glyph xmine-key-sel-button
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
726 (extent-property xmine-key-sel-button
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
727 'xmine-non-selected-glyph)))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
728 (set-extent-property ext 'xmine-non-selected-glyph
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
729 (annotation-glyph ext))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
730 (set-annotation-glyph ext sel-glyph)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
731 (setq xmine-key-sel-button ext)))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
732
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
733 (defun xmine-key-action1 ()
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
734 (interactive)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
735 (let ((action (extent-property xmine-key-sel-button 'action1)))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
736 (if action
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
737 (funcall action xmine-key-sel-button))))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
738
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
739 (defun xmine-key-action2 ()
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
740 (interactive)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
741 (let ((action (extent-property xmine-key-sel-button 'action2)))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
742 (if action
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
743 (funcall action xmine-key-sel-button))))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
744
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
745 (defun xmine-key-action3 ()
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
746 (interactive)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
747 (let ((action (extent-property xmine-key-sel-button 'action3)))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
748 (if action
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
749 (funcall action xmine-key-sel-button))))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
750
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
751 (defun xmine-key-quit ()
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
752 (interactive)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
753 (kill-buffer (current-buffer)))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
754
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
755 (defun xmine-key-new ()
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
756 (interactive)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
757 (xmine-field-create))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
758
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
759 (defun xmine-key-down-right ()
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
760 (interactive)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
761 (xmine-key-down)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
762 (xmine-key-right))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
763
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
764 (defun xmine-key-down-left ()
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
765 (interactive)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
766 (xmine-key-down)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
767 (xmine-key-left))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
768
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
769 (defun xmine-key-up-right ()
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
770 (interactive)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
771 (xmine-key-up)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
772 (xmine-key-right))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
773
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
774 (defun xmine-key-up-left ()
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
775 (interactive)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
776 (xmine-key-up)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
777 (xmine-key-left))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
778
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
779 (defun xmine-key-down ()
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
780 (interactive)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
781 (let* ((x (extent-property xmine-key-sel-button 'xmine-x))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
782 (y (extent-property xmine-key-sel-button 'xmine-y))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
783 (ext (xmine-field-button-at x (1+ y))))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
784 (if ext (xmine-select-button ext)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
785 (xmine-select-button (xmine-field-button-at x 1)))))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
786
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
787 (defun xmine-key-up ()
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
788 (interactive)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
789 (let* ((x (extent-property xmine-key-sel-button 'xmine-x))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
790 (y (extent-property xmine-key-sel-button 'xmine-y))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
791 (ext (xmine-field-button-at x (1- y))))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
792 (if ext (xmine-select-button ext)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
793 (xmine-select-button (xmine-field-button-at x xmine-height)))))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
794
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
795 (defun xmine-key-right ()
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
796 (interactive)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
797 (let* ((x (extent-property xmine-key-sel-button 'xmine-x))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
798 (y (extent-property xmine-key-sel-button 'xmine-y))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
799 (ext (xmine-field-button-at (1+ x) y)))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
800 (if ext (xmine-select-button ext)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
801 (xmine-select-button (xmine-field-button-at 1 y)))))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
802
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
803 (defun xmine-key-left ()
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
804 (interactive)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
805 (let* ((x (extent-property xmine-key-sel-button 'xmine-x))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
806 (y (extent-property xmine-key-sel-button 'xmine-y))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
807 (ext (xmine-field-button-at (1- x) y)))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
808 (if ext (xmine-select-button ext)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
809 (xmine-select-button (xmine-field-button-at xmine-width y)))))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
810
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
811 (provide 'xmine)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents:
diff changeset
812