Stable - A python TDD/MVC demonstration.
Python Makefile
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
charts
docs
hangman
tests
.coveragerc
.editorconfig
.gitignore
.requirements.diff
.travis.yml
AUTHORS.rst
CONTRIBUTING.rst
HISTORY.rst
LICENSE
MANIFEST.in
Makefile
README.rst
requirements.in
requirements.txt
requirements_dev.in
requirements_dev.txt
setup.cfg
setup.py
tox.ini
travis_pypi_setup.py

README.rst

python_hangman

Latest Version Development Status Build Status Coverage Status Documentation Status

A well tested, cli, python version-agnostic, multi-platform hangman game. It's built following a TDD workflow and a MVC design pattern. Each component services a sensibly distinct logical purpose. Python Hangman is a version agnostic, tox tested, travis-backed program! Documented and distributed.

Features

Screenshot

Compatibility

Supported Python versions
  • Python 2.6
  • Python 2.7
  • Python 3.3
  • Python 3.4
  • Python 3.5
  • PyPy

Installation

At the command line either via easy_install or pip

$ mkvirtualenv hangman  # optional for venv users
$ pip install python_hangman
$ hangman

Uninstall

$ pip uninstall python_hangman

Goals

2.0.0

MVC pattern. The goal was to explicitly demonstrate an MVC pattern out of the scope of web development.

Idiomatic code. In this overhaul there's a big emphasis on idiomatic code. The code should be describing its' own intention with the clarity your grandmother could read.

1.0.0

Learning! This was a Test Driven Development(TDD) exercise.

Also, explored:

  • Tox, test automation
  • Travis CI
  • Python version agnostic programming
  • Setuptools
  • Publishing on pip
  • Coverage via coveralls
  • Documentation with sphinx and ReadTheDocs
  • Cookiecutter development

Design

This game roughly follows the Model-View-Controller(MVC) pattern. In the latest overhaul, these roles have been explicitly named: hangman.model, hangman.view, hangman.controller.

Traditionally in MVC the controller is the focal point. It tells the view what information to collect from the user and what to show. It uses that information to communicate with the model--also, the data persistence later--and determine the next step. This Hangman MVC adheres to these principals

Model

The model is very simply the hangman game instance--hangman.model.Hangman. It's a class. Every class should have "state" and the methods of that class should manage that state. In this case, the "state" is the current "state of the game". The public API are for managing that state.

The entirety of the game logic is contained in hangman.model.Hangman. You could technically play the game in the python console by instantiating the class, submitting guesses with the method hangman.model.Hangman.guess and printing the game state.

For example:

>>> from hangman.model import Hangman
>>> game = Hangman(answer='hangman')
>>> game.guess('a')
hangman(status='_A___A_', misses=[], remaining_turns=10)

>>> game.guess('n').guess('z').guess('e')
hangman(status='_AN__AN', misses=['E', 'Z'], remaining_turns=8)

>>> game.status
'_AN__AN'

>>> game.misses
['E', 'Z']

>>> game.remaining_turns
8

View

hangman.view is a collection of stateless functions that represent the presentation layer. When called these functions handles printing the art to the console, and collecting input from the user.

Controller

In this program, the controller is actually the "game_loop"--hangman.controller.game_loop. I still think of it as a controller because the role it plays--communicating I/O from the view with the model-persistence layer.

The controller tells the view later what to print and what data to collect. It uses that information update the state of the game (model) and handle game events.

Call Diagram

Call Diagram

Credits

Tools used in rendering this package: