Practice

Time to practice!

You’ve just seen @Composable functions, state hoisting, and recomposition at work in FizzBuzz. Time to build your own small Jetpack Compose app from scratch: Hangman.

Rules

  • Timebox: 1h30, split roughly as suggested below.

  • Start a fresh Android Studio project from the "Empty Activity" template (see Create a project) and run it on an emulator or on your own paired device (see Pairing Device).

  • Borrow and adapt whatever you need from FizzBuzzMVP.kt: the composable building blocks (Text, Button, Column/Row, LazyVerticalGrid…​) and the state hoisting pattern.

  • The hangman figure is not required: a plain remaining-attempts counter is enough.

Part 1 (~1h): a guessable word

Design a screen that picks a word at random and lets the player guess it one letter at a time.

  • Pick a single word at random from a small hardcoded list (e.g. listOf("COMPOSE", "KOTLIN", "ANDROID")) the first time the screen is shown.

  • Display the word masked, one character per letter: already-guessed letters are shown, the rest are hidden behind an underscore (e.g. _ O M P O S E once "O" has been guessed). A single Text built from the target word and the set of guessed letters is enough — no need for one composable per letter.

  • Build a virtual keyboard: one Button per letter A-Z. A LazyVerticalGrid (as in FizzBuzzFinal.kt) or a handful of `Row`s both work well.

  • Tapping a letter adds it to a set of guessed letters hoisted at the screen level, exactly like FizzBuzzScreen hoists maximum, fizzDivisor, and buzzDivisor. The keyboard composable itself should hold no state of its own, it only reports taps upward through a callback.

  • Already-guessed letters should be reflected on the keyboard itself (for example, disabled or recolored) so the player never has to remember what they already tried.

Part 2 (~30 min): winning, losing, and trying again

  • Track a remaining-attempts counter (e.g. starting at 6) that decrements each time a guessed letter isn’t in the word.

  • Detect the two end states — every letter revealed (win), or no attempts left (lose) — and display an appropriate message in each case.

  • Add a button to restart with a new random word, resetting every piece of state back to its initial values.

Stretch goal

  • A letter that was already guessed shouldn’t be guessable (or countable) again.

  • When the player loses, reveal the full word.

  • Instead of a single hardcoded list, group words by category (animals, countries, …​) and show the category as a hint.