t_rob76
t_rob76

Reputation: 21

how to create a dynamic variable in android

I am creating a card game (blackJack) in android. the first two cards are easy card1 and card2, however i want to press a Hit me button and deal a new card and assign it to card3, card4 etc is there any way to do this without essentially creating the maximum number of variables you would need and using if then statements to check if they have been assigned a value or not?

Upvotes: 1

Views: 883

Answers (1)

Kazekage Gaara
Kazekage Gaara

Reputation: 15052

Use a List to keep track of your dealt cards instead of having individual variables.

private List<Card> dealtCard = new LinkedList<Card>();

you can then add and remove your cards easily,and dynamically.

Upvotes: 6

Related Questions