v 4.4.1
Hello everyone. I started to learn GDScript recently as a hobby and decided to make a Solitaire game as my first project, just to get used to Godot’s mechanics. I just recently made the cards draggable by mouse click, now what I’m struggling with is to implement the Solitaire’s mechanic of black cards going on top of red cards and vice versa, and same color cards not going on top of each other.
I thought about creating a variable called card_color, but I’m not sure how to proceed from here. Any help will be appreciated!!
Each card probably wants to keep a record of its face value (A23…JQK), color and suit. You can potentially pack those all into a single value as bits, but you can also keep them split out separately.
enum CardColors { none, red, black }
enum Suit { none, hearts, diamonds, spades, clubs }
You probably want the none
values available for things like open spaces that can take any card. Face value you probably want as int
so you can do simple comparisons. So, for instance, if you were dropping a card on one of the alternating stacks:
if card.color != slot.color:
if slot.faceval == 0 || (slot.faceval == card.faceval + 1):
# card can be placed
1 Like
Enums are definitely a good idea, as @hexgrid suggested.
From experience I can give you one tip - separate your data model and visualization, you’ll thank yourself later. No state should be stored in the cards themselves. Have a class that managest the state and ask it for everything.
By that I mean have methods for everythin, like:
- can the player grab this card in this stack?
- can the player place this card on this stack?
- Is stack complete?
- Give me next card from the deck
- can you complete this card? (Move to the colored stacks)
- complete this card
Etc. Model everything and drive the visualization from it
Good luck
1 Like