all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [ELPA] Patches for sokoban 1.4
@ 2017-05-27 10:58 Dieter Deyke
  0 siblings, 0 replies; only message in thread
From: Dieter Deyke @ 2017-05-27 10:58 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 721 bytes --]

Hi,

while I was playing sokoban from ELPA, I had the need for some local
patches:

1) fix off-by-1 error in sokoban-draw-score which caused on-screen score
   to be truncated

2) save sokoban-level when a level is completed, restore sokoban-level
   when a game is started

This allowed me to continue the game on the next day without me having
to remember what level I was on.

Eventually I finished all levels and looked on the net for new level
files. Having found some required:

3) allow for levels which are wider and higher, and for levels where the
   player character would already be on a target field at start

These 3 patches are attached to this mail. If they are useful, someone
could apply them to ELPA.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-fix-off-by-1-error-in-sokoban-draw-score-which-cause.patch --]
[-- Type: text/x-diff, Size: 1511 bytes --]

From 96ca5427cd2b950008a55bb5586702d40f5c078e Mon Sep 17 00:00:00 2001
From: Dieter Deyke <dieter.deyke@gmail.com>
Date: Thu, 25 May 2017 13:27:08 +0200
Subject: [PATCH] fix off-by-1 error in sokoban-draw-score which caused
 on-screen score to be truncated

---
 packages/sokoban/sokoban.el | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/packages/sokoban/sokoban.el b/packages/sokoban/sokoban.el
index 6e8bee25c..ae6f845cf 100644
--- a/packages/sokoban/sokoban.el
+++ b/packages/sokoban/sokoban.el
@@ -1,9 +1,9 @@
 ;;; sokoban.el --- Implementation of Sokoban for Emacs.
 
-;; Copyright (C) 1998, 2013 Free Software Foundation, Inc.
+;; Copyright (C) 1998, 2013, 2017 Free Software Foundation, Inc.
 
 ;; Author: Glynn Clements <glynn.clements@xemacs.org>
-;; Version: 1.4
+;; Version: 1.4.1
 ;; Created: 1997-09-11
 ;; Keywords: games
 ;; Package-Type: multi
@@ -41,6 +41,8 @@
 ;; Modified: 1998-06-04, added `undo' feature
 ;;   added number of blocks done/total to score and modeline
 ;; Modified: 2003-06-14, update email address, remove URL
+;; Modified: 2017-05-25, fix off-by-1 error in sokoban-draw-score which
+;;   caused on-screen score to be truncated
 
 ;; Tested with XEmacs 20.3/4/5 and Emacs 19.34
 
@@ -517,7 +519,7 @@ static char * player_xpm[] = {
 			 (format "Done:   %d/%d"
 				 sokoban-done
 				 sokoban-targets))))
-    (dotimes (y 2)
+    (dotimes (y 3)
       (let* ((string (aref strings y))
 	     (len (length string)))
 	(dotimes (x len)
-- 
2.11.0


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0002-save-sokoban-level-when-a-level-is-completed-restore.patch --]
[-- Type: text/x-diff, Size: 2308 bytes --]

From 4caa9c202fd67fdd3e31448dfd47973efafcaa66 Mon Sep 17 00:00:00 2001
From: Dieter Deyke <dieter.deyke@gmail.com>
Date: Sat, 27 May 2017 10:45:38 +0200
Subject: [PATCH] save sokoban-level when a level is completed, restore
 sokoban-level when game is started

---
 packages/sokoban/sokoban.el | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/packages/sokoban/sokoban.el b/packages/sokoban/sokoban.el
index ae6f845cf..3575d2818 100644
--- a/packages/sokoban/sokoban.el
+++ b/packages/sokoban/sokoban.el
@@ -3,7 +3,7 @@
 ;; Copyright (C) 1998, 2013, 2017 Free Software Foundation, Inc.
 
 ;; Author: Glynn Clements <glynn.clements@xemacs.org>
-;; Version: 1.4.1
+;; Version: 1.4.2
 ;; Created: 1997-09-11
 ;; Keywords: games
 ;; Package-Type: multi
@@ -43,6 +43,8 @@
 ;; Modified: 2003-06-14, update email address, remove URL
 ;; Modified: 2017-05-25, fix off-by-1 error in sokoban-draw-score which
 ;;   caused on-screen score to be truncated
+;; Modified: 2017-05-27, save sokoban-level when a level is completed,
+;;   restore sokoban-level when game is started
 
 ;; Tested with XEmacs 20.3/4/5 and Emacs 19.34
 
@@ -96,6 +98,8 @@
 
 (defvar sokoban-level-data nil)
 
+(defconst sokoban-state-filename (locate-user-emacs-file "sokoban-state"))
+
 ;; ;;;;;;;;;;;;; constants ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 (defconst sokoban-floor-xpm "\
@@ -616,6 +620,9 @@ static char * player_xpm[] = {
 			(incf sokoban-done))
 		    (sokoban-add-push dx dy)
 		    (cond ((= sokoban-done sokoban-targets)
+                           (let ((level sokoban-level))
+                             (with-temp-file sokoban-state-filename
+                               (print level (current-buffer))))
 			   (sit-for 3)
 			   (sokoban-next-level))))))))))
 
@@ -774,7 +781,14 @@ sokoban-mode keybindings:
   (switch-to-buffer sokoban-buffer-name)
   (gamegrid-kill-timer)
   (sokoban-mode)
-  (sokoban-start-game))
+  (setq sokoban-level 0)
+  (if (file-exists-p sokoban-state-filename)
+    (setq sokoban-level
+          (with-temp-buffer
+            (insert-file-contents sokoban-state-filename)
+            (goto-char (point-min))
+            (read (current-buffer)))))
+  (sokoban-next-level))
 
 ;;;###autoload
 (unless (featurep 'xemacs)
-- 
2.11.0


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: 0003-allow-for-player-to-start-on-a-target-allow-for-wide.patch --]
[-- Type: text/x-diff, Size: 3164 bytes --]

From ab2c9cfaed47c56ed213e1efbbde6fe9bae5a86e Mon Sep 17 00:00:00 2001
From: Dieter Deyke <dieter.deyke@gmail.com>
Date: Sat, 27 May 2017 12:43:34 +0200
Subject: [PATCH] allow for player to start on a target, allow for wider and
 higher levels

---
 packages/sokoban/sokoban.el | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)

diff --git a/packages/sokoban/sokoban.el b/packages/sokoban/sokoban.el
index 3575d2818..d59de952c 100644
--- a/packages/sokoban/sokoban.el
+++ b/packages/sokoban/sokoban.el
@@ -3,7 +3,7 @@
 ;; Copyright (C) 1998, 2013, 2017 Free Software Foundation, Inc.
 
 ;; Author: Glynn Clements <glynn.clements@xemacs.org>
-;; Version: 1.4.2
+;; Version: 1.4.3
 ;; Created: 1997-09-11
 ;; Keywords: games
 ;; Package-Type: multi
@@ -45,6 +45,8 @@
 ;;   caused on-screen score to be truncated
 ;; Modified: 2017-05-27, save sokoban-level when a level is completed,
 ;;   restore sokoban-level when game is started
+;; Modified: 2017-05-27, allow for player to start on a target,
+;;   allow for wider and higher levels
 
 ;; Tested with XEmacs 20.3/4/5 and Emacs 19.34
 
@@ -87,14 +89,14 @@
               (and (file-exists-p file) file))
 	(expand-file-name "sokoban.levels" data-directory))))
 
-(defvar sokoban-width 20)
-(defvar sokoban-height 16)
+(defvar sokoban-width 27)
+(defvar sokoban-height 20)
 
-(defvar sokoban-buffer-width 20)
-(defvar sokoban-buffer-height 20)
+(defvar sokoban-buffer-width sokoban-width)
+(defvar sokoban-buffer-height (+ 4 sokoban-height))
 
 (defvar sokoban-score-x 0)
-(defvar sokoban-score-y 17)
+(defvar sokoban-score-y (+ 1 sokoban-height))
 
 (defvar sokoban-level-data nil)
 
@@ -309,13 +311,14 @@ static char * player_xpm[] = {
 };
 ")
 
-(defconst sokoban-floor ?\+)
+(defconst sokoban-floor ?\&)
 ;; note - space character in level file is also allowed to indicate floor
 (defconst sokoban-target ?\.)
 (defconst sokoban-wall ?\#)
 (defconst sokoban-block ?\$)
 (defconst sokoban-player ?\@)
 (defconst sokoban-block-on-target ?\*)
+(defconst sokoban-player-on-target ?\+)
 
 ;; ;;;;;;;;;;;;; display options ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
@@ -488,7 +491,8 @@ static char * player_xpm[] = {
     (dotimes (x sokoban-width)
       (let ((c (aref (aref sokoban-level-map y) x)))
 	(cond
-	 ((= c sokoban-target)
+	 ((or (= c sokoban-target)
+	      (= c sokoban-player-on-target))
 	  (incf sokoban-targets))
 	 ((= c sokoban-block-on-target)
 	  (incf sokoban-targets)
@@ -499,7 +503,8 @@ static char * player_xpm[] = {
 (defun sokoban-get-floor (x y)
   (let ((c (aref (aref sokoban-level-map y) x)))
     (if (or (= c sokoban-target)
-	    (= c sokoban-block-on-target))
+	    (= c sokoban-block-on-target)
+	    (= c sokoban-player-on-target))
 	sokoban-target
       sokoban-floor)))
 
@@ -513,6 +518,10 @@ static char * player_xpm[] = {
 	(if (= c sokoban-player)
 	    (setq sokoban-x x
 		  sokoban-y y))
+	(if (= c sokoban-player-on-target)
+	    (setq sokoban-x x
+                  sokoban-y y
+                  c sokoban-player))
 	(if (= c sokoban-block-on-target)
 	    (setq c sokoban-block))
 	(gamegrid-set-cell x y c)))))
-- 
2.11.0


[-- Attachment #5: Type: text/plain, Size: 118 bytes --]


-- 
Dieter Deyke
mailto:dieter.deyke@gmail.com
Get my Gnupg key:
gpg --keyserver keys.gnupg.net --recv-keys B116EA20

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2017-05-27 10:58 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-27 10:58 [ELPA] Patches for sokoban 1.4 Dieter Deyke

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.