# How to divide cards deck between 2 players (How to make a War card game)

Hey guys.
I’m making a War card game for android. War (card game) - Wikipedia

Basically, the rules are like this: the deck is divided evenly, with each player receiving 26 cards, dealt one at a time, face down. Anyone may deal first. Each player places their stack of cards face down, in front of them.
Each player turns up a card at the same time and the player with the higher card takes both cards and puts them, face down, on the bottom of his stack.

The twist is your playing against Death.

I’m stuck for now and I don’t know how to do this thing: I want at the beginning, the 52 cards deck to be randomly divided between the 2 players, I mean the player and Death. How can I accomplish this?

Here is a short video with the animations: Cards War game - YouTube

Thank you!

I haven’t used the Arrays in GDevelop yet, but here’s my understanding of what you could do:
Setup:
Create an array “Deck” of all the cards different in the deck.
Create two empty arrays to represent the play and death hands: “PlayerHand” & “DeathHand”

Shuffling:
Generate a random number “x” up to the current number of the children of “Deck”.
Add and new value to the array “PlayerHand” that is the value of “Deck[x]”
Remove the element by index “x” from the “Deck” array
Generate a new random number “x” up to the current number of the children of “Deck”.
Add and new value to the array “DeathHand” that is the value of “Deck[x]”
Remove the element by index “x” from the “Deck” array
REPEAT until there are no more children in the array “Deck”

1 Like

in this example you need the 52 cards in a Group i called “Cards”
the Card objects need to be named Card1, Card2, Card3, …

this is similar to how i handle it in my cardgame.

you can use a variable as offset and tween Y pos to the pos you want - the offset variable, to have them look stacked. Then you should set the Z order of the cards to Cards.Y()*-1

2 Likes