app/src/main/java/com/zenappse/memorymatcher/TabbedGameActivity.java
@Override
    public void onCardItemClickInteraction(Card cardTapped) {
        gameController.cardTapped(cardTapped);

        final Card currentCard = cardTapped;
        if (gameController.isMatchingComplete() && !gameController.isMatchFound()) {

            runOnUiThread(new Runnable(){
                public void run() {
                    if (currentCard.getGameBoard() == 0) {
                        mGridOneFragment.onCardMatchNotFound(currentCard);
                    } else {
                        mGridTwoFragment.onCardMatchNotFound(currentCard);
                    }

                    Card previouslyTappedCard = gameController.getPreviousCardTapped();
                    if (previouslyTappedCard.getGameBoard() == 0) {
                        mGridOneFragment.onCardMatchNotFound(previouslyTappedCard);
                    } else {
                        mGridTwoFragment.onCardMatchNotFound(previouslyTappedCard);
                    }

                    mGridOneFragment.onScoreChange(gameController.getScore());
                    mGridTwoFragment.onScoreChange(gameController.getScore());
                }
            });

            gameController.resetCardMatching();

        } else if (gameController.isMatchingComplete()) {
            // Match found reset controller and increment score
            final boolean highscoreChanged = gameController.hasHighscoreChanged();
            runOnUiThread(new Runnable(){
                public void run() {
                    mGridOneFragment.onScoreChange(gameController.getScore());
                    mGridTwoFragment.onScoreChange(gameController.getScore());

                    if (highscoreChanged) {
                        mGridOneFragment.onHighScoreChange(gameController.getHighscore(), username);
                        mGridTwoFragment.onHighScoreChange(gameController.getHighscore(), username);
                    }
                }
            });

            if (highscoreChanged) {
                gameState.setRecordHolder(username);
                gameState.setHighscore(gameController.getHighscore());
            }

            gameController.resetCardMatching();
        }

        if (gameController.gameOver()) {
            showGameOverDialog();
        }
        gameState.setGameController(gameController);
        gameState.setCurrentScore(gameController.getScore());
        gameState.saveState();
    }
/**
     * Listener method that is invoked when a card is tapped on a GameGridFragment instance.
     * Performs the necessary functions in Game Controller and calls the callback to the
     * Fragments to flip cards back over and to update the score
     *
     * @param cardTapped Current Card that has been tapped
     */
Listener method that is invoked when a card is tapped on a GameGridFragment instance.
Performs the necessary functions in Game Controller and calls the callback to the
Fragments to flip cards back over and to update the score

@param cardTapped Current Card that has been tapped
Listener method that is invoked when a card is tapped on a GameGridFragment instance . Performs the necessary functions in Game Controller and calls the callback to the Fragments to flip cards back over and to update the score @param cardTapped Current Card that has been tapped
@Override
    public void onCardItemClickInteraction(Card cardTapped) {
        gameController.cardTapped(cardTapped);
        final Card currentCard = cardTapped;
        if (gameController.isMatchingComplete() && !gameController.isMatchFound()) {
            runOnUiThread(new Runnable(){
                public void run() {
                    if (currentCard.getGameBoard() == 0) {
                        mGridOneFragment.onCardMatchNotFound(currentCard);
                    } else {
                        mGridTwoFragment.onCardMatchNotFound(currentCard);
                    }
                    Card previouslyTappedCard = gameController.getPreviousCardTapped();
                    if (previouslyTappedCard.getGameBoard() == 0) {
                        mGridOneFragment.onCardMatchNotFound(previouslyTappedCard);
                    } else {
                        mGridTwoFragment.onCardMatchNotFound(previouslyTappedCard);
                    }
                    mGridOneFragment.onScoreChange(gameController.getScore());
                    mGridTwoFragment.onScoreChange(gameController.getScore());
                }
            });
            gameController.resetCardMatching();
        } else if (gameController.isMatchingComplete()) {
            final boolean highscoreChanged = gameController.hasHighscoreChanged();
            runOnUiThread(new Runnable(){
                public void run() {
                    mGridOneFragment.onScoreChange(gameController.getScore());
                    mGridTwoFragment.onScoreChange(gameController.getScore());
                    if (highscoreChanged) {
                        mGridOneFragment.onHighScoreChange(gameController.getHighscore(), username);
                        mGridTwoFragment.onHighScoreChange(gameController.getHighscore(), username);
                    }
                }
            });
            if (highscoreChanged) {
                gameState.setRecordHolder(username);
                gameState.setHighscore(gameController.getHighscore());
            }
            gameController.resetCardMatching();
        }
        if (gameController.gameOver()) {
            showGameOverDialog();
        }
        gameState.setGameController(gameController);
        gameState.setCurrentScore(gameController.getScore());
        gameState.saveState();
    }
@ Override public void onCardItemClickInteraction ( Card cardTapped ) { gameController . cardTapped ( cardTapped ) ; final Card currentCard = cardTapped ; if ( gameController . isMatchingComplete ( ) && ! gameController . isMatchFound ( ) ) { runOnUiThread ( new Runnable ( ) { public void run ( ) { if ( currentCard . getGameBoard ( ) == 0 ) { mGridOneFragment . onCardMatchNotFound ( currentCard ) ; } else { mGridTwoFragment . onCardMatchNotFound ( currentCard ) ; } Card previouslyTappedCard = gameController . getPreviousCardTapped ( ) ; if ( previouslyTappedCard . getGameBoard ( ) == 0 ) { mGridOneFragment . onCardMatchNotFound ( previouslyTappedCard ) ; } else { mGridTwoFragment . onCardMatchNotFound ( previouslyTappedCard ) ; } mGridOneFragment . onScoreChange ( gameController . getScore ( ) ) ; mGridTwoFragment . onScoreChange ( gameController . getScore ( ) ) ; } } ) ; gameController . resetCardMatching ( ) ; } else if ( gameController . isMatchingComplete ( ) ) { final boolean highscoreChanged = gameController . hasHighscoreChanged ( ) ; runOnUiThread ( new Runnable ( ) { public void run ( ) { mGridOneFragment . onScoreChange ( gameController . getScore ( ) ) ; mGridTwoFragment . onScoreChange ( gameController . getScore ( ) ) ; if ( highscoreChanged ) { mGridOneFragment . onHighScoreChange ( gameController . getHighscore ( ) , username ) ; mGridTwoFragment . onHighScoreChange ( gameController . getHighscore ( ) , username ) ; } } } ) ; if ( highscoreChanged ) { gameState . setRecordHolder ( username ) ; gameState . setHighscore ( gameController . getHighscore ( ) ) ; } gameController . resetCardMatching ( ) ; } if ( gameController . gameOver ( ) ) { showGameOverDialog ( ) ; } gameState . setGameController ( gameController ) ; gameState . setCurrentScore ( gameController . getScore ( ) ) ; gameState . saveState ( ) ; }
Listener method that is invoked when a card is tapped on a GameGridFragment instance.
Listener method that is invoked when a card is tapped on a GameGridFragment instance .
// Match found reset controller and increment score