A .NET library for integrating Hangman game in different projects.
Class | Methods | Properties | Events |
---|---|---|---|
HangmanGame | 5 | 11 | 4 |
HangmanDifficulty | 2 | 6 | 0 |
HangmanGameReport | 0 | 2 | 0 |
HangmanGameState | 0 | 10 | 0 |
Enums | Values |
---|---|
HangmanState | 5 |
HangmanResult | 6 |
Exception |
---|
HangmanException |
HangmanGameAlreadyStartedException |
HangmanGameNotStartedException |
HangmanGameUnableToStartException |
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 |
Initializes a HangmanGame object with a defined Difficulty Level
HangmanGame _gameHandler = new HangmanGame(HangmanDifficulty.Easy);
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.
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.
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.
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.
Returns a String with the rules of the game and available Difficulties.
Returns an Integer with the won games;
Returns an Integer with the lost games;
Returns a TimeSpan with the time elapsed since the game started;
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.
Returns a Boolean with game's current active state.
Returns a String with the hidden word.
Returns a String with the hidden word beeing dashed and spaced only with the found letters.
Returns a String List with all the correct letters found in this game session.
Returns a String List with all the incorrect letters found in this game session.
Returns a List type of HangmanGameReport containing all the previous game records.
Event triggered when the game stops for any reason. Event emmits a HangmanGameReport object.
public delegate void HangmanGameFinishedEventHandler(HangmanGameReport report);
Event triggered when the game starts. Event emmits a HangmanGameState object.
public delegate void HangmanGameStartedEventHandler(HangmanGameState state);
Event triggered when TrySolve or TryLetter is invoked. Event emmits a HangmanGameState object.
public delegate void HangmanAttemptEventHandler(HangmanGameState state);
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);
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 |
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);
Returns a String with Object's information.
Returns the Difficulty name.
Returns the maximum Toleretable Errors.
Returns the minimum word letters.
Returns whether the game's difficulty is time limited.
###HangmanDifficulty.TimeLimit Returns the time limit in seconds
Returns a List of HangmanDifficulty Objects.
Returns an easy HangmanDifficulty Object.
Returns a medium HangmanDifficulty Object.
Returns a hard HangmanDifficulty Object.
Returns an extreme HangmanDifficulty Object.
Property | Modifier | Return Type |
---|---|---|
Result | HangmanResult | |
Word | String | |
State | HangmanGameState |
Returns a HangmanResult enum value.
Returns a String containing the game's word.
Returns a HangmanGameState object.
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 |
Returns a TimeSpan with the time elapsed from start since this game state.
Returns a HangmanDifficulty object with the game's difficulty.
Returns a String with the hidden word beeing dashed and spaced only with the found letters.
Returns a String List with all the correct letters found in this game session.
Returns a String List with all the incorrect letters found in this game session.
Returns the length of the word.
Returns the number of found letters on the hidden word.
Returns a HangmanState enum value.
Returns the number of correct attempts.
Returns the number of failed attempts.
Name | Value |
---|---|
LetterTried | 0 |
SolveTried | 1 |
Started | 2 |
Stopped | 3 |
Finished | 4 |
Name | Value |
---|---|
WonByGuessing | 0 |
WonByTrying | 1 |
LostTimeout | 2 |
LostErrors | 3 |
LostByGuessing | 4 |
Stopped | 5 |