An open API service indexing awesome lists of open source software.

https://github.com/janeberry/hangman

Classic Hangman Game
https://github.com/janeberry/hangman

data-structures linked-list lists

Last synced: 27 days ago
JSON representation

Classic Hangman Game

Awesome Lists containing this project

README

          

# Hangman Game
This is a classic Hangman game implemented in Java.

The game selects a random word from a predefined list, and the player must guess the word one letter at a time.

The player has a limited number of attempts to guess the word correctly before losing the game.

👾How to play game


You can play the game in Java Console.

```java
Hangman game = new Hangman();
game.playgame();
```

Field Declarations



  • words: String [], random words list

  • secretWord: String, the chosen secret word

  • correctLetters: List(Character), correct guesses


  • incorrectLetters: List(Character), incorrect guesses


  • stdin: Scanner, user input

Constructor



  • Randomly choose a word from list of words.

  • and set the word as a secretWord



  • Build a initial pattern with _ based on the secretWord (correctLetters)

  • initialize incorrectLetters using an ArrayList

```java
Random rand = new Random();
int randIndex = rand.nextInt(words.length);
this.secretWord = words[randIndex];
correctLetters = new ArrayList();
for (int i=0; i();
```

Methods



  • playGame()

  • handleGuess()

  • gameWon()

  • gameLost()

  • gameOver()

  • printHangman()

  • toString()

  • setCurrentWord()

  • setCorrectLetters()

  • setIncorrectLetters()

  • setBadGuesses()