猫Riddlerの仕様書

自己開発のゲームの設計を記録して見ます。
Check Promotion部分

1. Detecting all riddles for a level are clear.
This is based on a comparison of two ScoreTracker data members: numRiddles and riddleNum. Analogous members are kept in the RiddleGroup class maintained by Game within GameServerEngine, but the riddle number on the server is reset after all players have checked answers for the last riddle on a level. Thus, by the time handleContinue in the ContinueListener checks the riddle number against the number of riddles in the level, the riddle number will be less than this number in most cases (unless numRiddles for a level is one, in which case we do not want to check promotion anyways), so no promotion check will occur.
2. Updating riddle number on server.
Previously, the riddle number was incremented by updateScores and the level was adjusted by checkPromotedStatus. However, the logic will change such that both the level and the riddle number will be adjusted by update scores. This will prevent the problem of a promotion occurring twice, when the continue listener code was entered twice before all players had called checkPromotionStatus.

3. Continuing after an answer checked (Client).
The handle continue method must determine whether the riddle whose answer was just checked was the last one or not. This is based on the riddleNum and numRiddles cached in ScoreTracker (compare with <).
Even if the number of riddles is one, this will not be a problem, as after a promotion the ScoreTracker fields will not have been reset (and if the number of riddles was one for the previous level, the justPromoted check will prevent another promotion).

4. Waiting for all players to continue.
This occurs in a while loop in the ContinueThread. When all players have called checkAnswerUpdateScores, canContinue is set to true and the while loop breaks. Then the riddle number of ScoreTracker and numRiddles are again checked. This code is needed, because, if a player is not the last to submit his answer for the last level of a riddle, the promotion check must occur before any continuation to the next riddle can be carried out (ie game may be over).
UPDATE: Actually, the check of numRiddles and current riddle in ContinueThread is unnecessary, as this code will not be entered until after promotion has been handled by processLast once and then doNextRiddle is called again by processLast (when getJustPromoted returns true). At this point, when the while loop breaks, doNextRiddleBody can be called directly (processLastFromThread is unnneeded).

5. Updating riddle and level (client).
Currently, the ScoreTracker level and riddleNumber are updated in doNextRiddleBody. However, the ScoreTracker numRiddles member must also be updated here. This value is checked in handleContinue, and must contain the number of riddles for the current level(ie it must be updated when the first riddle after a promotion is displayed).
UPDATE: numRiddles will be updated in GameSelectListener when the newGame method is invoked.

6. justPromoted member of ScoreTracker.
This is designed to handle the case where promotion has already occurred and another key press occurs to continue to the next riddle. ScoreTracker.riddleNum has not been reset yet (otherwise, if numRiddles in the next level is one, we would be checking for a promotion before the user has ansered). We want to skip all promotion logic and go to doNextRiddleBody.

7. numUncheckedPlayers in Game.
From now on, we need the riddles to be reloaded when the first player is promoted, not when the last one checks its status, as the player can continue to the next riddle before another player continues to check promoted status. Thus, we use the !someonePromoted check prior to loading the riddles, as we need reload only once for all players. We reset someonePromoted to false when all players' statuses have been checked.