Interactive Play

As you consider interactive play, you’ll need to make a few additions to the program. Right now the game only returns the final score, but an interactive game should report progress as the game progresses. Also, right now you’re choosing the word to guess, but we really need to let the program choose a random word so it’s a mystery to a human player.

Let’s tackle the random word first. Included in the hangman project is a file words.txt, which contains about 4000 words that you can use as a word bank. First, read those words into a data structure.

 (​defn​ valid-letter? [c]
  (<= (int ​\a​) (int c) (int ​\z​)))
 
 (defonce available-words
  (with-open [r (jio/reader ​"words.txt"​)]
  (->> (line-seq ...

Get Programming Clojure, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.