>From 4caa9c202fd67fdd3e31448dfd47973efafcaa66 Mon Sep 17 00:00:00 2001 From: Dieter Deyke 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 -;; 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