hangman package¶
python_hangman¶
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.
Submodules¶
hangman.__main__¶
Entry point for hangman
command.
hangman.controller¶
-
hangman.controller.
game_loop
(game=hangman(status='________', misses=[], remaining_turns=10), flash=<hangman.utils.FlashMessage object>)[source]¶ Run a single game.
Parameters: - game (hangman.model.Hangman) – Hangman game instance.
- flash (hangman.utils.FlashMessage) – FlashMessage utility
-
hangman.controller.
run
(game=hangman(status='_____', misses=[], remaining_turns=10), flash=<hangman.utils.FlashMessage object>)[source]¶ Run
game_loop
and handle exiting.Logic is separated from game_loop to cleanly avoid python recursion limits.
Parameters: - game (hangman.model.Hangman) – Hangman game instance.
- flash (hangman.utils.FlashMessage) – FlashMessage utility
hangman.model¶
-
class
hangman.model.
Hangman
(answer=None)[source]¶ Bases:
object
The the logic for managing the status of the game and raising key game related events.
>>> 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
-
MAX_TURNS
= 10¶
-
hits
¶ List of hits.
-
misses
¶ List of misses.
-
remaining_turns
¶ Calculate number of turns remaining.
-
status
¶ Build a string representation of status.
-
hangman.utils¶
App utilities.
-
class
hangman.utils.
WordBank
[source]¶ Bases:
object
Default collection of words to choose from
-
WORDS
= ['ATTEMPT', 'DOLL', 'ELLEN', 'FLOATING', 'PRIDE', 'HEADING', 'FILM', 'KIDS', 'MONKEY', 'LUNGS', 'HABIT', 'SPIN', 'DISCUSSION', 'OFFICIAL', 'PHILADELPHIA', 'FACING', 'MARTIN', 'NORWAY', 'POLICEMAN', 'TOBACCO', 'VESSELS', 'TALES', 'VAPOR', 'INDEPENDENT', 'COOKIES', 'WEALTH', 'PENNSYLVANIA', 'EXPLANATION', 'DAMAGE', 'OCCASIONALLY', 'EXIST', 'SIMPLEST', 'PLATES', 'CANAL', 'NEIGHBORHOOD', 'PALACE', 'ADVICE', 'LABEL', 'DANNY', 'CLAWS', 'RUSH', 'CHOSE', 'EGYPT', 'POETRY', 'BREEZE', 'WOLF', 'MANUFACTURING', 'OURSELVES', 'SCARED', 'ARRANGEMENT', 'POSSIBLY', 'PROMISED', 'BRICK', 'ACRES', 'TREATED', 'SELECTION', 'POSITIVE', 'CONSTANTLY', 'SATISFIED', 'ZOO', 'CUSTOMS', 'UNIVERSITY', 'FIREPLACE', 'SHALLOW', 'INSTANT', 'SALE', 'PRACTICAL', 'SILLY', 'SATELLITES', 'SHAKING', 'ROCKY', 'SLOPE', 'CASEY', 'REMARKABLE', 'RUBBED', 'HAPPILY', 'MISSION', 'CAST', 'SHAKE', 'REQUIRE', 'DONKEY', 'EXCHANGE', 'JANUARY', 'MOUNT', 'AUTUMN', 'SLIP', 'BORDER', 'LEE', 'MELTED', 'TRAP', 'SOLAR', 'RECALL', 'MYSTERIOUS', 'SWUNG', 'CONTRAST', 'TOY', 'GRABBED', 'AUGUST', 'RELATIONSHIP', 'HUNTER', 'DEPTH', 'FOLKS', 'DEEPLY', 'IMAGE', 'STIFF', 'RHYME', 'ILLINOIS', 'SPECIES', 'ADULT', 'FINEST', 'THUMB', 'SLIGHT', 'GRANDMOTHER', 'SHOUT', 'HARRY', 'MATHEMATICS', 'MILL', 'ESSENTIAL', 'TUNE', 'FORT', 'COACH', 'NUTS', 'GARAGE', 'CALM', 'MEMORY', 'SOAP']¶
-
hangman.view¶
View layer, printing and prompting.
-
hangman.view.
build_partial_picture
(remaining_turns)[source]¶ Generator, build the iconic hangman game status.
-
hangman.view.
draw_board
(game, message=<hangman.utils.FlashMessage object>)[source]¶ Present the game status with pictures.
- Clears the screen.
- Flashes any messages.
- Zip the two halves of the picture together.
+---------------------------------------------+ | message 45 x 1 | +---------------------------------------------+ | title 45 x 1 | +----------+----------------------------------+ | | | | | | | | | | | | | picture | misses | | 10 x 10 | 35 x 10 | | | | | | | | | | | | | +----------+----------------------------------+ | hits 45 x 1 | +---------------------------------------------+ Dare to pick a letter: _
Example output:
HANGMAN GAME _____ | | | | MISSES: | _ _ _ _ _ _ _ _ _ _ | | ________|_ _ _ _ _ _ _ _ Dare to pick a letter: _
Parameters: - game (hangman.Hangman) – game instance
- message (hangman.utils.FlashMessage) – flash message
Raises: hangman.utils.GameOverNotificationComplete