Created
June 19, 2015 15:41
-
-
Save marinoluck/96c07cda04169c92dcae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public claas QuizState implements Parceable { | |
private int currentPromptNumber; | |
private long quizId; | |
private boolean opponentAnswered; | |
private boolean userAnswered; | |
private int loopAccumulatedTime; | |
private long outTimestamp; | |
private String currentPromptLoop; // START, PLAYING, END | |
private Map<Integer, Response> playerResponses; // responses that the player answered till the pause. | |
} | |
public void onPause() { | |
state = new QuizState(); | |
state.setQuizId(quiz.getId()); | |
state.setCurrentPromptNumber(currentPrompt.getPosition()); | |
//...... the other fields | |
currentLoop.stop(); | |
} | |
public void onResume() { | |
//Recreate the whole state of the game | |
chatHolder.remeoveAllViews(); // remove al views if there are any | |
// recreate complete prompts till current momment | |
for (int = 1; i < state.getCurrentPromptId()) { | |
quizController.getNextPrompt(); | |
// simulate the game state as well it was played | |
// add views with opponent and user responses | |
// add the user responses to the quiz controller | |
} | |
// now continue with the loop was running at the time | |
if (state.getCurrentPromptLoop().equals(START_LOOP_ID)) { | |
runStartLoop(START_LOOP_DELAY - state.getLoopAccumulatedTime()); | |
} else if (state.getCurrentPromptLoop().equals(PROMPT_LOOP_ID)) { | |
// TODO addquestion and options simulating the start loop already ran | |
runStartLoop(PROMPT_LOOP_DELAY - state.getLoopAccumulatedTime()); | |
} else if (state.getCurrentPromptLoop().equals(PROMPT_END_ID)) { | |
runStartLoop(PROMPT_END_DELAY - state.getLoopAccumulatedTime()); | |
} | |
} | |
public void onSaveInstanceState(Bundle savedInstanceState) { | |
// Save the user's current game state | |
savedInstanceState.putParceable(STATE_QUIZ, state); | |
// Always call the superclass so it can save the view hierarchy state | |
super.onSaveInstanceState(savedInstanceState); | |
} | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); // Always call the superclass first | |
// Check whether we're recreating a previously destroyed instance | |
if (savedInstanceState != null) { | |
// Restore value of members from saved state | |
state = savedInstanceState.getParceable(STATE_QUIZ); | |
//TODO ask the quiz by ID stat.getQuizId and other objects we need | |
} else { | |
// Probably initialize members with default values for a new instance | |
} | |
... | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment