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
- Host: GitHub
- URL: https://github.com/janeberry/hangman
- Owner: janeberry
- Created: 2024-05-27T04:34:06.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-08-11T01:07:51.000Z (almost 2 years ago)
- Last Synced: 2025-02-28T07:07:38.819Z (over 1 year ago)
- Topics: data-structures, linked-list, lists
- Language: Java
- Homepage:
- Size: 24.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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()