From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Dieter Deyke Newsgroups: gmane.emacs.devel Subject: [PATCH] elpa/packages/sokoban/sokoban.el Date: Sun, 16 Jul 2017 16:14:23 +0200 Message-ID: <87k2385v0g.fsf@deyke2> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1500214536 8574 195.159.176.226 (16 Jul 2017 14:15:36 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 16 Jul 2017 14:15:36 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Jul 16 16:15:29 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dWkKO-0001SR-TS for ged-emacs-devel@m.gmane.org; Sun, 16 Jul 2017 16:15:21 +0200 Original-Received: from localhost ([::1]:45390 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dWkKU-0007r8-5i for ged-emacs-devel@m.gmane.org; Sun, 16 Jul 2017 10:15:26 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:40118) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dWkJr-0007qY-LY for emacs-devel@gnu.org; Sun, 16 Jul 2017 10:14:48 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dWkJo-0003Jd-90 for emacs-devel@gnu.org; Sun, 16 Jul 2017 10:14:47 -0400 Original-Received: from [195.159.176.226] (port=45982 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dWkJo-0003In-1p for emacs-devel@gnu.org; Sun, 16 Jul 2017 10:14:44 -0400 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1dWkJg-0007hF-HV for emacs-devel@gnu.org; Sun, 16 Jul 2017 16:14:36 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 98 Original-X-Complaints-To: usenet@blaine.gmane.org Cancel-Lock: sha1:9sqeXVvK5AwsHGvk7Fp+/sspbC4= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 195.159.176.226 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:216727 Archived-At: Determine sokoban-width and sokoban-height dynamically This avoids hard-coding sokoban-width and sokoban-height by scanning the level file and finding the correct values dynamically. diff --git a/sokoban.el b/sokoban.el index 3ac1b6e..d29b134 100644 --- a/sokoban.el +++ b/sokoban.el @@ -4,7 +4,7 @@ ;; Author: Glynn Clements ;; Maintainer: Dieter Deyke -;; Version: 1.4.2 +;; Version: 1.4.3 ;; Created: 1997-09-11 ;; Keywords: games ;; Package-Type: multi @@ -71,8 +71,6 @@ (defvar sokoban-buffer-name "*Sokoban*") -(defvar sokoban-temp-buffer-name " Sokoban-tmp") - (defvar sokoban-level-file (if (fboundp 'locate-data-file) (locate-data-file "sokoban.levels") @@ -84,14 +82,14 @@ (and (file-exists-p file) file)) (expand-file-name "sokoban.levels" data-directory)))) -(defvar sokoban-width 27) -(defvar sokoban-height 20) +(defvar sokoban-width) +(defvar sokoban-height) -(defvar sokoban-buffer-width sokoban-width) -(defvar sokoban-buffer-height (+ 4 sokoban-height)) +(defvar sokoban-buffer-width) +(defvar sokoban-buffer-height) -(defvar sokoban-score-x 0) -(defvar sokoban-score-y (1+ sokoban-height)) +(defvar sokoban-score-x) +(defvar sokoban-score-y) (defvar sokoban-level-data nil) @@ -542,6 +540,28 @@ static char * player_on_target_xpm[] = { (if (fboundp 'read-only-mode) (read-only-mode 1) (setq buffer-read-only t)) + + (setq sokoban-width 1 + sokoban-height 1) + (goto-char (point-min)) + (re-search-forward sokoban-level-regexp nil t) + (forward-char) + (let (r) + (while (not (eobp)) + (while (looking-at sokoban-comment-regexp) + (forward-line)) + (setq r 0) + (while (not (or (eobp) + (looking-at sokoban-comment-regexp))) + (incf r) + (setq sokoban-height (max sokoban-height r) + sokoban-width (max sokoban-width (- (line-end-position) (line-beginning-position)))) + (forward-line)))) + (setq sokoban-buffer-width sokoban-width + sokoban-buffer-height (+ 4 sokoban-height) + sokoban-score-x 0 + sokoban-score-y (1+ sokoban-height)) + (goto-char (point-min)) (re-search-forward sokoban-level-regexp nil t) (forward-char) @@ -823,8 +843,7 @@ static char * player_on_target_xpm[] = { (sokoban-draw-score)) (defun sokoban-next-level () - (incf sokoban-level) - (sokoban-restart-level)) + (sokoban-goto-level (1+ sokoban-level))) (defun sokoban-goto-level (level) "Jump to a specified LEVEL." @@ -915,4 +934,3 @@ sokoban-mode keybindings: (provide 'sokoban) ;;; sokoban.el ends here - -- Dieter Deyke mailto:dieter.deyke@gmail.com Get my Gnupg key: gpg --keyserver keys.gnupg.net --recv-keys B116EA20