Experts of Defold, how would you structure a card game?

Interesting question! Without having given card games any thought in Defold before this I’ll try to answer as best I can.

I would probably use game objects with collision components to detect touch and dropping cards in different piles or locations on the game area. I’d have a main script that acquires input and detects collisions with the touch/mouse position and the cards. The main script would know of the rules of the game and decide if the player can pick up a card from a certain pile or discard/drop it at some other position. The cards themselves would probably also have a script and some kind of knowledge of where they belong (in the hand of the player, discard pile, stack of cards etc). The card script would be able to react to messages to move from one location to another and to flip to show front/back of card.

I’ll try to put together a small example to show some of my thinking.

6 Likes