A state cycle is a state-machine structure where transitions eventually return to an earlier state, allowing an interaction to repeat. In a trivia game, the flow moves from getting a question to asking it, showing a result, and—when the game continues—returning to GET_QUESTION. section 9.6.2
A practical implementation tracks the cycle through:
- A questions list, which records previously asked questions and supports question numbering. section 9.6.2
- A proceed_to_next_question method, which changes the status back to GET_QUESTION. section 9.6.2
- A Next question button, displayed after results when the game is not over. section 9.6.2
Multi-question trivia game
After a result appears, clicking Next question calls proceed_to_next_question(). The application then returns to GET_QUESTION, obtains another question, and repeats the cycle until the maximum question count is reached. section 9.6.2
Figure 9.11 To implement multiple questions, we now cycle through the game states in a loop.
Use the state diagram to follow the loop between question retrieval, question display, results, and the next-question transition. section 9.6.2
