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

Hi!

So, I’m starting to learn this engine, and I’m liking it so far. My problem is that it is the first time I use something like this, besides maybe game maker years ago. I’ve only used frameworks in the past, like libgdx or as3, in which you had to do quite a lot of work yourself to get stuff done.

The thing that I’m struggling the most right now is how to structure the game and how to use in a smart way the messaging system.

To warm up and to learn all the different stuff I decided to try and program a simple card game (the Klondike solitaire), but I feel like the way I’m doing it is not efficient and it is not using the engine how it should be used. Basically what I’m doing is to implement the different mechanics (reacting to clicks, dragging cards and releasing them on other cards) using only a GUI with boxes and putting all the code in a gui script that creates and moves around new boxes, implements the rules of the game and reacts to the user input (that is easier using GUI nodes thanks to gui.pick_node),

Having all the code in one script doesn’t seem really good though… How would you do it instead?

2 Likes

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