tetris.el 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. ;;; tetris.el --- implementation of Tetris for Emacs
  2. ;; Copyright (C) 1997, 2001-2012 Free Software Foundation, Inc.
  3. ;; Author: Glynn Clements <glynn@sensei.co.uk>
  4. ;; Version: 2.01
  5. ;; Created: 1997-08-13
  6. ;; Keywords: games
  7. ;; This file is part of GNU Emacs.
  8. ;; GNU Emacs is free software: you can redistribute it and/or modify
  9. ;; it under the terms of the GNU General Public License as published by
  10. ;; the Free Software Foundation, either version 3 of the License, or
  11. ;; (at your option) any later version.
  12. ;; GNU Emacs is distributed in the hope that it will be useful,
  13. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ;; GNU General Public License for more details.
  16. ;; You should have received a copy of the GNU General Public License
  17. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  18. ;;; Commentary:
  19. ;;; Code:
  20. (eval-when-compile
  21. (require 'cl))
  22. (require 'gamegrid)
  23. ;; ;;;;;;;;;;;;; customization variables ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  24. (defgroup tetris nil
  25. "Play a game of Tetris."
  26. :prefix "tetris-"
  27. :group 'games)
  28. (defcustom tetris-use-glyphs t
  29. "Non-nil means use glyphs when available."
  30. :group 'tetris
  31. :type 'boolean)
  32. (defcustom tetris-use-color t
  33. "Non-nil means use color when available."
  34. :group 'tetris
  35. :type 'boolean)
  36. (defcustom tetris-draw-border-with-glyphs t
  37. "Non-nil means draw a border even when using glyphs."
  38. :group 'tetris
  39. :type 'boolean)
  40. (defcustom tetris-default-tick-period 0.3
  41. "The default time taken for a shape to drop one row."
  42. :group 'tetris
  43. :type 'number)
  44. (defcustom tetris-update-speed-function
  45. 'tetris-default-update-speed-function
  46. "Function run whenever the Tetris score changes.
  47. Called with two arguments: (SHAPES ROWS)
  48. SHAPES is the number of shapes which have been dropped.
  49. ROWS is the number of rows which have been completed.
  50. If the return value is a number, it is used as the timer period."
  51. :group 'tetris
  52. :type 'function)
  53. (defcustom tetris-mode-hook nil
  54. "Hook run upon starting Tetris."
  55. :group 'tetris
  56. :type 'hook)
  57. (defcustom tetris-tty-colors
  58. ["blue" "white" "yellow" "magenta" "cyan" "green" "red"]
  59. "Vector of colors of the various shapes in text mode."
  60. :group 'tetris
  61. :type (let ((names `("Shape 1" "Shape 2" "Shape 3"
  62. "Shape 4" "Shape 5" "Shape 6" "Shape 7"))
  63. (result nil))
  64. (while names
  65. (add-to-list 'result
  66. (cons 'choice
  67. (cons :tag
  68. (cons (car names)
  69. (mapcar (lambda (color)
  70. (list 'const color))
  71. (defined-colors)))))
  72. t)
  73. (setq names (cdr names)))
  74. result))
  75. (defcustom tetris-x-colors
  76. [[0 0 1] [0.7 0 1] [1 1 0] [1 0 1] [0 1 1] [0 1 0] [1 0 0]]
  77. "Vector of colors of the various shapes."
  78. :group 'tetris
  79. :type 'sexp)
  80. (defcustom tetris-buffer-name "*Tetris*"
  81. "Name used for Tetris buffer."
  82. :group 'tetris
  83. :type 'string)
  84. (defcustom tetris-buffer-width 30
  85. "Width of used portion of buffer."
  86. :group 'tetris
  87. :type 'number)
  88. (defcustom tetris-buffer-height 22
  89. "Height of used portion of buffer."
  90. :group 'tetris
  91. :type 'number)
  92. (defcustom tetris-width 10
  93. "Width of playing area."
  94. :group 'tetris
  95. :type 'number)
  96. (defcustom tetris-height 20
  97. "Height of playing area."
  98. :group 'tetris
  99. :type 'number)
  100. (defcustom tetris-top-left-x 3
  101. "X position of top left of playing area."
  102. :group 'tetris
  103. :type 'number)
  104. (defcustom tetris-top-left-y 1
  105. "Y position of top left of playing area."
  106. :group 'tetris
  107. :type 'number)
  108. (defvar tetris-next-x (+ (* 2 tetris-top-left-x) tetris-width)
  109. "X position of next shape.")
  110. (defvar tetris-next-y tetris-top-left-y
  111. "Y position of next shape.")
  112. (defvar tetris-score-x tetris-next-x
  113. "X position of score.")
  114. (defvar tetris-score-y (+ tetris-next-y 6)
  115. "Y position of score.")
  116. ;; It is not safe to put this in /tmp.
  117. ;; Someone could make a symlink in /tmp
  118. ;; pointing to a file you don't want to clobber.
  119. (defvar tetris-score-file "tetris-scores"
  120. ;; anybody with a well-connected server want to host this?
  121. ;(defvar tetris-score-file "/anonymous@ftp.pgt.com:/pub/cgw/tetris-scores"
  122. "File for holding high scores.")
  123. ;; ;;;;;;;;;;;;; display options ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  124. (defvar tetris-blank-options
  125. '(((glyph colorize)
  126. (t ?\040))
  127. ((color-x color-x)
  128. (mono-x grid-x)
  129. (color-tty color-tty))
  130. (((glyph color-x) [0 0 0])
  131. (color-tty "black"))))
  132. (defvar tetris-cell-options
  133. '(((glyph colorize)
  134. (emacs-tty ?O)
  135. (t ?\040))
  136. ((color-x color-x)
  137. (mono-x mono-x)
  138. (color-tty color-tty)
  139. (mono-tty mono-tty))
  140. ;; color information is taken from tetris-x-colors and tetris-tty-colors
  141. ))
  142. (defvar tetris-border-options
  143. '(((glyph colorize)
  144. (t ?\+))
  145. ((color-x color-x)
  146. (mono-x grid-x)
  147. (color-tty color-tty))
  148. (((glyph color-x) [0.5 0.5 0.5])
  149. (color-tty "white"))))
  150. (defvar tetris-space-options
  151. '(((t ?\040))
  152. nil
  153. nil))
  154. ;; ;;;;;;;;;;;;; constants ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  155. (defconst tetris-shapes
  156. [[[[0 0] [1 0] [0 1] [1 1]]]
  157. [[[0 0] [1 0] [2 0] [2 1]]
  158. [[1 -1] [1 0] [1 1] [0 1]]
  159. [[0 -1] [0 0] [1 0] [2 0]]
  160. [[1 -1] [2 -1] [1 0] [1 1]]]
  161. [[[0 0] [1 0] [2 0] [0 1]]
  162. [[0 -1] [1 -1] [1 0] [1 1]]
  163. [[2 -1] [0 0] [1 0] [2 0]]
  164. [[1 -1] [1 0] [1 1] [2 1]]]
  165. [[[0 0] [1 0] [1 1] [2 1]]
  166. [[1 0] [0 1] [1 1] [0 2]]]
  167. [[[1 0] [2 0] [0 1] [1 1]]
  168. [[0 0] [0 1] [1 1] [1 2]]]
  169. [[[1 0] [0 1] [1 1] [2 1]]
  170. [[1 0] [1 1] [2 1] [1 2]]
  171. [[0 1] [1 1] [2 1] [1 2]]
  172. [[1 0] [0 1] [1 1] [1 2]]]
  173. [[[0 0] [1 0] [2 0] [3 0]]
  174. [[1 -1] [1 0] [1 1] [1 2]]]]
  175. "Each shape is described by a vector that contains the coordinates of
  176. each one of its four blocks.")
  177. ;;the scoring rules were taken from "xtetris". Blocks score differently
  178. ;;depending on their rotation
  179. (defconst tetris-shape-scores
  180. [[6] [6 7 6 7] [6 7 6 7] [6 7] [6 7] [5 5 6 5] [5 8]] )
  181. (defconst tetris-shape-dimensions
  182. [[2 2] [3 2] [3 2] [3 2] [3 2] [3 2] [4 1]])
  183. (defconst tetris-blank 7)
  184. (defconst tetris-border 8)
  185. (defconst tetris-space 9)
  186. (defun tetris-default-update-speed-function (_shapes rows)
  187. (/ 20.0 (+ 50.0 rows)))
  188. ;; ;;;;;;;;;;;;; variables ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  189. (defvar tetris-shape 0)
  190. (defvar tetris-rot 0)
  191. (defvar tetris-next-shape 0)
  192. (defvar tetris-n-shapes 0)
  193. (defvar tetris-n-rows 0)
  194. (defvar tetris-score 0)
  195. (defvar tetris-pos-x 0)
  196. (defvar tetris-pos-y 0)
  197. (defvar tetris-paused nil)
  198. (make-variable-buffer-local 'tetris-shape)
  199. (make-variable-buffer-local 'tetris-rot)
  200. (make-variable-buffer-local 'tetris-next-shape)
  201. (make-variable-buffer-local 'tetris-n-shapes)
  202. (make-variable-buffer-local 'tetris-n-rows)
  203. (make-variable-buffer-local 'tetris-score)
  204. (make-variable-buffer-local 'tetris-pos-x)
  205. (make-variable-buffer-local 'tetris-pos-y)
  206. (make-variable-buffer-local 'tetris-paused)
  207. ;; ;;;;;;;;;;;;; keymaps ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  208. (defvar tetris-mode-map
  209. (let ((map (make-sparse-keymap 'tetris-mode-map)))
  210. (define-key map "n" 'tetris-start-game)
  211. (define-key map "q" 'tetris-end-game)
  212. (define-key map "p" 'tetris-pause-game)
  213. (define-key map " " 'tetris-move-bottom)
  214. (define-key map [left] 'tetris-move-left)
  215. (define-key map [right] 'tetris-move-right)
  216. (define-key map [up] 'tetris-rotate-prev)
  217. (define-key map [down] 'tetris-rotate-next)
  218. map))
  219. (defvar tetris-null-map
  220. (let ((map (make-sparse-keymap 'tetris-null-map)))
  221. (define-key map "n" 'tetris-start-game)
  222. map))
  223. ;; ;;;;;;;;;;;;;;;; game functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  224. (defun tetris-display-options ()
  225. (let ((options (make-vector 256 nil)))
  226. (loop for c from 0 to 255 do
  227. (aset options c
  228. (cond ((= c tetris-blank)
  229. tetris-blank-options)
  230. ((and (>= c 0) (<= c 6))
  231. (append
  232. tetris-cell-options
  233. `((((glyph color-x) ,(aref tetris-x-colors c))
  234. (color-tty ,(aref tetris-tty-colors c))
  235. (t nil)))))
  236. ((= c tetris-border)
  237. tetris-border-options)
  238. ((= c tetris-space)
  239. tetris-space-options)
  240. (t
  241. '(nil nil nil)))))
  242. options))
  243. (defun tetris-get-tick-period ()
  244. (if (boundp 'tetris-update-speed-function)
  245. (let ((period (apply tetris-update-speed-function
  246. tetris-n-shapes
  247. tetris-n-rows nil)))
  248. (and (numberp period) period))))
  249. (defun tetris-get-shape-cell (block)
  250. (aref (aref (aref tetris-shapes
  251. tetris-shape) tetris-rot)
  252. block))
  253. (defun tetris-shape-width ()
  254. (aref (aref tetris-shape-dimensions tetris-shape) 0))
  255. (defun tetris-shape-rotations ()
  256. (length (aref tetris-shapes tetris-shape)))
  257. (defun tetris-draw-score ()
  258. (let ((strings (vector (format "Shapes: %05d" tetris-n-shapes)
  259. (format "Rows: %05d" tetris-n-rows)
  260. (format "Score: %05d" tetris-score))))
  261. (loop for y from 0 to 2 do
  262. (let* ((string (aref strings y))
  263. (len (length string)))
  264. (loop for x from 0 to (1- len) do
  265. (gamegrid-set-cell (+ tetris-score-x x)
  266. (+ tetris-score-y y)
  267. (aref string x)))))))
  268. (defun tetris-update-score ()
  269. (tetris-draw-score)
  270. (let ((period (tetris-get-tick-period)))
  271. (if period (gamegrid-set-timer period))))
  272. (defun tetris-new-shape ()
  273. (setq tetris-shape tetris-next-shape)
  274. (setq tetris-rot 0)
  275. (setq tetris-next-shape (random 7))
  276. (setq tetris-pos-x (/ (- tetris-width (tetris-shape-width)) 2))
  277. (setq tetris-pos-y 0)
  278. (if (tetris-test-shape)
  279. (tetris-end-game)
  280. (tetris-draw-shape)
  281. (tetris-draw-next-shape)
  282. (tetris-update-score)))
  283. (defun tetris-draw-next-shape ()
  284. (loop for x from 0 to 3 do
  285. (loop for y from 0 to 3 do
  286. (gamegrid-set-cell (+ tetris-next-x x)
  287. (+ tetris-next-y y)
  288. tetris-blank)))
  289. (loop for i from 0 to 3 do
  290. (let ((tetris-shape tetris-next-shape)
  291. (tetris-rot 0))
  292. (gamegrid-set-cell (+ tetris-next-x
  293. (aref (tetris-get-shape-cell i) 0))
  294. (+ tetris-next-y
  295. (aref (tetris-get-shape-cell i) 1))
  296. tetris-shape))))
  297. (defun tetris-draw-shape ()
  298. (loop for i from 0 to 3 do
  299. (let ((c (tetris-get-shape-cell i)))
  300. (gamegrid-set-cell (+ tetris-top-left-x
  301. tetris-pos-x
  302. (aref c 0))
  303. (+ tetris-top-left-y
  304. tetris-pos-y
  305. (aref c 1))
  306. tetris-shape))))
  307. (defun tetris-erase-shape ()
  308. (loop for i from 0 to 3 do
  309. (let ((c (tetris-get-shape-cell i)))
  310. (gamegrid-set-cell (+ tetris-top-left-x
  311. tetris-pos-x
  312. (aref c 0))
  313. (+ tetris-top-left-y
  314. tetris-pos-y
  315. (aref c 1))
  316. tetris-blank))))
  317. (defun tetris-test-shape ()
  318. (let ((hit nil))
  319. (loop for i from 0 to 3 do
  320. (unless hit
  321. (setq hit
  322. (let* ((c (tetris-get-shape-cell i))
  323. (xx (+ tetris-pos-x
  324. (aref c 0)))
  325. (yy (+ tetris-pos-y
  326. (aref c 1))))
  327. (or (>= xx tetris-width)
  328. (>= yy tetris-height)
  329. (/= (gamegrid-get-cell
  330. (+ xx tetris-top-left-x)
  331. (+ yy tetris-top-left-y))
  332. tetris-blank))))))
  333. hit))
  334. (defun tetris-full-row (y)
  335. (let ((full t))
  336. (loop for x from 0 to (1- tetris-width) do
  337. (if (= (gamegrid-get-cell (+ tetris-top-left-x x)
  338. (+ tetris-top-left-y y))
  339. tetris-blank)
  340. (setq full nil)))
  341. full))
  342. (defun tetris-shift-row (y)
  343. (if (= y 0)
  344. (loop for x from 0 to (1- tetris-width) do
  345. (gamegrid-set-cell (+ tetris-top-left-x x)
  346. (+ tetris-top-left-y y)
  347. tetris-blank))
  348. (loop for x from 0 to (1- tetris-width) do
  349. (let ((c (gamegrid-get-cell (+ tetris-top-left-x x)
  350. (+ tetris-top-left-y y -1))))
  351. (gamegrid-set-cell (+ tetris-top-left-x x)
  352. (+ tetris-top-left-y y)
  353. c)))))
  354. (defun tetris-shift-down ()
  355. (loop for y0 from 0 to (1- tetris-height) do
  356. (if (tetris-full-row y0)
  357. (progn (setq tetris-n-rows (1+ tetris-n-rows))
  358. (loop for y from y0 downto 0 do
  359. (tetris-shift-row y))))))
  360. (defun tetris-draw-border-p ()
  361. (or (not (eq gamegrid-display-mode 'glyph))
  362. tetris-draw-border-with-glyphs))
  363. (defun tetris-init-buffer ()
  364. (gamegrid-init-buffer tetris-buffer-width
  365. tetris-buffer-height
  366. tetris-space)
  367. (let ((buffer-read-only nil))
  368. (if (tetris-draw-border-p)
  369. (loop for y from -1 to tetris-height do
  370. (loop for x from -1 to tetris-width do
  371. (gamegrid-set-cell (+ tetris-top-left-x x)
  372. (+ tetris-top-left-y y)
  373. tetris-border))))
  374. (loop for y from 0 to (1- tetris-height) do
  375. (loop for x from 0 to (1- tetris-width) do
  376. (gamegrid-set-cell (+ tetris-top-left-x x)
  377. (+ tetris-top-left-y y)
  378. tetris-blank)))
  379. (if (tetris-draw-border-p)
  380. (loop for y from -1 to 4 do
  381. (loop for x from -1 to 4 do
  382. (gamegrid-set-cell (+ tetris-next-x x)
  383. (+ tetris-next-y y)
  384. tetris-border))))))
  385. (defun tetris-reset-game ()
  386. (gamegrid-kill-timer)
  387. (tetris-init-buffer)
  388. (setq tetris-next-shape (random 7))
  389. (setq tetris-shape 0
  390. tetris-rot 0
  391. tetris-pos-x 0
  392. tetris-pos-y 0
  393. tetris-n-shapes 0
  394. tetris-n-rows 0
  395. tetris-score 0
  396. tetris-paused nil)
  397. (tetris-new-shape))
  398. (defun tetris-shape-done ()
  399. (tetris-shift-down)
  400. (setq tetris-n-shapes (1+ tetris-n-shapes))
  401. (setq tetris-score
  402. (+ tetris-score
  403. (aref (aref tetris-shape-scores tetris-shape) tetris-rot)))
  404. (tetris-update-score)
  405. (tetris-new-shape))
  406. (defun tetris-update-game (tetris-buffer)
  407. "Called on each clock tick.
  408. Drops the shape one square, testing for collision."
  409. (if (and (not tetris-paused)
  410. (eq (current-buffer) tetris-buffer))
  411. (let (hit)
  412. (tetris-erase-shape)
  413. (setq tetris-pos-y (1+ tetris-pos-y))
  414. (setq hit (tetris-test-shape))
  415. (if hit
  416. (setq tetris-pos-y (1- tetris-pos-y)))
  417. (tetris-draw-shape)
  418. (if hit
  419. (tetris-shape-done)))))
  420. (defun tetris-move-bottom ()
  421. "Drop the shape to the bottom of the playing area."
  422. (interactive)
  423. (unless tetris-paused
  424. (let ((hit nil))
  425. (tetris-erase-shape)
  426. (while (not hit)
  427. (setq tetris-pos-y (1+ tetris-pos-y))
  428. (setq hit (tetris-test-shape)))
  429. (setq tetris-pos-y (1- tetris-pos-y))
  430. (tetris-draw-shape)
  431. (tetris-shape-done))))
  432. (defun tetris-move-left ()
  433. "Move the shape one square to the left."
  434. (interactive)
  435. (unless tetris-paused
  436. (tetris-erase-shape)
  437. (setq tetris-pos-x (1- tetris-pos-x))
  438. (if (tetris-test-shape)
  439. (setq tetris-pos-x (1+ tetris-pos-x)))
  440. (tetris-draw-shape)))
  441. (defun tetris-move-right ()
  442. "Move the shape one square to the right."
  443. (interactive)
  444. (unless tetris-paused
  445. (tetris-erase-shape)
  446. (setq tetris-pos-x (1+ tetris-pos-x))
  447. (if (tetris-test-shape)
  448. (setq tetris-pos-x (1- tetris-pos-x)))
  449. (tetris-draw-shape)))
  450. (defun tetris-rotate-prev ()
  451. "Rotate the shape clockwise."
  452. (interactive)
  453. (unless tetris-paused
  454. (tetris-erase-shape)
  455. (setq tetris-rot (% (+ 1 tetris-rot)
  456. (tetris-shape-rotations)))
  457. (if (tetris-test-shape)
  458. (setq tetris-rot (% (+ 3 tetris-rot)
  459. (tetris-shape-rotations))))
  460. (tetris-draw-shape)))
  461. (defun tetris-rotate-next ()
  462. "Rotate the shape anticlockwise."
  463. (interactive)
  464. (unless tetris-paused
  465. (tetris-erase-shape)
  466. (setq tetris-rot (% (+ 3 tetris-rot)
  467. (tetris-shape-rotations)))
  468. (if (tetris-test-shape)
  469. (setq tetris-rot (% (+ 1 tetris-rot)
  470. (tetris-shape-rotations))))
  471. (tetris-draw-shape)))
  472. (defun tetris-end-game ()
  473. "Terminate the current game."
  474. (interactive)
  475. (gamegrid-kill-timer)
  476. (use-local-map tetris-null-map)
  477. (gamegrid-add-score tetris-score-file tetris-score))
  478. (defun tetris-start-game ()
  479. "Start a new game of Tetris."
  480. (interactive)
  481. (tetris-reset-game)
  482. (use-local-map tetris-mode-map)
  483. (let ((period (or (tetris-get-tick-period)
  484. tetris-default-tick-period)))
  485. (gamegrid-start-timer period 'tetris-update-game)))
  486. (defun tetris-pause-game ()
  487. "Pause (or resume) the current game."
  488. (interactive)
  489. (setq tetris-paused (not tetris-paused))
  490. (message (and tetris-paused "Game paused (press p to resume)")))
  491. (defun tetris-active-p ()
  492. (eq (current-local-map) tetris-mode-map))
  493. (put 'tetris-mode 'mode-class 'special)
  494. (define-derived-mode tetris-mode nil "Tetris"
  495. "A mode for playing Tetris."
  496. (add-hook 'kill-buffer-hook 'gamegrid-kill-timer nil t)
  497. (use-local-map tetris-null-map)
  498. (unless (featurep 'emacs)
  499. (setq mode-popup-menu
  500. '("Tetris Commands"
  501. ["Start new game" tetris-start-game]
  502. ["End game" tetris-end-game
  503. (tetris-active-p)]
  504. ["Pause" tetris-pause-game
  505. (and (tetris-active-p) (not tetris-paused))]
  506. ["Resume" tetris-pause-game
  507. (and (tetris-active-p) tetris-paused)])))
  508. (setq show-trailing-whitespace nil)
  509. (setq gamegrid-use-glyphs tetris-use-glyphs)
  510. (setq gamegrid-use-color tetris-use-color)
  511. (gamegrid-init (tetris-display-options)))
  512. ;;;###autoload
  513. (defun tetris ()
  514. "Play the Tetris game.
  515. Shapes drop from the top of the screen, and the user has to move and
  516. rotate the shape to fit in with those at the bottom of the screen so
  517. as to form complete rows.
  518. tetris-mode keybindings:
  519. \\<tetris-mode-map>
  520. \\[tetris-start-game] Starts a new game of Tetris
  521. \\[tetris-end-game] Terminates the current game
  522. \\[tetris-pause-game] Pauses (or resumes) the current game
  523. \\[tetris-move-left] Moves the shape one square to the left
  524. \\[tetris-move-right] Moves the shape one square to the right
  525. \\[tetris-rotate-prev] Rotates the shape clockwise
  526. \\[tetris-rotate-next] Rotates the shape anticlockwise
  527. \\[tetris-move-bottom] Drops the shape to the bottom of the playing area
  528. "
  529. (interactive)
  530. (select-window (or (get-buffer-window tetris-buffer-name)
  531. (selected-window)))
  532. (switch-to-buffer tetris-buffer-name)
  533. (gamegrid-kill-timer)
  534. (tetris-mode)
  535. (tetris-start-game))
  536. (random t)
  537. (provide 'tetris)
  538. ;;; tetris.el ends here