Ejemplo n.º 1
0
  private void parseGameSetupAndStart() {

    switch (mCurrentGameType) {
      case GAMETYPE_ALL_QUESTIONS:
        break;
      case GAMETYPE_CATEGORIES:
        break;
      case GAMETYPE_LEVELS:
        mCurrentGame =
            new ClassGameLevels(
                mCurrentGameType,
                3,
                10,
                10,
                mRestartLivesEachLevel,
                mTriviaDb,
                mTimeToAnswerQuestion);

        break;

      default:
        break;
    }

    mCurrentGame.setGameListener(this);
    // TODO: change this to start from certain level
    mCurrentGame.setupNewGame(0);
    textViewLivesLeftValue.setText(mCurrentGame.getCurrentLivesAsString());
    textViewGameScoreText.setText(mCurrentGame.getGameScoreAsString());
    showStartLevel();
  }
Ejemplo n.º 2
0
  @Override
  public void onDisplayQuestion(Question currentQuestion) {
    if (currentQuestion != null) {
      resetAnswerButtonBackground(R.drawable.blue_button);
      initializeQuestionTextViews(currentQuestion);
      textViewNumberOfQuestionsLeft.setText(mCurrentGame.getNumberOfQuestionsLeftAsString());
      enableAnswerButtons();
      mCurrentGame.questionClockStart();
    } else {

    }
  }
Ejemplo n.º 3
0
  private void checkAnswer(int i, Button o_Button) {
    //
    mCurrentGame.questionClockStop();
    // this is implemented in order to prevent double click
    disableAnswerButtons();

    // checking if time is up
    if (i == -1) {
      startSoundFromSoundPool(mSoundAnswerWrong, 0);
      mCurrentGame.checkIsAnswerCorrect(i);

    } else if (i == -2) {
      // if pass question pressed
    } else {
      if (mCurrentGame.checkIsAnswerCorrect(i)) {

        setButtonGreen(o_Button);

        startSoundFromSoundPool(mSoundAnswerCorrect, 0);

        mTriviaDb.incUserCorrectCounter(mCurrentQuestion.getQuestionId());

        toastLastScore();
        setGameScoreText(mCurrentGame.getGameScoreAsString());
      } else {

        startSoundFromSoundPool(mSoundAnswerWrong, 0);

        setButtonRed(o_Button);
        mTriviaDb.incUserWrongCounter(mCurrentQuestion.getQuestionId());

        // checking if the user answer wrong and we need to show the
        // correct answer
        if (mShowCorrectAnswer) {
          setButtonGreen(mCurrentQuestion.getCorrectAnswerIndex());
        }
      }
    }

    textViewLivesLeftValue.setText(mCurrentGame.getCurrentLivesAsString());

    new StartNewQuestionAsync().execute(1000);
  }
Ejemplo n.º 4
0
  private void toastLastScore() {
    //
    Toast t =
        Toast.makeText(
            this, "" + "(+" + mCurrentGame.getLastAddedScore() + ")", Toast.LENGTH_SHORT);

    t.setGravity(Gravity.TOP, textViewGameScoreText.getLeft(), textViewGameScoreText.getTop());
    t.setMargin(0, 0);

    t.show();
  }
Ejemplo n.º 5
0
  private void initializeQuestionTextViews(Question currentQuestion) {
    //
    mCurrentQuestion = currentQuestion;

    if (mReverseNumbersInQuestions) {
      textViewQuestion.setText(
          mStringParser.reverseNumbersInStringHebrew(
              mCurrentGame.getCurrentQuestion().getQuestion()));

      textViewTimesPlayedTitle.setText(
          mStringParser.reverseNumbersInStringHebrew(
              getString(R.string.textViewTimesPlayedTitleText)
                  + mCurrentGame.getCurrentQuestion().getQuestionTimesPlayed()));
    } else {
      textViewQuestion.setText(mCurrentGame.getCurrentQuestion().getQuestion());
      textViewTimesPlayedTitle.setText(
          getString(R.string.textViewTimesPlayedTitleText)
              + " "
              + mCurrentGame.getCurrentQuestion().getQuestionTimesPlayed());
    }
    // setting question difficulty
    textViewQuestionLevel.setText(mCurrentGame.getCurrentLevelAsString());

    textViewHowManyTimesQuestionsBeenAsked.setText(
        mCurrentGame.getHowManyTimesQuestionsBeenAsked());

    // randomize answer places (indices)
    mCurrentQuestion.randomizeAnswerPlaces(m_Random);

    buttonAnswer1.setText(mCurrentQuestion.getAnswer1());
    buttonAnswer2.setText(mCurrentQuestion.getAnswer2());
    buttonAnswer3.setText(mCurrentQuestion.getAnswer3());
    buttonAnswer4.setText(mCurrentQuestion.getAnswer4());
  }
Ejemplo n.º 6
0
  private void showGameOver() {

    // send score
    if (getGamesClient().isConnected()) {
      getGamesClient()
          .submitScore(getString(R.string.game_levels_leadersboard), mCurrentGame.getGameScore());
    }

    mCurrentGame.questionClockStop();

    AlertDialog.Builder gameOverDialog = new AlertDialog.Builder(this);
    gameOverDialog.setTitle(getString(R.string.game_over));
    gameOverDialog.setCancelable(false);
    gameOverDialog.setPositiveButton(
        getString(R.string.exit),
        new DialogInterface.OnClickListener() {

          @Override
          public void onClick(DialogInterface dialog, int which) {
            //
            finish();
          }
        });
    gameOverDialog.setNegativeButton(
        getString(R.string.new_game),
        new DialogInterface.OnClickListener() {

          @Override
          public void onClick(DialogInterface dialog, int which) {
            //

            parseGameSetupAndStart();
          }
        });
    if (!isFinishing()) {
      gameOverDialog.show();
    }
  }
Ejemplo n.º 7
0
  private void showStartLevel() {

    // verifying clock is stopped
    mCurrentGame.questionClockStop();

    AlertDialog.Builder levelFinished = new AlertDialog.Builder(this);
    levelFinished.setTitle("שלב" + " " + mCurrentGame.getNextLevelAsString());
    levelFinished.setCancelable(false);
    levelFinished.setPositiveButton(
        getString(R.string.start),
        new DialogInterface.OnClickListener() {

          @Override
          public void onClick(DialogInterface dialog, int which) {
            //
            mCurrentGame.startNewRound();
          }
        });

    if (!isFinishing()) {
      levelFinished.show();
    }
  }