Skip to content

Commit

Permalink
games: add typit, a simple typing game.
Browse files Browse the repository at this point in the history
  • Loading branch information
syl20bnr committed Apr 6, 2016
1 parent 0ec385c commit 6866e02
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 14 deletions.
27 changes: 25 additions & 2 deletions layers/+fun/games/README.org
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 |
Expand Down Expand Up @@ -53,6 +55,7 @@ Possible helm actions:
| ~k~ | Move up |
| ~l~ | Move right |
| | |

** Tetris

| Key Binding | Description |
Expand All @@ -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.
44 changes: 44 additions & 0 deletions layers/+fun/games/funcs.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
;;; funcs.el --- Games Layer functions File for Spacemacs
;;
;; Copyright (c) 2012-2016 Sylvain Benner & Contributors
;;
;; Author: Sylvain Benner <[email protected]>
;; 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))))))


30 changes: 18 additions & 12 deletions layers/+fun/games/packages.el
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
(helm-games :location local)
pacmacs
(tetris :location built-in)
typit
))

(defun games/init-2048-game ()
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)))

0 comments on commit 6866e02

Please sign in to comment.