emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] elpa/packages/sokoban/sokoban.el


From: Stefan Monnier
Subject: Re: [PATCH] elpa/packages/sokoban/sokoban.el
Date: Sun, 16 Jul 2017 12:01:41 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux)

> 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.

Looks good to me.  I'd document also the (apparently) unrelated changes
included, such as the removal of sokoban-temp-buffer-name and the change
to sokoban-next-level.


        Stefan


> 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 <address@hidden>
>  ;; Maintainer: Dieter Deyke <address@hidden>
> -;; 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:address@hidden
> Get my Gnupg key:
> gpg --keyserver keys.gnupg.net --recv-keys B116EA20







reply via email to

[Prev in Thread] Current Thread [Next in Thread]