๐ 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
- Question Generation
- Randomly selects a start day (MondayโSunday).
- Applies the offset (operand) from
GameQuestion.answer
. -
Calculates the correct day using modulo arithmetic.
-
User Interaction
- Renders 7 buttons (MondayโSunday).
- Player selects a button to answer.
-
Handles correct/incorrect answers with attempt tracking.
-
Accessibility
- Announces each new question (e.g., "If today is Tuesday, what day will it be after 5 days?").
-
Ensures first question text receives focus for TalkBack users.
-
Game Flow
- Sequentially iterates through provided
GameQuestion
s. - Tracks elapsed time per question.
- 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
- onCreateView()
-
Inflate layout and map weekday buttons.
-
onViewCreated()
-
Assigns click listeners for all 7 buttons โ calls
checkAnswer()
. -
onDestroyView()
-
Cleans up binding to prevent memory leaks.
-
onQuestionsLoaded()
- Loads all
GameQuestion
s. - If empty โ shows "No questions available".
- 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) tocorrectDay
. - 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.