Ejemplo n.º 1
0
  @Override
  public void restartBoard() {
    if (mHomeView == null) return;

    List<Integer> cardVals = new ArrayList<>();

    cardVals.clear();
    cardsList.clear();

    for (int i = 0; i < pairs; i++) {
      cardVals.add(i);
      cardVals.add(i);
    }

    Collections.shuffle(cardVals);

    for (int val : cardVals) {
      CardModel c = new CardModel();
      c.setId(val);
      cardsList.add(c);
    }
    c1 = null;
    c2 = null;
    bAllowClick = true;

    iUserScore = 0;
    mHomeView.updateScore(iUserScore);
    changeVisibilityCards();
    flipBackAllCards();
  }
Ejemplo n.º 2
0
  @Override
  public void doTurn(ImageView imageBoard, int position) {
    if (mHomeView == null) return;

    if (bAllowClick) {
      if (!cardsList.get(position).isMatched())
        if (c1 == null && !cardsList.get(position).isFlipped()) {
          cardsList.get(position).setFlipped(true);
          c1 = cardsList.get(position);
          mHomeView.flipCard(imageBoard, c1.getId());
        } else if (c2 == null && !cardsList.get(position).isFlipped()) {
          cardsList.get(position).setFlipped(true);
          c2 = cardsList.get(position);
          mHomeView.flipCard(imageBoard, c2.getId());

          bAllowClick = false;
          startTimer(1000);
        }
    }
  }
Ejemplo n.º 3
0
  @Override
  public void flipAllCards() {
    if (mHomeView == null) return;

    bAllowClick = false;

    for (int a = 0; a < cardsList.size(); a++)
      mHomeView.flipCard(cardsView.get(a), cardsList.get(a).getId());

    startTimer(3000);
  }
Ejemplo n.º 4
0
  @Override
  public void checkCards() {
    if (mHomeView == null) return;

    if (c1.getId() == c2.getId()) {
      c1.setMatched(true);
      c2.setMatched(true);
      iUserScore += iCorrectPair;
      mHomeView.updateScore(iUserScore);
      c1 = null;
      c2 = null;
      changeVisibilityCards();

      if (isGameWon()) mHomeView.onGameFinished(iUserScore);
    } else {
      iUserScore -= iInCorrectPair;

      mHomeView.updateScore(iUserScore);
      flipBackAllCards();
    }

    bAllowClick = true;
  }
Ejemplo n.º 5
0
  @Override
  public void flipBackAllCards() {
    if (mHomeView == null) return;

    for (int a = 0; a < cardsList.size(); a++) {
      if (!cardsList.get(a).isMatched()) {
        cardsList.get(a).setFlipped(false);
        mHomeView.flipBack(cardsView.get(a));
      } else {
        cardsList.get(a).setFlipped(true);
      }
    }
    c1 = null;
    c2 = null;
  }
Ejemplo n.º 6
0
 @Override
 public void changeVisibilityCards() {
   for (int a = 0; a < cardsList.size(); a++)
     mHomeView.changeVisibilityCard(cardsView.get(a), !cardsList.get(a).isMatched());
 }