@@ -0,0 +1,3192 @@
+package fr.polytech.quizz.services;%0A%0Aimport android.app.IntentService;%0Aimport android.content.Intent;%0Aimport android.support.annotation.Nullable;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.Collections;%0Aimport java.util.List;%0Aimport java.util.concurrent.atomic.AtomicInteger;%0A%0Aimport fr.polytech.quizz.entities.Question;%0Aimport fr.polytech.quizz.entities.IntentRequest;%0Aimport fr.polytech.quizz.entities.builders.QuestionBuilder;%0A%0Apublic class GameEngineIntentService extends IntentService %7B%0A%0A    public static final String INTENT_SERVICE_NAME = %22GameEngineIntentService%22;%0A%0A    public static final String REQUEST_MESSAGE_KEY = %22request%22;%0A%0A    public static final String QUESTION_MESSAGE_KEY = %22question%22;%0A%0A    public static final String ANSWER_MESSAGE_KEY = %22answer%22;%0A%0A    public static final String STATUS_MESSAGE_KEY = %22status%22;%0A%0A    public static String STATUS_ACTION = %22status_action%22;%0A%0A    public static String QUESTION_ACTION = %22question_action%22;%0A%0A    private static final List%3CQuestion%3E questions = new ArrayList%3CQuestion%3E();%0A%0A    private static final AtomicInteger counter = new AtomicInteger(0);%0A%0A    %7B%0A        questions.add(new QuestionBuilder().addQuestion(%22D'o%C3%B9 venez-vous ?%22).addAvailableAnswer(%22France%22).addAvailableAnswer(%22Allemagne%22).addAvailableAnswer(%22Italie%22).addAvailableAnswer(%22Suisse%22).addCorrectAnswer(%22France%22).build());%0A        questions.add(new QuestionBuilder().addQuestion(%22O%C3%B9 se situe Polytech Lyon ?%22).addAvailableAnswer(%22Paris%22).addAvailableAnswer(%22Marseille%22).addAvailableAnswer(%22Lyon%22).addAvailableAnswer(%22Toulouse%22).addCorrectAnswer(%22Lyon%22).build());%0A        Collections.shuffle(questions);%0A    %7D%0A%0A    public GameEngineIntentService() %7B%0A        super(INTENT_SERVICE_NAME);%0A    %7D%0A%0A    @Override%0A    protected void onHandleIntent(@Nullable Intent intent) %7B%0A        final IntentRequest userRequest = (IntentRequest) intent.getSerializableExtra(REQUEST_MESSAGE_KEY);%0A        switch (userRequest.getMessageKey()) %7B%0A            case QUESTION_MESSAGE_KEY:%0A                sendNextQuestion();%0A                break;%0A            case ANSWER_MESSAGE_KEY:%0A                checkSubmittedAnswer(userRequest.getMessage());%0A                break;%0A        %7D%0A    %7D%0A%0A    private void sendNextQuestion() %7B%0A        final int nextQuestionOffset = counter.getAndIncrement();%0A        final Question nextQuestion = (nextQuestionOffset %3C questions.size() ? questions.get(nextQuestionOffset) : null);%0A%0A        final Intent broadcastIntent = new Intent();%0A        broadcastIntent.setAction(QUESTION_ACTION);%0A        broadcastIntent.addCategory(Intent.CATEGORY_DEFAULT);%0A        broadcastIntent.putExtra(QUESTION_MESSAGE_KEY, nextQuestion);%0A        sendBroadcast(broadcastIntent);%0A    %7D%0A%0A    private void checkSubmittedAnswer(String submittedAnswer) %7B%0A        final Question currentQuestion = questions.get(counter.get());%0A%0A        final Intent broadcastIntent = new Intent();%0A        broadcastIntent.setAction(STATUS_ACTION);%0A        broadcastIntent.addCategory(Intent.CATEGORY_DEFAULT);%0A        broadcastIntent.putExtra(STATUS_MESSAGE_KEY, (currentQuestion.isCorrectAnswer(submittedAnswer) ? %22Answer correct!%22 : %22Answer incorrect!%22));%0A        sendBroadcast(broadcastIntent);%0A    %7D%0A%7D

Add intent service