[elisp」puyopuyo作成中

というわけで、puyopuyo作成中。作成方針は、以下の2点。

  • tetrisのソースで借りれそうな場所は思いっきり借りる
    • おもいっきりつかえそうなんで
  • puyopuyoのアルゴリズム用関数作成
    • 前解説してあったサイト見たことあるし

んで、現在の状況がこんな感じ。defcustomとか、defvarは思いっきりtetrisの拝借できるんで、考えるところは主にfunction部分. コピペはしてないんで、ひたすらつかえそうなコードを打ちまくった気がする。

;;; puyopuyo.el ---- implementation of PuyoPuyo for Emacs

;;   puyopuyo nanndayo dayo!
;;   2007 Replore, Inc.

;;   I made this software for the purpose of doing puyopuyo on the Emacs!
  
;;   author replore 2007/07/28
;;   BSD license or GNU license or MIT license
;;   I do not know which is good for the most.
;;

;;; Commentary:

;;; Code;

(eval-when-compile
  (require 'cl))

(require 'gamegrid)

;; ;;;;;;;;;;;;; customization variables ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


(defgroup puyopuyo nil
  "Play a game of puyopuyo."
  :prefix "puyopuyo-"
  :group 'games)

(defcustom puyopuyo-use-glyphs t
  "*Non-nil means use glyphs when available."
  :group 'puyopuyo
  :type 'boolean)

(defcustom puyopuyo-use-color t
  "*Non-nil means use color when available."
  :group 'puyopuyo
  :type 'boolean)

(defcustom puyopuyo-draw-border-with-glyphs t
 "*NOn-nil means draw a border even when using glyphs."
 :group 'puyopuyo
 :type 'boolean)

;;; speed customization ;;;

(defcustom puyopuyo-default-tick-period 0.3
  "*The default time taken for a shape to drop one row."
  :group 'puyopuyo
  :type 'number)

(defcustom puyopuyo-update-speed-function
  'puyopuyo-default-update-speed-function
  " I will not use this code"
  :group 'puyopuyo
  :type 'function)

(defcustom puyopuyo-mode-hook nil
  "Hook run upon starting puyopuyo."
  :group 'puyopuyo
  :type 'hook)

;(defcustom puyopuyo-tty-colors
;  [nil "blue" "white" "yellow" "magenta" "cyan" "green" "red"] 
;  "vector of colors of the various shapes in text mode
;  Element 0 is ignored"
;  :group 'puyopuyo
;  :type (let ((names '("Shape 1")))
;


(defcustom puyopuyo-x-colors
  [nil [0 0 1] [0.7 0 1] [1 1 0] [1 0 1] [0 1 1] [0 1 0] [1 0 0]]
  "vector of colors of the various shapes Element 0 is ignored."
  :group 'puyopuyo
  :type 'sexp)

(defcustom puyopuyo-buffer-name "*puyopuyo*"
  "Name used for puyopuyo buffer."
  :group 'puyopuyo
  :type 'string)

(defcustom puyopuyo-buffer-width 40
  "Width of used portion of buffer."
  :group 'puyopuyo
  :type 'number)

(defcustom puyopuyo-buffer-height 22
  "Height of used portion of buffer."
  :group 'puyopuyo
  :type 'number)

(defcustom puyopuyo-width 10
  "WIdth of playing area."
  :group 'puyopuyo
  :type 'number)

(defcustom puyopuyo-height 20
  "Height of playing area."
  :group 'puyopuyo
  :type 'number)

; I do not this can be used for puyopuyo program.
(defcustom puyopuyo-top-left-x 3
  "X position of top left of playing area."
  :group  'puyopuyo
  :type 'number)

(defvar puyopuyo-next-x (+ (* 2 puyopuyo-top-left-x) puyopuyo-width)
  "X position of next shape.")

(defvar puyopuyo-next-y puyopuyo-top-left-y
  "Y position of next shape.")

(defvar puyopuyo-score-x puyopuyo-next-x
  "X position of score.")

(defvar puyopuyo-score-y (+ puyopuyo-next-y 6)
  "Y position of score.")

(defvar puyopuyo-score-file "puyopuyo-scores"
  "File for holding high scores.")


;; ;;;;;;;;;;;;; display options ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; can be use this code directly?

(defvar puyopuyo-blank-options
  '(((glyph colorize)
     (t ?\040))
    ((color-x color-x)
     (mono-x grid-x)
     (color-tty color-tty))
    (((glyph color-x) [0 0 0])
     (color-tty "black"))))

(defvar puyopuyo-cell-options
  '(((glyph colorize)
     (emacs-tty ?O)
     (t ?\040))
    ((color-x color-x)
     (mono-x mono-x)
     (color-tty color-tty)
     (mono-tty mono-tty))
    ;; color information is taken from puyopuyo-x-colors and puyopuyo-tty-colors
    ))

(defvar puyopuyo-border-options
  '(((glyph colorize)
     (t ?\+))
    ((color-x color-x)
     (mono-x grid-x)
     (color-tty color-tty))
    (((glyph color-x) [0.5 0.5 0.5])
     (color-tty "white"))))

(defvar puyopuyo-space-options
  '(((t ?\040))
    nil
    nil))

;; ;;;;;;;;;;;;; constants ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


(defconst puyopuo-blank 0)
(defconst puyopuyo-border 8)
(defconst puyopuyo-space 9)


(defun puyopuyo-default-update-speed-function (shapes rows)
  (/ 20.0 (+ 50.0 rows)))


;; ;;;;;;;;;;;;; variables ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defvar puyopuyo-shape 0)
(defvar puyopuyo-rot 0)
(defvar puyopuyo-next-shape 0)
(defvar puyopuyo-n-shapes 0)
(defvar puyopuyo-n-rows 0)
(defvar puyopuyo-score 0)
(defvar puyopuyo-pos-x 0)
(defvar puyopuyo-pos-y 0)
(defvar puyopuyo-paused nil)

(make-variable-buffer-local 'puyopuyo-shape)
(make-variable-buffer-local 'puyopuyo-rot)
(make-variable-buffer-local 'puyopuyo-next-shape)
(make-variable-buffer-local 'puyopuyo-n-shapes)
(make-variable-buffer-local 'puyopuyo-n-rows)
(make-variable-buffer-local 'puyopuyo-score)
(make-variable-buffer-local 'puyopuyo-pos-x)
(make-variable-buffer-local 'puyopuyo-pos-y)
(make-variable-buffer-local 'puyopuyo-paused)


;; ;;;;;;;;;;;;; keymaps ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defvar puyopuyo-mode-map
  (make-sparse-keymap 'puyopuyo-mode-map))

(define-key puyopuyo-mode-map "s"		'puyopuyo-start-game)
(define-key puyopuyo-mode-map "e"		'puyopuyo-end-game)
(define-key puyopuyo-mode-map "p"		'puyopuyo-pause-game)
; default "" 'puyopuyo-move-bottom
(define-key puyopuyo-mode-map "b"		'puyopuyo-move-bottom)
(define-key puyopuyo-mode-map "h"	'puyopuyo-move-left)
(define-key puyopuyo-mode-map "l"	'puyopuyo-move-right)
(define-key puyopuyo-mode-map "k"	'puyopuyo-rotate-prev)
(define-key puyopuyo-mode-map "j"	'puyopuyo-rotate-next)
; It's not good way, I think!

(defvar puyopuyo-null-map
  (make-sparse-keymap 'puyopuyo-null-map))

(define-key puyopuyo-null-map "n"		'puyopuyo-start-game)

;; ;;;;;;;;;;;;;;;; game functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun puyopuyo-display-options ())

(defun puyopuyo-get-tick-period ())

(defun puyopuyo-get-shape-cell (x y))

(defun puyopuyo-shape-width ())

(defun puyopuyo-shape-height ())

(defun puyopuyo-draw-score ())

(defun puyopuyo-update-score ())

(defun puyopuyo-new-shape ())

(defun puyopuyo-draw-next-shape ())

(defun puyopuyo-draw-shape ())

(defun puyopuyo-erase-shape ())

(defun puyopuyo-test-shape ())

(defun puyopuyo-full-row (y))

(defun puyopuyo-shift-row (y))

(defun puyopuyo-shift-down ())

(defun puyopuyo-draw-border-p ())

(defun puyopuyo-init-buffer ())

(defun puyopuyo-reset-game())

(defun puyopuyo-shape-done ())

(defun puyopuyo-update-game (tetris-buffer))

(defun puyopuyo-move-bottom ())

(defun puyopuyo-move-left ())

(defun puyopuyo-move-right ())

(defun puyopuyo-rotate-prev ())

(defun puyopuyo-rotate-next ())

(defun puyopuyo-end-game ())


(defun puyopuyo-start-game ())

(defun puyopuyo-pause-game ())

(defun puyopuyo-active-p ())

(defun puyopuyo-mode ())

;;;###autoload
(defun puyopuyo()
  "This is a game. nanndayo! dayo!" )


(provide 'puyopuyo)

こんな感じでいいのだろうか。次は関数の実装といったとこかなぁ