]> code.delx.au - gnu-emacs/blobdiff - lisp/play/pong.el
Update copyright year to 2015
[gnu-emacs] / lisp / play / pong.el
index 2e17ebff367b070d8cf192e8b13d98d25ce346cc..54d8d537f4702e4c9f441e973fec8e75ed0a7c5c 100644 (file)
@@ -1,7 +1,6 @@
 ;;; pong.el --- classical implementation of pong
 
-;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
-;;   2008, 2009, 2010, 2011  Free Software Foundation, Inc.
+;; Copyright (C) 1999-2015 Free Software Foundation, Inc.
 
 ;; Author: Benjamin Drieu <bdrieu@april.org>
 ;; Keywords: games
@@ -27,7 +26,7 @@
 
 ;;; Code:
 
-(eval-when-compile (require 'cl))
+(eval-when-compile (require 'cl-lib))
 
 (require 'gamegrid)
 
 ;;; Initialize maps
 
 (defvar pong-mode-map
-  (make-sparse-keymap 'pong-mode-map) "Modemap for pong-mode.")
+  (let ((map (make-sparse-keymap 'pong-mode-map)))
+    (define-key map [left]      'pong-move-left)
+    (define-key map [right]     'pong-move-right)
+    (define-key map [up]                'pong-move-up)
+    (define-key map [down]      'pong-move-down)
+    (define-key map pong-left-key  'pong-move-left)
+    (define-key map pong-right-key 'pong-move-right)
+    (define-key map pong-up-key         'pong-move-up)
+    (define-key map pong-down-key  'pong-move-down)
+    (define-key map pong-quit-key  'pong-quit)
+    (define-key map pong-pause-key 'pong-pause)
+    map)
+  "Modemap for pong-mode.")
 
 (defvar pong-null-map
   (make-sparse-keymap 'pong-null-map) "Null map for pong-mode.")
 
-(define-key pong-mode-map [left]        'pong-move-left)
-(define-key pong-mode-map [right]       'pong-move-right)
-(define-key pong-mode-map [up]          'pong-move-up)
-(define-key pong-mode-map [down]        'pong-move-down)
-(define-key pong-mode-map pong-left-key  'pong-move-left)
-(define-key pong-mode-map pong-right-key 'pong-move-right)
-(define-key pong-mode-map pong-up-key   'pong-move-up)
-(define-key pong-mode-map pong-down-key  'pong-move-down)
-(define-key pong-mode-map pong-quit-key  'pong-quit)
-(define-key pong-mode-map pong-pause-key 'pong-pause)
 
 
 ;;; Fun stuff -- The code
 (defun pong-display-options ()
   "Computes display options (required by gamegrid for colors)."
   (let ((options (make-vector 256 nil)))
-    (loop for c from 0 to 255 do
+    (dotimes (c 256)
       (aset options c
-           (cond ((= c pong-blank)
-                  pong-blank-options)
+            (cond ((= c pong-blank)
+                   pong-blank-options)
                   ((= c pong-bat)
-                  pong-bat-options)
+                   pong-bat-options)
                   ((= c pong-ball)
-                  pong-ball-options)
+                   pong-ball-options)
                   ((= c pong-border)
-                  pong-border-options)
+                   pong-border-options)
                   (t
-                  '(nil nil nil)))))
+                   '(nil nil nil)))))
     options))
 
 
                        ?\s)
 
   (let ((buffer-read-only nil))
-    (loop for y from 0 to (1- pong-height) do
-         (loop for x from 0 to (1- pong-width) do
-               (gamegrid-set-cell x y pong-border)))
-    (loop for y from 1 to (- pong-height 2) do
-         (loop for x from 1 to (- pong-width 2) do
-               (gamegrid-set-cell x y pong-blank))))
-
-  (loop for y from pong-bat-player1 to (1- (+ pong-bat-player1 pong-bat-width)) do
-       (gamegrid-set-cell 2 y pong-bat))
-  (loop for y from pong-bat-player2 to (1- (+ pong-bat-player2 pong-bat-width)) do
-       (gamegrid-set-cell (- pong-width 3) y pong-bat)))
+    (dotimes (y pong-height)
+      (dotimes (x pong-width)
+        (gamegrid-set-cell x y pong-border)))
+    (cl-loop for y from 1 to (- pong-height 2) do
+             (cl-loop for x from 1 to (- pong-width 2) do
+                      (gamegrid-set-cell x y pong-blank))))
 
+  (cl-loop for y from pong-bat-player1
+           to (1- (+ pong-bat-player1 pong-bat-width))
+           do (gamegrid-set-cell 2 y pong-bat))
+  (cl-loop for y from pong-bat-player2
+           to (1- (+ pong-bat-player2 pong-bat-width))
+           do (gamegrid-set-cell (- pong-width 3) y pong-bat)))
 
 
 (defun pong-move-left ()
@@ -400,13 +402,12 @@ detection and checks if a player scores."
 
 (defun pong-update-score ()
   "Update score and print it on bottom of the game grid."
-  (let* ((string (format "Score:  %d / %d" pong-score-player1 pong-score-player2))
+  (let* ((string (format "Score:  %d / %d"
+                         pong-score-player1 pong-score-player2))
         (len (length string)))
-    (loop for x from 0 to (1- len) do
-         (if (string-equal (buffer-name (current-buffer)) pong-buffer-name)
-             (gamegrid-set-cell x
-                                pong-height
-                                (aref string x))))))
+    (dotimes (x len)
+      (if (string-equal (buffer-name (current-buffer)) pong-buffer-name)
+          (gamegrid-set-cell x pong-height (aref string x))))))