Skip to content

ProIcons/HangmanSharp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hangman Game Library (.NET)

Build status


A .NET library for integrating Hangman game in different projects.

Classes

Class Methods Properties Events
HangmanGame 5 11 4
HangmanDifficulty 2 6 0
HangmanGameReport 0 2 0
HangmanGameState 0 10 0

Enums

Enums Values
HangmanState 5
HangmanResult 6

Exceptions

Exception
HangmanException
HangmanGameAlreadyStartedException
HangmanGameNotStartedException
HangmanGameUnableToStartException

HangmanGame Class

Method Modifier Return Type Parameters
HangmanGame Constructor HanngmanDifficulty
StartGame void String/void
StopGame void void
TryLetter void char/string
TrySolve void String
Property Modifier Return Type
Rules String
WonGames int
LostGames int
TimeElapsed TimeSpan
Difficulty HanngmanDifficulty
IsGameStarted bool
GivenWord String
DisplayWord String
CorrectLetters List<String>
IncorrectLetters List<String>
History List<HangmanGameReport>
Event Parameters
OnFinish HangmanGameReport
OnStart HangmanGameState
OnAttempt HangmanGameState
OnSecondElapsed HangmanGameState

Methods

HangmanGame (HangmanDifficulty)

Initializes a HangmanGame object with a defined Difficulty Level

HangmanGame _gameHandler = new HangmanGame(HangmanDifficulty.Easy);

HangmanGame.StartGame (String = null)

Starts the game with a random word fetched from a word provider service. If parameter is defined starts the game with the word defined.

Without parameter

HangmanGame _gameHandler = new HangmanGame(HangmanDifficulty.Easy);
_gameHandler.StartGame();

With parameter

HangmanGame _gameHandler = new HangmanGame(HangmanDifficulty.Easy);
_gameHandler.StartGame("test");
  • Throws HangmanGameAlreadyStartedException if game is already started.
  • Throws HangmanGameUnableToStartException if word provider is offline and no parameter is given.

HangmanGame.StopGame (void)

Stops the game if is started. When it stops the game, a point to LostGames is beeing added.

HangmanGame _gameHandler = new HangmanGame(HangmanDifficulty.Easy);
_gameHandler.StartGame();
_gameHandler.StopGame();
  • Throws HangmanGameNotStartedException if game is already started.

HangmanGame.TryLetter (char / string)

If game is started it tries to find a letter on the word.

Raises an OnAttempt event.

HangmanGame _gameHandler = new HangmanGame(HangmanDifficulty.Easy);
_gameHandler.StartGame();
_gameHandler.TryLetter('c');
_gameHandler.TryLetter("a");
  • Throws HangmanException if char is not in [a-Z] range.
  • Throws HangmanException if string is more than 1 character.
  • Throws HangmanException if string is not in [a-Z] range.
  • Throws HangmanGameNotStartedException if game is not started.

HangmanGame.TrySolve (string)

If game is started it tries to solve the game. If guess is correct player wins the game, and a point is added on WonGames, otherwise a point is added on LostGames

Raises an OnAttempt event.

HangmanGame _gameHandler = new HangmanGame(HangmanDifficulty.Easy);
_gameHandler.StartGame();
_gameHandler.TrySolve("Test");
  • Throws HangmanException if string is not in [a-Z] range.
  • Throws HangmanGameNotStartedException if game is not started.

Properties

HangmanGame.Rules

Returns a String with the rules of the game and available Difficulties.

HangmanGame.WonGames

Returns an Integer with the won games;

HangmanGame.LostGames

Returns an Integer with the lost games;

HangmanGame.TimeElapsed

Returns a TimeSpan with the time elapsed since the game started;

HangmanGame.Difficulty

Returns a HangmanDifficulty Object with the Difficulty of the currect active game. Sets the Difficulty of the next game. If game is active it will get changed after game finishes.

HangmanGame.IsGameStarted

Returns a Boolean with game's current active state.

HangmanGame.GivenWord

Returns a String with the hidden word.

HangmanGame.DisplayWord

Returns a String with the hidden word beeing dashed and spaced only with the found letters.

HangmanGame.CorrectLetters

Returns a String List with all the correct letters found in this game session.

HangmanGame.IncorrectLetters

Returns a String List with all the incorrect letters found in this game session.

HangmanGame.History

Returns a List type of HangmanGameReport containing all the previous game records.


Events

HangmanGame.OnFinish

Event triggered when the game stops for any reason. Event emmits a HangmanGameReport object.

public delegate void HangmanGameFinishedEventHandler(HangmanGameReport report);

HangmanGame.OnStart

Event triggered when the game starts. Event emmits a HangmanGameState object.

public delegate void HangmanGameStartedEventHandler(HangmanGameState state);

HangmanGame.OnAttempt

Event triggered when TrySolve or TryLetter is invoked. Event emmits a HangmanGameState object.

public delegate void HangmanAttemptEventHandler(HangmanGameState state);

HangmanGame.OnSecondElapsed

Event triggered every second after the game is started. Used for Timeout Checking, and Time calculating. Event emmits a HangmanGameState object.

public delegate void HangmanSecondElapsedEventHandler(HangmanGameState state);

HangmanDifficulty Class

Method Modifier Return Type Parameters
HangmanDifficulty Constructor String, int, int, bool, int
ToString String void
Property Modifier Return Type
Name String
ToleretableErrors int
MinimumLetters int
IsTimeLimited bool
TimeLimit int
List Static List<HangmanDifficulty>
Easy Static HangmanDifficulty
Medium Static HangmanDifficulty
Hard Static HangmanDifficulty
Extreme Static HangmanDifficulty

Methods

HangmanDifficulty(string,int,int,bool,int)

Initializes a HangmanDifficulty object with user defined game constraints

Parameters:

Type Name Constraints Description
String Name Defines the name of the Difficulty
int toleretableErrors [0-6] Defines the maximum toleretable errors a user can do.
int minimumLetters [4-20] Defines the minimum letter count.
bool isTimeLimited true/false Defines whether the game will be time limited. [Optional]
int TimeLimit [0-3600] Defines the time limit in seconds. [Optional]
HangmanDifficulty difficulty = new HangmanDifficulty("Custom Difficulty",1,10,true,300);
HangmanGame _gameHandler = new HangmanGame(difficulty);

HangmanDifficulty.ToString()

Returns a String with Object's information.


Properties

HangmanDifficulty.Name

Returns the Difficulty name.

HangmanDifficulty.ToleretableErrors

Returns the maximum Toleretable Errors.

HangmanDifficulty.MinimumLetters

Returns the minimum word letters.

HangmanDifficulty.IsTimeLimited

Returns whether the game's difficulty is time limited.

###HangmanDifficulty.TimeLimit Returns the time limit in seconds

HangmanDifficulty.List

Returns a List of HangmanDifficulty Objects.

HangmanDifficulty.Easy

Returns an easy HangmanDifficulty Object.

HangmanDifficulty.Medium

Returns a medium HangmanDifficulty Object.

HangmanDifficulty.Hard

Returns a hard HangmanDifficulty Object.

HangmanDifficulty.Extreme

Returns an extreme HangmanDifficulty Object.


HangmanGameReport Class

Property Modifier Return Type
Result HangmanResult
Word String
State HangmanGameState

Properties

HangmanGameReport.Result

Returns a HangmanResult enum value.

HangmanGameReport.Word

Returns a String containing the game's word.

HangmanGameReport.State

Returns a HangmanGameState object.


HangmanGameState Class

Property Modifier Return Type
TimeElapsed TimeSpan
Difficulty HanngmanDifficulty
DisplayWord String
CorrectLetters List<String>
IncorrectLetters List<String>
CorrectAttempts int
FailedAttemmpts int
TotalLetters int
FoundLetters int
State HangmanState

Properties

HangmanGameState.TimeElapsed

Returns a TimeSpan with the time elapsed from start since this game state.

HangmanGameState.Difficulty

Returns a HangmanDifficulty object with the game's difficulty.

HangmanGameState.DisplayWord

Returns a String with the hidden word beeing dashed and spaced only with the found letters.

HangmanGameState.CorrectLetters

Returns a String List with all the correct letters found in this game session.

HangmanGameState.IncorrectLetters

Returns a String List with all the incorrect letters found in this game session.

HangmanGameState.TotalLetters

Returns the length of the word.

HangmanGameState.FoundLetters

Returns the number of found letters on the hidden word.

HangmanGameState.State

Returns a HangmanState enum value.

HangmanGameState.CorrectAttempts

Returns the number of correct attempts.

HangmanGameState.FailedAttempts

Returns the number of failed attempts.


HangmanState Enum

Values

Name Value
LetterTried 0
SolveTried 1
Started 2
Stopped 3
Finished 4

HangmanResult Enum

Values

Name Value
WonByGuessing 0
WonByTrying 1
LostTimeout 2
LostErrors 3
LostByGuessing 4
Stopped 5

Examples

Console


GUI