2048: join trailing paren lines
This commit is contained in:
parent
241be55236
commit
c4b9733f18
71
lisp/2048.el
71
lisp/2048.el
@ -151,8 +151,7 @@ TODO: rewrite with calculations based on `2048--cell-width's other than 6."
|
|||||||
"Face for number 4096 in 2048."
|
"Face for number 4096 in 2048."
|
||||||
:group '2048-mode)
|
:group '2048-mode)
|
||||||
(setq 2048-highlights
|
(setq 2048-highlights
|
||||||
'(
|
'((" 2 " . '2048-2)
|
||||||
(" 2 " . '2048-2)
|
|
||||||
(" 4 " . '2048-4)
|
(" 4 " . '2048-4)
|
||||||
(" 8 " . '2048-8)
|
(" 8 " . '2048-8)
|
||||||
(" 16 " . '2048-16)
|
(" 16 " . '2048-16)
|
||||||
@ -163,8 +162,7 @@ TODO: rewrite with calculations based on `2048--cell-width's other than 6."
|
|||||||
(" 512 " . '2048-512)
|
(" 512 " . '2048-512)
|
||||||
(" 1024 " . '2048-1024)
|
(" 1024 " . '2048-1024)
|
||||||
(" 2048 " . '2048-2048)
|
(" 2048 " . '2048-2048)
|
||||||
(" 4096 " . '2048-4096)
|
(" 4096 " . '2048-4096)))
|
||||||
))
|
|
||||||
|
|
||||||
(defun 2048-draw-board ()
|
(defun 2048-draw-board ()
|
||||||
"Draws the 4x4 gaming grid."
|
"Draws the 4x4 gaming grid."
|
||||||
@ -175,15 +173,10 @@ TODO: rewrite with calculations based on `2048--cell-width's other than 6."
|
|||||||
(let ( (k (2048-get-num-at i j)) (o "") )
|
(let ( (k (2048-get-num-at i j)) (o "") )
|
||||||
(insert 2048--vertical-sep-char)
|
(insert 2048--vertical-sep-char)
|
||||||
(setq o (2048--pad k))
|
(setq o (2048--pad k))
|
||||||
(insert o)
|
(insert o)))
|
||||||
)
|
|
||||||
)
|
|
||||||
(insert ;(concat "|\n" 2048-space-sep "\n")
|
(insert ;(concat "|\n" 2048-space-sep "\n")
|
||||||
(concat (string 2048--vertical-sep-char ?\n) 2048-space-sep "\n")
|
(concat (string 2048--vertical-sep-char ?\n) 2048-space-sep "\n")))
|
||||||
)
|
(insert 2048-plus-sep))
|
||||||
)
|
|
||||||
(insert 2048-plus-sep)
|
|
||||||
)
|
|
||||||
|
|
||||||
(defun 2048-get-num-at (x y) "0, 0 is top-left" (aref (aref 2048-board y) x) )
|
(defun 2048-get-num-at (x y) "0, 0 is top-left" (aref (aref 2048-board y) x) )
|
||||||
|
|
||||||
@ -278,12 +271,8 @@ the 2048-shift function. Slides and merges for four directions."
|
|||||||
(let ((k 0))
|
(let ((k 0))
|
||||||
(dotimes (j 2048--board-size)
|
(dotimes (j 2048--board-size)
|
||||||
(dotimes (i 2048--board-size)
|
(dotimes (i 2048--board-size)
|
||||||
(when (= (2048-get-num-at i j) 0) (setq k (+ k 1)))
|
(when (= (2048-get-num-at i j) 0) (setq k (+ k 1)))))
|
||||||
)
|
k))
|
||||||
)
|
|
||||||
k
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
(defun 2048-check-total-diff ()
|
(defun 2048-check-total-diff ()
|
||||||
"Run 2048-check-diff on the whole board.
|
"Run 2048-check-diff on the whole board.
|
||||||
@ -294,28 +283,20 @@ Return t/nil if board has changed or not. Only relevant after
|
|||||||
(catch 'breaker
|
(catch 'breaker
|
||||||
(dotimes (j 2048--board-size)
|
(dotimes (j 2048--board-size)
|
||||||
(dotimes (i 2048--board-size)
|
(dotimes (i 2048--board-size)
|
||||||
(when (2048-check-diff i j) (throw 'breaker t))
|
(when (2048-check-diff i j) (throw 'breaker t))))
|
||||||
)
|
(throw 'breaker nil)))
|
||||||
)
|
|
||||||
(throw 'breaker nil)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
(defun 2048-check-diff (x y)
|
(defun 2048-check-diff (x y)
|
||||||
"Returns t if board has changed since beginning of shift."
|
"Returns t if board has changed since beginning of shift."
|
||||||
(/= (aref (aref 2048-board y) x)
|
(/= (aref (aref 2048-board y) x)
|
||||||
(aref (aref 2048-board-old y) x))
|
(aref (aref 2048-board-old y) x)))
|
||||||
)
|
|
||||||
|
|
||||||
(defun 2048-push-board()
|
(defun 2048-push-board()
|
||||||
"Push 2048-board to 2048-board-old. Essentially makes a snapshot of the
|
"Push 2048-board to 2048-board-old. Essentially makes a snapshot of the
|
||||||
game board to detect modifications later."
|
game board to detect modifications later."
|
||||||
(dotimes (j 2048--board-size)
|
(dotimes (j 2048--board-size)
|
||||||
(dotimes (i 2048--board-size)
|
(dotimes (i 2048--board-size)
|
||||||
(aset (aref 2048-board-old j) i (aref (aref 2048-board j) i))
|
(aset (aref 2048-board-old j) i (aref (aref 2048-board j) i)))))
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
(defun 2048-spawn ()
|
(defun 2048-spawn ()
|
||||||
"Add either a 2 or 4 to the 2048-board array at a random, free space."
|
"Add either a 2 or 4 to the 2048-board array at a random, free space."
|
||||||
@ -324,13 +305,9 @@ game board to detect modifications later."
|
|||||||
(let ((j (random 2048--board-size)) (i (random 2048--board-size)) (k (random 100)))
|
(let ((j (random 2048--board-size)) (i (random 2048--board-size)) (k (random 100)))
|
||||||
(while (/= (2048-get-num-at i j) 0)
|
(while (/= (2048-get-num-at i j) 0)
|
||||||
(setq i (random 2048--board-size))
|
(setq i (random 2048--board-size))
|
||||||
(setq j (random 2048--board-size))
|
(setq j (random 2048--board-size)))
|
||||||
)
|
|
||||||
(cond ( (< k 75) (aset (aref 2048-board j) i 2 ))
|
(cond ( (< k 75) (aset (aref 2048-board j) i 2 ))
|
||||||
( t (aset (aref 2048-board j) i 4)))
|
( t (aset (aref 2048-board j) i 4))))))
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
(defun 2048-shift (direction)
|
(defun 2048-shift (direction)
|
||||||
"Entry point for shifting. All the keypresses get mapped to this function with
|
"Entry point for shifting. All the keypresses get mapped to this function with
|
||||||
@ -341,26 +318,19 @@ individually."
|
|||||||
((or (string= direction "l") (string= direction "u"))
|
((or (string= direction "l") (string= direction "u"))
|
||||||
(dotimes (j 2048--board-size)
|
(dotimes (j 2048--board-size)
|
||||||
(dotimes (i 2048--board-size)
|
(dotimes (i 2048--board-size)
|
||||||
(2048-slide-single-piece i j direction)
|
(2048-slide-single-piece i j direction))))
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
((or (string= direction "r") (string= direction "d"))
|
((or (string= direction "r") (string= direction "d"))
|
||||||
(dotimes (j 2048--board-size)
|
(dotimes (j 2048--board-size)
|
||||||
(dotimes (i 2048--board-size)
|
(dotimes (i 2048--board-size)
|
||||||
(2048-slide-single-piece (- (1- 2048--board-size) i) (- (1- 2048--board-size) j) direction)
|
(2048-slide-single-piece (- (1- 2048--board-size) i)
|
||||||
)
|
(- (1- 2048--board-size) j) direction)))))
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
(when
|
(when
|
||||||
(2048-check-total-diff) (2048-spawn))
|
(2048-check-total-diff) (2048-spawn))
|
||||||
;; Redraw... even if stuff don't need it.
|
;; Redraw... even if stuff don't need it.
|
||||||
(erase-buffer)
|
(erase-buffer)
|
||||||
(2048-draw-board)
|
(2048-draw-board))
|
||||||
)
|
|
||||||
|
|
||||||
(defun 2048-shift-left () (interactive) (2048-shift "l") )
|
(defun 2048-shift-left () (interactive) (2048-shift "l") )
|
||||||
(defun 2048-shift-right () (interactive) (2048-shift "r"))
|
(defun 2048-shift-right () (interactive) (2048-shift "r"))
|
||||||
@ -398,13 +368,12 @@ individually."
|
|||||||
(local-set-key (kbd "<mouse-7>") '2048-shift-up)
|
(local-set-key (kbd "<mouse-7>") '2048-shift-up)
|
||||||
|
|
||||||
(2048-startup)
|
(2048-startup)
|
||||||
(setq font-lock-defaults '(2048-highlights))
|
(setq font-lock-defaults '(2048-highlights)))
|
||||||
)
|
|
||||||
|
|
||||||
(defun play-2048 ()
|
(defun play-2048 ()
|
||||||
"Play 2048 in Emacs!"
|
"Play 2048 in Emacs!"
|
||||||
(switch-to-buffer (get-buffer-create "*2048*"))
|
(switch-to-buffer (get-buffer-create "*2048*"))
|
||||||
(2048-mode)
|
(2048-mode))
|
||||||
)
|
|
||||||
(provide '2048)
|
(provide '2048)
|
||||||
;;; 2048.el ends here
|
;;; 2048.el ends here
|
||||||
|
@ -892,10 +892,13 @@ Return nil if DIR is not in a hugo project at all."
|
|||||||
:config
|
:config
|
||||||
(add-hook 'Info-mode-hook #'info-variable-pitch-mode))
|
(add-hook 'Info-mode-hook #'info-variable-pitch-mode))
|
||||||
|
|
||||||
;; (elpaca-use-package exwm
|
;; (elpaca nil
|
||||||
;; ;; :init
|
;; (use-package exwm
|
||||||
;; ;; (require 'exwm-config)
|
;; :ensure nil
|
||||||
;; ;; (exwm-config-example))
|
;; :if (package-installed-p 'exwm)
|
||||||
|
;; :init
|
||||||
|
;; (require 'exwm-config)
|
||||||
|
;; (exwm-config-example)))
|
||||||
|
|
||||||
(elpaca nil
|
(elpaca nil
|
||||||
(use-package xwidget
|
(use-package xwidget
|
||||||
|
Loading…
Reference in New Issue
Block a user