#What is the best approach to create a UNO card ?

1 messages · Page 1 of 1 (latest)

bronze blade
#

Here is my actual method:

Card is a TextureRect with two properties:

  • type: NUMBERED, SKIP, REVERSE, DRAW, WILD, WILDDRAW
  • color: RED, YELLOW, GREEN, BLUE

To check if a card can be played, the game will verify if the color or the type matches the previous card, except for WILD and WILDDRAW cards
Also, when the type is NUMBERED, a third property is added to represent the number of the card

Right now, I'm struggling with the additional number property. I don't know how to update the symbol when the property is change.

I linked my code to this post

half quarry
#

How about something like this?

enum CardType {
  NUMBERED  = 0,
  SKIP      = 1,
  REVERSE   = 2,
  DRAW      = 3,
  WILD      = 4,
  WILDDRAW  = 5
}

signal changed(type: CardType, number: int)

# behind the scenes values
var _type: CardType = NUMBERED
var _number: int = 0

var type:
  get:
    return _type
  set(value):
    if value == _type:
      return
    _type = value
    changed.emit(_type, _number)

var number:
  get:
    return _number
  set(value):
    if value == _number:
      return
    _number = value
    changed.emit(_type, _number)

These setters/getters copy the values from/to the private properties and emit a signal on actual changes (which you can listen for).

bronze blade
pallid drum
#

Because Sprite2D is for Node2D and TextureRect is for Control

bronze blade
#

Yes, I know, it’s going to be integrated into a control node