Skip to content

Add timed mode, a hint system, and length-based tries#256

Open
shayanmohd wants to merge 1 commit into
selenide-examples:mainfrom
shayanmohd:feature/timed-mode-and-hints
Open

Add timed mode, a hint system, and length-based tries#256
shayanmohd wants to merge 1 commit into
selenide-examples:mainfrom
shayanmohd:feature/timed-mode-and-hints

Conversation

@shayanmohd

@shayanmohd shayanmohd commented Jul 4, 2026

Copy link
Copy Markdown

Add timed mode, a hint system, and length-based tries

Extends the game with a few optional mechanics, all reachable from the UI. The classic flow (untimed, six tries) still works; the new pieces are opt-in from the start screen.

Mode select

A start screen to choose Timed or Untimed. In timed mode a countdown (a base allowance plus a few seconds per letter) runs while you guess; running out loses the round.

Hints

Reveal one letter of the target word, unlocked only after a number of wrong guesses. Until then a locked label counts down how many more wrong guesses are needed.

Length-based tries

Allowed wrong guesses now scale with word length (6 + one per letter beyond five) instead of a fixed six, so longer words are fairer. Covered by new HangmanTest cases.

Also

  • Keyboard input for letters, a How to play panel, and a Play again flow.
  • Restyled board, timer and hint UI.
  • New message strings in English, Estonian and Russian.
  • Selenide UI specs and page objects updated for the new controls.

Checks

./gradlew check passes locally (compile + unit tests). The uitest_chrome / uitest_firefox jobs need a browser and weren't run on my machine, but the UI test sources compile.

Since this repo is primarily a Selenide example, happy to trim the scope (e.g. land just the UI-test additions, or split the gameplay features out) if that fits the project better. Just let me know.

Copilot AI review requested due to automatic review settings July 4, 2026 20:40

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends the Hangman web UI and backend with optional gameplay mechanics (timed mode, hints, and length-based allowed failures), updates the word list and i18n strings, and refreshes the Selenide/Selenium UI test suites and Gradle tasks to reflect the new UI flow.

Changes:

  • Add mode selection (timed/untimed), countdown timer, keyboard shortcuts, and a How-to-play modal in the web UI.
  • Add hint UI/logic and length-based maxErrors in the model + API responses.
  • Expand the dictionary and update unit/UI tests and Gradle UI-test tasks.

Reviewed changes

Copilot reviewed 16 out of 17 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
test/uitest/selenium_page_objects/HangmanWithPageObjectTest.java Updates Selenium UI tests for hint + mode selection flow (currently assumes deterministic words).
test/uitest/selenium_page_objects/HangmanPage.java Updates Selenium page object to support mode selection and hint elements.
test/uitest/selenide/HangmanSpec.java Updates/extends Selenide specs for hint/timer/how-to UI (currently assumes deterministic words).
test/uitest/selenide_page_objects/HangmanSpec.java Updates Selenide page-object specs for new flow (currently assumes deterministic words).
test/uitest/selenide_page_objects/HangmanPage.java Adds page-object actions for mode selection and hint.
test/ee/era/hangman/model/HangmanTest.java Adds unit tests for length-based maxErrors.
src/words.001.csv Expands word/topic inventory (increases randomness/variation for UI tests).
src/webapp/js/hangman.js Implements mode select, timer, hint lock/unlock, keyboard input, and updated failure rendering.
src/webapp/index.html Adds mode select UI, hint UI, SVG hangman, and How-to-play modal markup.
src/webapp/css/hangman.css Styles new toolbar/mode buttons/timer/hint UI and modal.
src/messages_ru.properties Adds i18n strings for hint/mode/how-to-play.
src/messages_et.properties Adds i18n strings for hint/mode/how-to-play.
src/messages_en.properties Adds i18n strings for hint/mode/how-to-play.
src/ee/era/hangman/model/Hangman.java Introduces length-based maxErrors and exposes it via getMaxErrors().
src/ee/era/hangman/actions/Guess.java Includes maxErrors in guess response JSON.
src/ee/era/hangman/actions/Game.java Includes maxErrors in start-game response JSON.
build.gradle Refactors UI test tasks to parameterize browser selection and scope to uitest/**.
Comments suppressed due to low confidence (1)

test/uitest/selenium_page_objects/HangmanWithPageObjectTest.java:55

  • These Selenium page-object tests assume the started game always uses the same word length ("____") and topic ("house"), but /game picks a random word from src/words.001.csv and max errors now depend on word length. With multiple words/topics per language, the assertions (and the win/lose flows that assume the word is "sofa" and 6 tries) become nondeterministic/flaky. Consider adding a deterministic word selection hook for UI tests (seeded RNG or test-only fixed word/topic parameter) and update the tests to use it.
  @Test
  public void showsMaskedWord() {
    assertThat(hangmanPage.wordInWork.getText()).isEqualTo("____");
  }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/webapp/js/hangman.js
Comment on lines +128 to +132
function revealHint() {
if (!isPlaying || elements.hintButton.disabled) return;
elements.topic.style.visibility = 'visible';
elements.hintButton.style.display = 'none';
elements.hintLocked.textContent = '';
Comment thread src/webapp/index.html
</button>
</div>

<div id="howToPlayModal" style="display: none;">
Comment on lines +22 to +24
public void revealHint() {
$("#hintButton").click();
}
Comment on lines +30 to +34
public void showsMaskedWordAndLockedHintAtTheBeginning() {
$("#wordInWork").shouldHave(text("____"));
$("#hintButton").shouldBe(disabled);
$("#topic").shouldNotBe(visible);
}
Comment on lines 20 to 23
@Test
public void showsTopicAndMaskedWordAtTheBeginning() {
page.shouldHaveTopic("house");
public void showsMaskedWordAtTheBeginning() {
page.shouldHaveWord("____");
}
Comment thread src/webapp/js/hangman.js
Comment on lines +262 to +263
updateHintLock();

Extend the game with several new mechanics:

- Mode select: a start screen to choose Timed or Untimed. In timed
  mode a countdown (a base allowance plus a few seconds per letter)
  runs while you guess, and running out loses the round.

- Hints: reveal one letter of the target word, unlocked only after a
  number of wrong guesses. Until then a locked label counts down how
  many more wrong guesses are needed.

- Length-based tries: the number of allowed wrong guesses now scales
  with word length (6 + one per letter beyond five) instead of a fixed
  six, so longer words are fairer.

- Keyboard input for letters, a "How to play" panel, and a "Play
  again" flow, with restyled board, timer and hint UI.

New message strings for all of the above in English, Estonian and
Russian. Adds model unit tests for the length-based try count and
extends the Selenide UI specs and page objects to cover the new
controls.
@shayanmohd
shayanmohd force-pushed the feature/timed-mode-and-hints branch from 90b7045 to 643c657 Compare July 4, 2026 20:51
@asolntsev

Copy link
Copy Markdown
Contributor

@shayanmohd All good, thank you for the contribution!
Happy to see the game is evolving! :)

  1. I think this principle is arguable:

Length-based tries
Allowed wrong guesses now scale with word length (6 + one per letter beyond five) instead of a fixed six, so longer words are fairer. Covered by new HangmanTest cases.

The long word is probably easier to guess. Because every letter player tries has greater chance to occur in the word.

  1. There are few AI comments on the PR that seem reasonable. Don't you want to fix them?
    E.g., why don't you use static import here?

$("#hintButton").shouldBe(com.codeborne.selenide.Condition.enabled).click();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants