an app that turns cards to reverse nervous breakdown

Asked 2 years ago, Updated 2 years ago, 66 views

http://pastebin.com/KTCkMu1p
A total of 4 cards including cards [img_0] turned upside down and images [img_s1-s3] with 3 different designs. Display 6 cards turned upside down on the screen and clear after 3 consecutive different designs
Game over
if you put out the same design by the third time. I would like to create an app that says that it is currently clogged up t

  • How do you treat a tapped card as a first tapped card variable?
    card1=Declare the first card;
  • if (second tapped card!=first tapped card)
  • if (third!=second||first)

How should I write about nesting if?
Please teach me.

android

2022-09-30 20:51

2 Answers

I don't know Java, so this is a general coding method.

You can make a decision by combining many if statements, but I think it's better to prepare a function like this that abstracts the judgment logic.

 boolean Overlapping cards (list of cards previously flipped, new cards) {
    for {
        if (card == new flipped card) return true;
    }
    return false;
}

Also, every time you flip a new card,
1. Call the Overlapping Card Function
2. Add a flipped card to the
List of cards you have flipped so far
You should repeat this process.
No matter how many pages you flip, you can just call this function.


2022-09-30 20:51

You may be able to use the contents().
No matter how many cards you have or how many times you flip, you can handle them.

ArrayList<Cards>cards=newArrayList<>();

// The card was flipped over.
if(cards.contains)) {
    // the same design (have been turned over in the past)
} else{
    // Different designs (for the first time
    cards.add; // keep added
}


2022-09-30 20:51

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.