2048 in Emacs, and colours too
Posted: - Modified: | emacsWhile browsing through M-x list-packages
, I noticed that there was a new MELPA package that implemented the 2048 game in Emacs. I wrote the following code to colorize it. Haven't tested the higher numbers yet, but they're easy enough to tweak if the colours disagree with your theme. =)
(defface 2048-2-face '((t (:foreground "red"))) "Face used for 2" :group '2048-game) (defface 2048-4-face '((t (:foreground "orange"))) "Face used for 4" :group '2048-game) (defface 2048-8-face '((t (:foreground "yellow"))) "Face used for 8" :group '2048-game) (defface 2048-16-face '((t (:foreground "green"))) "Face used for 16" :group '2048-game) (defface 2048-32-face '((t (:foreground "lightblue" :bold t))) "Face used for 32" :group '2048-game) (defface 2048-64-face '((t (:foreground "lavender" :bold t))) "Face used for 64" :group '2048-game) (defface 2048-128-face '((t (:foreground "SlateBlue" :bold t))) "Face used for 128" :group '2048-game) (defface 2048-256-face '((t (:foreground "MediumVioletRed" :bold t))) "Face used for 256" :group '2048-game) (defface 2048-512-face '((t (:foreground "tomato" :bold t))) "Face used for 512" :group '2048-game) (defface 2048-1024-face '((t (:foreground "SkyBlue1" :bold t))) "Face used for 1024" :group '2048-game) (defface 2048-2048-face '((t (:foreground "lightgreen" :bold t))) "Face used for 2048" :group '2048-game) (defvar 2048-font-lock-keywords '(("\\<2\\>" 0 '2048-2-face) ("\\<4\\>" 0 '2048-4-face) ("\\<8\\>" 0 '2048-8-face) ("\\<16\\>" 0 '2048-16-face) ("\\<32\\>" 0 '2048-32-face) ("\\<64\\>" 0 '2048-64-face) ("\\<128\\>" 0 '2048-128-face) ("\\<256\\>" 0 '2048-256-face) ("\\<512\\>" 0 '2048-512-face) ("\\<1024\\>" 0 '2048-1024-face) ("\\<2048\\>" 0 '2048-2048-face))) (defun sacha/2048-fontify () (font-lock-add-keywords nil 2048-font-lock-keywords)) (defun sacha/2048-set-font-size () (text-scale-set 5)) (use-package 2048-game :config (progn (add-hook '2048-mode-hook 'sacha/2048-fontify) (add-hook '2048-mode-hook 'sacha/2048-set-font-size)))
10 comments
Dave P
2014-05-06T06:47:29ZSo... What's the 2048 game please? Not heard of it?
And are the colours somehow related to the css #123456 colour scheme?
And how does the above work? Or a link to colouring text in the e-lisp manual please?
sachac
2014-05-07T00:26:55ZArbitrary colours, no meaning. I just picked stuff I could see. =)
Colouring text: see defface - http://www.gnu.org/software...
Gerrit
2014-05-06T13:08:39Z@Da: This is the game https://gabrielecirulli.git...
It's quite addictive to play. There goes my productivity :D
verdammelt
2014-05-06T15:18:22ZJust met the author of this package last night at the NYC emacs Meetup - he's going to talk next month at the Meetup about writing games in Emacs.
Scott
2014-05-06T18:38:40ZJust learned there is such a thing as "Emacs Meetup"! I've lead a sheltered life.
sachac
2014-05-07T00:18:06ZMe too! =) I wish there was one in Toronto, but I don't feel like organizing one.
The Emacs Conference was tons of fun too. =)
Jaocb
2014-05-06T18:02:42ZAlso met the author and also met verdammelt BOOM.
sachac
2014-05-07T00:18:37ZHooray for meetups!
verdammelt
2014-05-07T00:42:54ZSmall world - but of course I don't remember names! So hopefully I'll meet you again at the next one!
yasuhito
2014-05-23T08:32:51ZAlthough not related to emacs, I've written 2048 terminal version in Ruby.
https://github.com/yasuhito...