0.0
No release in over 3 years
Low commit activity in last 3 years
Use this library to build your own HANGMAN game. HangmanEngine::Game have all you need to control the game flow. HangmanEngine::Drawer will help you to build a console based interface for your HangmanEngine::Game
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

hangman_engine

Use this library to build your own HANGMAN game in ruby.

Installation

Run from your command line:

$ gem install 'hangman_engine'

Then, require it on your file:

require 'hangman_engine'

Usage

Game Flow

All you need to control your Hangman game flow is in HangmanEngine::Game. To get started, create a new instace:

# - Parameters
# word: the word to guess.
# allowed_attempts: number of attempts the player has to solve the game before losing.
# clue: short helper text for the player.
hangman_game = HangmanEngine::Game.new(word, allowed_attempts, clue)

After creating a HangmanEngine::Game instance, use its methods to control the game flow (getters and setters are not shown):

guess(ltr) # attempts to guess a letter.
guessed?(ltr) # determines whether the given letter was guessed or not.
remaining_attempts
solved? 
lost? # determines if the player has lost.
finished? # determines whether the game was solved or if the player has lost.

Game View

A helper class to help you build a console interface for the game is also included. HangmanEngine::Drawer is going to help you to display a HangmanEngine::Game in the console. Available methods are:

# Dinamically generate the game 'puppet' based on the length of the word to guess and the remaining attempts to guess it.
# 
#  O
# /|\
# / \
#
HangmanEngine::Drawer.draw_puppet(hangman_game)

# Draw the game board based on the word to guess and the guessed letters.
# 
# a _ f o _  _ _
# 
HangmanEngine::Drawer.draw_board(hangman_game)

Examples

List of Hangman games built using this library: