Hello, I need some logic on how to create the mechanics of this.
My game is not a traditional 52 card deck, however, if you want to use it as an example it is fine.
Let’s say I have 30 cards and I start with a shuffle and instantiate all 30 cards onto the game, but only show the first 5 cards as the “hand”
I want to create a hand of 5 cards like below:
[1][2][3][4][5]
then when the player discards [1][3][4]
I want [2] and [5] to slide to where [1] and [2] were before
My theory is to make it so
[1][2][3][4][5] / [6][7][8][9][10] (off screen)
[2][5][6][7][8] / [9][10][11][12][13]
Would this be a good idea? How would you implement something like this to update the hand? List of gameobjects?
You might be able to use the List datatype and use the remove method to remove card 1,3 and 4. At that point when you iterate through the list it’ll only contain the remaining cards shifted over. I would personally consider the deck a separate entity and allow for a random card draw so it cannot be predicted and exploited.
Is iterate the way to update your hand / the cards in the list? So would I use a list for the hand, and a list for the deck?
I’ve been messing around with lists and arrays, and I’m pretty confused, although learning more about them both.
I’ve been reading about how costly destroying gameobjects are so I wanted to instantiate all of them into the scene somewhere, but not be seen or accessed until it’s in your hand. I think this is a better way than to instantiate cards each turn from the deck to refill the hand, would you agree?
Is it costly but not terribly costly if you’re only instantiating 1 card a turn or something. You can instantiate them all if you’d like and just disable them until you need them. It’s one way to go about doing it.
However if you’re drawing linearly through the deck in a predefined fashion it’ll be available to someone in memory if they’d like to cheat. Likewise if you handle the opponent the same way they could potential read memory to see what they’re going to draw next. As long as you randomize the draw it should be fine. There are many ways to handle the problem you’re bring up. Whichever seems most effective and easiest for you to code is what I would recommend.