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."
|
||||
:group '2048-mode)
|
||||
(setq 2048-highlights
|
||||
'(
|
||||
(" 2 " . '2048-2)
|
||||
'((" 2 " . '2048-2)
|
||||
(" 4 " . '2048-4)
|
||||
(" 8 " . '2048-8)
|
||||
(" 16 " . '2048-16)
|
||||
@ -163,8 +162,7 @@ TODO: rewrite with calculations based on `2048--cell-width's other than 6."
|
||||
(" 512 " . '2048-512)
|
||||
(" 1024 " . '2048-1024)
|
||||
(" 2048 " . '2048-2048)
|
||||
(" 4096 " . '2048-4096)
|
||||
))
|
||||
(" 4096 " . '2048-4096)))
|
||||
|
||||
(defun 2048-draw-board ()
|
||||
"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 "") )
|
||||
(insert 2048--vertical-sep-char)
|
||||
(setq o (2048--pad k))
|
||||
(insert o)
|
||||
)
|
||||
)
|
||||
(insert o)))
|
||||
(insert ;(concat "|\n" 2048-space-sep "\n")
|
||||
(concat (string 2048--vertical-sep-char ?\n) 2048-space-sep "\n")
|
||||
)
|
||||
)
|
||||
(insert 2048-plus-sep)
|
||||
)
|
||||
(concat (string 2048--vertical-sep-char ?\n) 2048-space-sep "\n")))
|
||||
(insert 2048-plus-sep))
|
||||
|
||||
(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))
|
||||
(dotimes (j 2048--board-size)
|
||||
(dotimes (i 2048--board-size)
|
||||
(when (= (2048-get-num-at i j) 0) (setq k (+ k 1)))
|
||||
)
|
||||
)
|
||||
k
|
||||
)
|
||||
)
|
||||
(when (= (2048-get-num-at i j) 0) (setq k (+ k 1)))))
|
||||
k))
|
||||
|
||||
(defun 2048-check-total-diff ()
|
||||
"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
|
||||
(dotimes (j 2048--board-size)
|
||||
(dotimes (i 2048--board-size)
|
||||
(when (2048-check-diff i j) (throw 'breaker t))
|
||||
)
|
||||
)
|
||||
(throw 'breaker nil)
|
||||
)
|
||||
)
|
||||
(when (2048-check-diff i j) (throw 'breaker t))))
|
||||
(throw 'breaker nil)))
|
||||
|
||||
(defun 2048-check-diff (x y)
|
||||
"Returns t if board has changed since beginning of shift."
|
||||
(/= (aref (aref 2048-board y) x)
|
||||
(aref (aref 2048-board-old y) x))
|
||||
)
|
||||
(aref (aref 2048-board-old y) x)))
|
||||
|
||||
(defun 2048-push-board()
|
||||
"Push 2048-board to 2048-board-old. Essentially makes a snapshot of the
|
||||
game board to detect modifications later."
|
||||
(dotimes (j 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 ()
|
||||
"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)))
|
||||
(while (/= (2048-get-num-at i j) 0)
|
||||
(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 ))
|
||||
( t (aset (aref 2048-board j) i 4)))
|
||||
)
|
||||
)
|
||||
)
|
||||
( t (aset (aref 2048-board j) i 4))))))
|
||||
|
||||
(defun 2048-shift (direction)
|
||||
"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"))
|
||||
(dotimes (j 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"))
|
||||
(dotimes (j 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
|
||||
(2048-check-total-diff) (2048-spawn))
|
||||
;; Redraw... even if stuff don't need it.
|
||||
(erase-buffer)
|
||||
(2048-draw-board)
|
||||
)
|
||||
(2048-draw-board))
|
||||
|
||||
(defun 2048-shift-left () (interactive) (2048-shift "l") )
|
||||
(defun 2048-shift-right () (interactive) (2048-shift "r"))
|
||||
@ -398,13 +368,12 @@ individually."
|
||||
(local-set-key (kbd "<mouse-7>") '2048-shift-up)
|
||||
|
||||
(2048-startup)
|
||||
(setq font-lock-defaults '(2048-highlights))
|
||||
)
|
||||
(setq font-lock-defaults '(2048-highlights)))
|
||||
|
||||
(defun play-2048 ()
|
||||
"Play 2048 in Emacs!"
|
||||
(switch-to-buffer (get-buffer-create "*2048*"))
|
||||
(2048-mode)
|
||||
)
|
||||
(2048-mode))
|
||||
|
||||
(provide '2048)
|
||||
;;; 2048.el ends here
|
||||
|
@ -892,10 +892,13 @@ Return nil if DIR is not in a hugo project at all."
|
||||
:config
|
||||
(add-hook 'Info-mode-hook #'info-variable-pitch-mode))
|
||||
|
||||
;; (elpaca-use-package exwm
|
||||
;; ;; :init
|
||||
;; ;; (require 'exwm-config)
|
||||
;; ;; (exwm-config-example))
|
||||
;; (elpaca nil
|
||||
;; (use-package exwm
|
||||
;; :ensure nil
|
||||
;; :if (package-installed-p 'exwm)
|
||||
;; :init
|
||||
;; (require 'exwm-config)
|
||||
;; (exwm-config-example)))
|
||||
|
||||
(elpaca nil
|
||||
(use-package xwidget
|
||||
|
Loading…
Reference in New Issue
Block a user