diff --git a/layers/+fun/games/README.org b/layers/+fun/games/README.org index 36155fd6b52a..2f336367414a 100644 --- a/layers/+fun/games/README.org +++ b/layers/+fun/games/README.org @@ -5,10 +5,11 @@ * Table of Contents :TOC_4_gh:noexport: - [[#description][Description]] - [[#install][Install]] - - [[#key-bindings][Key bindings]] + - [[#key-bindings-and-configuration][Key bindings and configuration]] - [[#2048][2048]] - [[#pacmacs][Pacmacs]] - [[#tetris][Tetris]] + - [[#typit][Typit]] * Description This layer allows you to play evilified games in spacemacs. @@ -17,13 +18,14 @@ The games available now are: - 2048-game - Pacmacs (Pacman for Emacs) - Tetris +- Typit * Install To use this configuration layer, add it to your =~/.spacemacs=. You will need to add =games= to the existing =dotspacemacs-configuration-layers= list in this file. -* Key bindings +* Key bindings and configuration To run a game: | Key Binding | Description | @@ -53,6 +55,7 @@ Possible helm actions: | ~k~ | Move up | | ~l~ | Move right | | | | + ** Tetris | Key Binding | Description | @@ -65,3 +68,23 @@ Possible helm actions: | ~n~ | Start a new game | | ~p~ | Pause the game | | ~q~ | Quit the game | + +** Typit +There is no specific key bindings for this game, just launch it and begin +typing. + +The game can be customized with the following variables: + +| Vsariable | Description | +|---------------------+-------------------------------------------------------| +| =typit-dict= | Language dictionary to use (default is =english.txt=) | +| =typit-dict-dir= | A directory path where to find dictionaries | +| =typit-line-length= | Length of generated lines (default 80) | +| =typit-test-time= | Duration of a game (default 60sec) | + +Instrutions to create a new dictionary: + +To add a new dictionary, you need to create a text file named your-language.txt +and put it under the dict directory. That file should contain 1000 most common +words from the language, a word per line. Please make sure that it uses +Unix-style (that is, LF) end-of-line sequence and the file ends with a newline. diff --git a/layers/+fun/games/funcs.el b/layers/+fun/games/funcs.el new file mode 100644 index 000000000000..91faea62a16f --- /dev/null +++ b/layers/+fun/games/funcs.el @@ -0,0 +1,44 @@ +;;; funcs.el --- Games Layer functions File for Spacemacs +;; +;; Copyright (c) 2012-2016 Sylvain Benner & Contributors +;; +;; Author: Sylvain Benner +;; URL: https://github.com/syl20bnr/spacemacs +;; +;; This file is not part of GNU Emacs. +;; +;;; License: GPLv3 + + + +(defun spacemacs/tetris-quit-game () + "Correctly quit tetris by killng the game buffer." + (interactive) + (tetris-pause-game) + (if (yes-or-no-p "Do you really want to quit ? ") + (progn + (tetris-end-game) + (kill-buffer "*Tetris*")) + (tetris-pause-game))) + + + +(defun spacemacs/games-start-typit-beginner () + "Start `typit' game in beginner difficulty." + (interactive) + (spacemacs//games-start-typit 'basic)) + +(defun spacemacs/games-start-typit-expert () + "Start `typit' game in expert difficulty." + (interactive) + (spacemacs//games-start-typit 'advanced)) + +(defun spacemacs//games-start-typit (type) + "Start a `typit' game with TYPE difficulty." + (with-current-buffer (get-buffer-create "*typit*") + (let ((evil-escape-inhibit t) + (golden-ratio-mode nil)) + (evil-insert-state) + (funcall (intern (format "typit-%S-test" type)))))) + + diff --git a/layers/+fun/games/packages.el b/layers/+fun/games/packages.el index b439e091252f..081f3d70df4e 100644 --- a/layers/+fun/games/packages.el +++ b/layers/+fun/games/packages.el @@ -15,6 +15,7 @@ (helm-games :location local) pacmacs (tetris :location built-in) + typit )) (defun games/init-2048-game () @@ -43,8 +44,9 @@ (use-package pacmacs :defer t :init - (push '("pacmacs" . (pacmacs-start :quit (kill-buffer-ask (get-buffer "*Pacmacs*")) - :reset pacmacs-start)) helm-games-list) + (push '("pacmacs" . (pacmacs-start + :quit (kill-buffer-ask (get-buffer "*Pacmacs*")) + :reset pacmacs-start)) helm-games-list) (evilified-state-evilify pacmacs-mode pacmacs-mode-map "h" 'pacmacs-left "j" 'pacmacs-down @@ -59,16 +61,7 @@ (push '("Tetris" . (tetris :quit spacemacs/tetris-quit-game :reset tetris-start-game)) helm-games-list) (setq tetris-score-file (concat spacemacs-games-cache-directory - "tetris-scores.txt")) - (defun spacemacs/tetris-quit-game () - "Correctly quit tetris by killng the game buffer." - (interactive) - (tetris-pause-game) - (if (yes-or-no-p "Do you really want to quit ? ") - (progn - (tetris-end-game) - (kill-buffer "*Tetris*")) - (tetris-pause-game)))) + "tetris-scores.txt"))) :config (progn (evilified-state-evilify tetris-mode tetris-mode-map @@ -78,3 +71,16 @@ "k" 'tetris-rotate-next "l" 'tetris-move-right "q" 'spacemacs/tetris-quit-game)))) + +(defun games/init-typit () + (use-package typit + :defer t + :init + (push '("typit (beginner)" . (spacemacs/games-start-typit-beginner + :quit (kill-buffer-ask (get-buffer "*typit*")) + :reset spacemacs/games-start-typit-beginner)) + helm-games-list) + (push '("typit (expert)" . (spacemacs/games-start-typit-expert + :quit (kill-buffer-ask (get-buffer "*typit*")) + :reset spacemacs/games-start-typit-expert)) + helm-games-list)))