Skip to content

๐Ÿ“… Day Game Mode (Developer Docs)

The DayFragment implements the Day Game Mode in zMantra.
This mode challenges players to calculate the day of the week after a given offset.
For example: "If today is Monday, what day will it be after 3 days?"

It provides a multiple-choice button interface (Mondayโ€“Sunday) and is fully accessible with TalkBack.


๐Ÿ“‚ Location

com.zendalona.zmantra.presentation.features.game.day.DayFragment


๐Ÿ”‘ Core Responsibilities

  1. Question Generation
  2. Randomly selects a start day (Mondayโ€“Sunday).
  3. Applies the offset (operand) from GameQuestion.answer.
  4. Calculates the correct day using modulo arithmetic.

  5. User Interaction

  6. Renders 7 buttons (Mondayโ€“Sunday).
  7. Player selects a button to answer.
  8. Handles correct/incorrect answers with attempt tracking.

  9. Accessibility

  10. Announces each new question (e.g., "If today is Tuesday, what day will it be after 5 days?").
  11. Ensures first question text receives focus for TalkBack users.

  12. Game Flow

  13. Sequentially iterates through provided GameQuestions.
  14. Tracks elapsed time per question.
  15. Limits incorrect attempts to 3 before showing the correct answer.

โš™๏ธ Key Fields

Variable Type Purpose
_binding / binding FragmentGameDayBinding View binding for layout.
days List<String> Ordered list of weekdays.
buttons List<Button> References to 7 day buttons.
correctDay String Correct answer for current question.
questionStartTime Long Timestamp when question started.
totalTime Double Time limit for answering (30s).
isFirstQuestion Boolean Ensures TalkBack focus only for first question.
questions List<GameQuestion> List of all questions in this game mode.
questionIndex Int Current index in questions list.

๐Ÿ”„ Lifecycle

  1. onCreateView()
  2. Inflate layout and map weekday buttons.

  3. onViewCreated()

  4. Assigns click listeners for all 7 buttons โ†’ calls checkAnswer().

  5. onDestroyView()

  6. Cleans up binding to prevent memory leaks.

  7. onQuestionsLoaded()

  8. Loads all GameQuestions.
  9. If empty โ†’ shows "No questions available".
  10. Otherwise โ†’ starts with generateQuestion().

๐Ÿ“ Question Generation

```kotlin val correctIndex = (startDayIndex + operand) % 7 correctDay = days[correctIndex] ````

  • Random start day chosen.
  • Operand (from questionโ€™s answer) applied as an offset.
  • Uses modulo % 7 to wrap around the week.
  • Sets correctDay.

Example:

  • Start = Friday, Operand = 3 โ†’ Answer = Monday.

โœ… Answer Validation

  • checkAnswer(selected: String):

  • Compares selected (button text) to correctDay.

  • Tracks elapsedTime.
  • Correct answer โ†’ disables buttons, moves to next question.
  • Incorrect answer โ†’ increments attemptCount.

    • If attempts โ‰ฅ 3 โ†’ shows correct answer, disables buttons, moves to next question.
    • Else โ†’ allows retry.

๐ŸŽง Accessibility

  • Announces question text aloud for TalkBack.
  • Example: "If today is Thursday, what day will it be after 2 days?"
  • Ensures focus on first question text for screen reader users.

๐Ÿงช Testing Notes

  • Validate day offset calculation (including wrap-around, e.g., Saturday + 3 = Tuesday).
  • Ensure attempt limit (3) works correctly.
  • Check time tracking (30s limit passed to handleAnswerSubmission).
  • Verify accessibility announcements.
  • Confirm buttons disable after correct/incorrect completion.