aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThien-Thi Nguyen2007-09-14 18:11:36 +0000
committerThien-Thi Nguyen2007-09-14 18:11:36 +0000
commita4fcacde1e493e0b38a246b07f34cd4aa85ac0e7 (patch)
tree6f03cd17905bb50d50f60f9b8566ad0953d3836b
parent34acda03c2ae306db56217f8259180381eee4d49 (diff)
downloademacs-a4fcacde1e493e0b38a246b07f34cd4aa85ac0e7.tar.gz
emacs-a4fcacde1e493e0b38a246b07f34cd4aa85ac0e7.zip
(bubbles-version): Bump value to "0.5".
(bubbles-mode-map): Move define-key statements here. (bubbles-game-theme-menu): Ditto. (bubbles-graphics-theme-menu): Ditto. (bubbles-menu): Ditto. (bubbles-mode): Initialize buffer-undo-list, redisplay. (bubbles--initialize): Reset buffer-undo-list, redisplay. (bubbles-plop): Set buffer-undo-list, redisplay. (bubbles-undo): Reset buffer-undo-list, redisplay. (bubbles--show-images): Take care of missing text properties.
-rw-r--r--lisp/ChangeLog13
-rw-r--r--lisp/play/bubbles.el200
2 files changed, 126 insertions, 87 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 54aba3bf7c3..5c33c9c4db4 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,16 @@
12007-09-14 Ulf Jasper <ulf.jasper@web.de>
2
3 * play/bubbles.el (bubbles-version): Bump value to "0.5".
4 (bubbles-mode-map): Move define-key statements here.
5 (bubbles-game-theme-menu): Ditto.
6 (bubbles-graphics-theme-menu): Ditto.
7 (bubbles-menu): Ditto.
8 (bubbles-mode): Initialize buffer-undo-list, redisplay.
9 (bubbles--initialize): Reset buffer-undo-list, redisplay.
10 (bubbles-plop): Set buffer-undo-list, redisplay.
11 (bubbles-undo): Reset buffer-undo-list, redisplay.
12 (bubbles--show-images): Take care of missing text properties.
13
12007-09-14 Glenn Morris <rgm@gnu.org> 142007-09-14 Glenn Morris <rgm@gnu.org>
2 15
3 * startup.el (fancy-startup-text, fancy-about-text): Fix face 16 * startup.el (fancy-startup-text, fancy-about-text): Fix face
diff --git a/lisp/play/bubbles.el b/lisp/play/bubbles.el
index 00cb6e04397..5f8709d17b7 100644
--- a/lisp/play/bubbles.el
+++ b/lisp/play/bubbles.el
@@ -43,6 +43,9 @@
43 43
44;;; History: 44;;; History:
45 45
46;; 0.5 (2007-09-14)
47;; - Minor bugfixes.
48
46;; 0.4 (2007-08-27) 49;; 0.4 (2007-08-27)
47;; - Allow for undoing last move. 50;; - Allow for undoing last move.
48;; - Bonus for removing all bubbles. 51;; - Bonus for removing all bubbles.
@@ -78,7 +81,7 @@
78 81
79;;; Code: 82;;; Code:
80 83
81(defconst bubbles-version "0.4" "Version number of bubbles.el.") 84(defconst bubbles-version "0.5" "Version number of bubbles.el.")
82 85
83(require 'gamegrid) 86(require 'gamegrid)
84(require 'cl) 87(require 'cl)
@@ -824,89 +827,98 @@ static char * dot3d_xpm[] = {
824 (bubbles--initialize-images) 827 (bubbles--initialize-images)
825 (bubbles--update-faces-or-images)) 828 (bubbles--update-faces-or-images))
826 829
827;; bubbles mode map
828(defvar bubbles-mode-map
829 (make-keymap 'bubbles-mode-map))
830(define-key bubbles-mode-map "q" 'bubbles-quit)
831(define-key bubbles-mode-map "\n" 'bubbles-plop)
832(define-key bubbles-mode-map " " 'bubbles-plop)
833(define-key bubbles-mode-map [double-down-mouse-1] 'bubbles-plop)
834(define-key bubbles-mode-map [mouse-2] 'bubbles-plop)
835(define-key bubbles-mode-map "\C-m" 'bubbles-plop)
836(define-key bubbles-mode-map "u" 'bubbles-undo)
837(define-key bubbles-mode-map "p" 'previous-line)
838(define-key bubbles-mode-map "n" 'next-line)
839(define-key bubbles-mode-map "f" 'forward-char)
840(define-key bubbles-mode-map "b" 'backward-char)
841
842
843;; game theme menu 830;; game theme menu
844(defvar bubbles-game-theme-menu (make-sparse-keymap "Game Theme")) 831(defvar bubbles-game-theme-menu
845(define-key bubbles-game-theme-menu [bubbles-set-game-userdefined] 832 (let ((menu (make-sparse-keymap "Game Theme")))
846 (list 'menu-item "User defined" 'bubbles-set-game-userdefined 833 (define-key menu [bubbles-set-game-userdefined]
847 :button '(:radio . (eq bubbles-game-theme 'user-defined)))) 834 (list 'menu-item "User defined" 'bubbles-set-game-userdefined
848(define-key bubbles-game-theme-menu [bubbles-set-game-hard] 835 :button '(:radio . (eq bubbles-game-theme 'user-defined))))
849 (list 'menu-item "Hard" 'bubbles-set-game-hard 836 (define-key menu [bubbles-set-game-hard]
850 :button '(:radio . (eq bubbles-game-theme 'hard)))) 837 (list 'menu-item "Hard" 'bubbles-set-game-hard
851(define-key bubbles-game-theme-menu [bubbles-set-game-difficult] 838 :button '(:radio . (eq bubbles-game-theme 'hard))))
852 (list 'menu-item "Difficult" 'bubbles-set-game-difficult 839 (define-key menu [bubbles-set-game-difficult]
853 :button '(:radio . (eq bubbles-game-theme 'difficult)))) 840 (list 'menu-item "Difficult" 'bubbles-set-game-difficult
854(define-key bubbles-game-theme-menu [bubbles-set-game-medium] 841 :button '(:radio . (eq bubbles-game-theme 'difficult))))
855 (list 'menu-item "Medium" 'bubbles-set-game-medium 842 (define-key menu [bubbles-set-game-medium]
856 :button '(:radio . (eq bubbles-game-theme 'medium)))) 843 (list 'menu-item "Medium" 'bubbles-set-game-medium
857(define-key bubbles-game-theme-menu [bubbles-set-game-easy] 844 :button '(:radio . (eq bubbles-game-theme 'medium))))
858 (list 'menu-item "Easy" 'bubbles-set-game-easy 845 (define-key menu [bubbles-set-game-easy]
859 :button '(:radio . (eq bubbles-game-theme 'easy)))) 846 (list 'menu-item "Easy" 'bubbles-set-game-easy
847 :button '(:radio . (eq bubbles-game-theme 'easy))))
848 menu)
849 "Map for bubbles game theme menu.")
860 850
861;; graphics theme menu 851;; graphics theme menu
862(defvar bubbles-graphics-theme-menu (make-sparse-keymap "Graphics Theme")) 852(defvar bubbles-graphics-theme-menu
863(define-key bubbles-graphics-theme-menu [bubbles-set-graphics-theme-ascii] 853 (let ((menu (make-sparse-keymap "Graphics Theme")))
864 (list 'menu-item "ASCII" 'bubbles-set-graphics-theme-ascii 854 (define-key menu [bubbles-set-graphics-theme-ascii]
865 :button '(:radio . (eq bubbles-graphics-theme 'ascii)))) 855 (list 'menu-item "ASCII" 'bubbles-set-graphics-theme-ascii
866(define-key bubbles-graphics-theme-menu [bubbles-set-graphics-theme-emacs] 856 :button '(:radio . (eq bubbles-graphics-theme 'ascii))))
867 (list 'menu-item "Emacs" 'bubbles-set-graphics-theme-emacs 857 (define-key menu [bubbles-set-graphics-theme-emacs]
868 :button '(:radio . (eq bubbles-graphics-theme 'emacs)))) 858 (list 'menu-item "Emacs" 'bubbles-set-graphics-theme-emacs
869(define-key bubbles-graphics-theme-menu [bubbles-set-graphics-theme-balls] 859 :button '(:radio . (eq bubbles-graphics-theme 'emacs))))
870 (list 'menu-item "Balls" 'bubbles-set-graphics-theme-balls 860 (define-key menu [bubbles-set-graphics-theme-balls]
871 :button '(:radio . (eq bubbles-graphics-theme 'balls)))) 861 (list 'menu-item "Balls" 'bubbles-set-graphics-theme-balls
872(define-key bubbles-graphics-theme-menu [bubbles-set-graphics-theme-diamonds] 862 :button '(:radio . (eq bubbles-graphics-theme 'balls))))
873 (list 'menu-item "Diamonds" 'bubbles-set-graphics-theme-diamonds 863 (define-key menu [bubbles-set-graphics-theme-diamonds]
874 :button '(:radio . (eq bubbles-graphics-theme 'diamonds)))) 864 (list 'menu-item "Diamonds" 'bubbles-set-graphics-theme-diamonds
875(define-key bubbles-graphics-theme-menu [bubbles-set-graphics-theme-squares] 865 :button '(:radio . (eq bubbles-graphics-theme 'diamonds))))
876 (list 'menu-item "Squares" 'bubbles-set-graphics-theme-squares 866 (define-key menu [bubbles-set-graphics-theme-squares]
877 :button '(:radio . (eq bubbles-graphics-theme 'squares)))) 867 (list 'menu-item "Squares" 'bubbles-set-graphics-theme-squares
878(define-key bubbles-graphics-theme-menu [bubbles-set-graphics-theme-circles] 868 :button '(:radio . (eq bubbles-graphics-theme 'squares))))
879 (list 'menu-item "Circles" 'bubbles-set-graphics-theme-circles 869 (define-key menu [bubbles-set-graphics-theme-circles]
880 :button '(:radio . (eq bubbles-graphics-theme 'circles)))) 870 (list 'menu-item "Circles" 'bubbles-set-graphics-theme-circles
871 :button '(:radio . (eq bubbles-graphics-theme 'circles))))
872 menu)
873 "Map for bubbles graphics theme menu.")
881 874
882;; menu 875;; menu
883(defvar bubbles-menu (make-sparse-keymap "Bubbles")) 876(defvar bubbles-menu
884(define-key bubbles-menu [bubbles-quit] 877 (let ((menu (make-sparse-keymap "Bubbles")))
885 (list 'menu-item "Quit" 'bubbles-quit)) 878 (define-key menu [bubbles-quit]
886(define-key bubbles-menu [bubbles] 879 (list 'menu-item "Quit" 'bubbles-quit))
887 (list 'menu-item "New game" 'bubbles)) 880 (define-key menu [bubbles]
888(define-key bubbles-menu [bubbles-separator-1] 881 (list 'menu-item "New game" 'bubbles))
889 '("--")) 882 (define-key menu [bubbles-separator-1]
890(define-key bubbles-menu [bubbles-save-settings] 883 '("--"))
891 (list 'menu-item "Save all settings" 'bubbles-save-settings)) 884 (define-key menu [bubbles-save-settings]
892(define-key bubbles-menu [bubbles-customize] 885 (list 'menu-item "Save all settings" 'bubbles-save-settings))
893 (list 'menu-item "Edit all settings" 'bubbles-customize)) 886 (define-key menu [bubbles-customize]
894(define-key bubbles-menu [bubbles-game-theme-menu] 887 (list 'menu-item "Edit all settings" 'bubbles-customize))
895 (list 'menu-item "Game Theme" bubbles-game-theme-menu)) 888 (define-key menu [bubbles-game-theme-menu]
896(define-key bubbles-menu [bubbles-graphics-theme-menu] 889 (list 'menu-item "Game Theme" bubbles-game-theme-menu))
897 (list 'menu-item "Graphics Theme" bubbles-graphics-theme-menu 890 (define-key menu [bubbles-graphics-theme-menu]
898 :enable 'bubbles--playing)) 891 (list 'menu-item "Graphics Theme" bubbles-graphics-theme-menu
899(define-key bubbles-menu [bubbles-separator-2] 892 :enable 'bubbles--playing))
900 '("--")) 893 (define-key menu [bubbles-separator-2]
901(define-key bubbles-menu [bubbles-undo] 894 '("--"))
902 (list 'menu-item "Undo last move" 'bubbles-undo 895 (define-key menu [bubbles-undo]
903 :enable '(and bubbles--playing bubbles--save-data))) 896 (list 'menu-item "Undo last move" 'bubbles-undo
904 897 :enable '(and bubbles--playing (listp buffer-undo-list))))
905;; bind menu to mouse 898 menu)
906(define-key bubbles-mode-map [down-mouse-3] bubbles-menu) 899 "Map for bubbles menu.")
907;; Put menu in menu-bar 900
908(define-key bubbles-mode-map [menu-bar Bubbles] 901;; bubbles mode map
909 (cons "Bubbles" bubbles-menu)) 902(defvar bubbles-mode-map
903 (let ((map (make-sparse-keymap 'bubbles-mode-map)))
904;; (suppress-keymap map t)
905 (define-key map "q" 'bubbles-quit)
906 (define-key map "\n" 'bubbles-plop)
907 (define-key map " " 'bubbles-plop)
908 (define-key map [double-down-mouse-1] 'bubbles-plop)
909 (define-key map [mouse-2] 'bubbles-plop)
910 (define-key map "\C-m" 'bubbles-plop)
911 (define-key map "u" 'bubbles-undo)
912 (define-key map "p" 'previous-line)
913 (define-key map "n" 'next-line)
914 (define-key map "f" 'forward-char)
915 (define-key map "b" 'backward-char)
916 ;; bind menu to mouse
917 (define-key map [down-mouse-3] bubbles-menu)
918 ;; Put menu in menu-bar
919 (define-key map [menu-bar Bubbles] (cons "Bubbles" bubbles-menu))
920 map)
921 "Mode map for bubbles.")
910 922
911(defun bubbles-mode () 923(defun bubbles-mode ()
912 "Major mode for playing bubbles. 924 "Major mode for playing bubbles.
@@ -916,7 +928,10 @@ static char * dot3d_xpm[] = {
916 (setq major-mode 'bubbles-mode) 928 (setq major-mode 'bubbles-mode)
917 (setq mode-name "Bubbles") 929 (setq mode-name "Bubbles")
918 (setq buffer-read-only t) 930 (setq buffer-read-only t)
919 (buffer-enable-undo) 931 (buffer-disable-undo)
932 (setq buffer-undo-list t)
933 (force-mode-line-update)
934 (redisplay)
920 (add-hook 'post-command-hook 'bubbles--mark-neighbourhood t t) 935 (add-hook 'post-command-hook 'bubbles--mark-neighbourhood t t)
921 (run-hooks 'bubbles-mode-hook)) 936 (run-hooks 'bubbles-mode-hook))
922 937
@@ -1014,7 +1029,10 @@ Set `bubbles--col-offset' and `bubbles--row-offset'."
1014 (bubbles-mode) 1029 (bubbles-mode)
1015 (bubbles--reset-score) 1030 (bubbles--reset-score)
1016 (bubbles--update-faces-or-images) 1031 (bubbles--update-faces-or-images)
1017 (bubbles--goto 0 0)) 1032 (bubbles--goto 0 0)
1033 (setq buffer-undo-list t)
1034 (force-mode-line-update)
1035 (redisplay))
1018 1036
1019(defun bubbles--initialize-faces () 1037(defun bubbles--initialize-faces ()
1020 "Prepare faces for playing `bubbles'." 1038 "Prepare faces for playing `bubbles'."
@@ -1196,7 +1214,6 @@ Use optional parameter POS instead of point if given."
1196 (when (and bubbles--playing 1214 (when (and bubbles--playing
1197 (> bubbles--neighbourhood-score 0)) 1215 (> bubbles--neighbourhood-score 0))
1198 (setq bubbles--save-data (list bubbles--score (buffer-string))) 1216 (setq bubbles--save-data (list bubbles--score (buffer-string)))
1199 (setq buffer-undo-list '(apply bubbles-undo . nil))
1200 (let ((inhibit-read-only t)) 1217 (let ((inhibit-read-only t))
1201 ;; blank out current neighbourhood 1218 ;; blank out current neighbourhood
1202 (let ((row (bubbles--row (point))) 1219 (let ((row (bubbles--row (point)))
@@ -1245,7 +1262,8 @@ Use optional parameter POS instead of point if given."
1245 (dotimes (j (bubbles--grid-width)) 1262 (dotimes (j (bubbles--grid-width))
1246 (bubbles--goto i j) 1263 (bubbles--goto i j)
1247 (while (get-text-property (point) 'removed) 1264 (while (get-text-property (point) 'removed)
1248 (setq shifted (or (bubbles--shift 'right i j) shifted)))))) 1265 (setq shifted (or (bubbles--shift 'right i j)
1266 shifted))))))
1249 (bubbles--update-faces-or-images) 1267 (bubbles--update-faces-or-images)
1250 (sleep-for 0.5)) 1268 (sleep-for 0.5))
1251 (t ;; default shift-mode 1269 (t ;; default shift-mode
@@ -1259,7 +1277,8 @@ Use optional parameter POS instead of point if given."
1259 (dotimes (k shifted-cols) 1277 (dotimes (k shifted-cols)
1260 (let ((i (- (bubbles--grid-height) 2))) 1278 (let ((i (- (bubbles--grid-height) 2)))
1261 (while (>= i 0) 1279 (while (>= i 0)
1262 (setq shifted (or (bubbles--shift 'right i j) shifted)) 1280 (setq shifted (or (bubbles--shift 'right i j)
1281 shifted))
1263 (setq i (1- i)))))))))) 1282 (setq i (1- i))))))))))
1264 (when shifted 1283 (when shifted
1265 ;;(sleep-for 0.5) 1284 ;;(sleep-for 0.5)
@@ -1267,7 +1286,11 @@ Use optional parameter POS instead of point if given."
1267 (sit-for 0))) 1286 (sit-for 0)))
1268 (put-text-property (point-min) (point-max) 'removed nil) 1287 (put-text-property (point-min) (point-max) 'removed nil)
1269 (unless (bubbles--neighbourhood-available) 1288 (unless (bubbles--neighbourhood-available)
1270 (bubbles--game-over))))) 1289 (bubbles--game-over)))
1290 ;; undo
1291 (setq buffer-undo-list '((apply bubbles-undo . nil)))
1292 (force-mode-line-update)
1293 (redisplay)))
1271 1294
1272(defun bubbles-undo () 1295(defun bubbles-undo ()
1273 "Undo last move." 1296 "Undo last move."
@@ -1279,7 +1302,10 @@ Use optional parameter POS instead of point if given."
1279 (insert (cadr bubbles--save-data)) 1302 (insert (cadr bubbles--save-data))
1280 (bubbles--update-faces-or-images) 1303 (bubbles--update-faces-or-images)
1281 (setq bubbles--score (car bubbles--save-data)) 1304 (setq bubbles--score (car bubbles--save-data))
1282 (goto-char pos)))) 1305 (goto-char pos))
1306 (setq buffer-undo-list t)
1307 (force-mode-line-update)
1308 (redisplay)))
1283 1309
1284(defun bubbles--shift (from row col) 1310(defun bubbles--shift (from row col)
1285 "Move bubbles FROM one side to position ROW COL. 1311 "Move bubbles FROM one side to position ROW COL.
@@ -1408,7 +1434,7 @@ Return t if new char is non-empty."
1408 (dotimes (i (bubbles--grid-height)) 1434 (dotimes (i (bubbles--grid-height))
1409 (dotimes (j (bubbles--grid-width)) 1435 (dotimes (j (bubbles--grid-width))
1410 (forward-char 1) 1436 (forward-char 1)
1411 (let ((index (get-text-property (point) 'index))) 1437 (let ((index (or (get-text-property (point) 'index) -1)))
1412 (let ((img bubbles--empty-image)) 1438 (let ((img bubbles--empty-image))
1413 (if (>= index 0) 1439 (if (>= index 0)
1414 (setq img (nth index bubbles--images))) 1440 (setq img (nth index bubbles--images)))