The goal of this project is to create a command-line Hangman game in Golang. The script lets you play Hangman by guessing letters of a hidden word, with a limited number of attempts.
fmtfor displaying output and reading user inputosfor handling command-line arguments and exiting on errorstringsfor formatting output- Slices and runes for word and letter management
If you don't have Golang installed, run:
sudo apt update
sudo apt install golang-goRun the script with the following argument:
go run . <word><word>: the word to guess (letters only, no spaces or symbols)
go run . bananeYou should see something like:
What you currently found:
_ _ _ _ _ _
The letters you already chose:
You still have 10 lives
Choose a letter: Then, follow the prompts to guess letters. The game ends when you find the word or run out of lives.
If you provide an invalid word (with non-letter characters), the script will print an error message and exit.
Enjoy playing Hangman in your terminal!