uno icon indicating copy to clipboard operation
uno copied to clipboard

How to create a new action card?

Open fuyangli opened this issue 2 years ago • 0 comments

I'm experimenting with your code to improve the game. I want to add a action card that allows you to steal a random card from a random player on the table and a card to clear all the table stack. I've add it to the BotsServer to test it first, but the code I've added does not reflect to the visuals in the game:

`if (card) { // if (card.action === "draw two") this.sumDrawing += 2; // if (card.action === "draw four") this.sumDrawing += 4;

  if (card.action == "clean table stack") {
    this.tableStk = [];
  }
  else {
    this.tableStk.unshift(card);
  }

  if (card.action == "steal") {

    const lastPlayerIndex = wrapMod(
      this.curPlayer - 1 * this.direction,
      this.players.length
    );

    const lastPlayer = this.players[lastPlayerIndex];

    if (lastPlayer && lastPlayer.cards.length > 0) {
      const randomCardIndex = Math.floor(
        Math.random() * lastPlayer.cards.length
      );

      const stolenCard = lastPlayer.cards.splice(randomCardIndex, 1)[0];
      this.players[this.curPlayer].cards.push(stolenCard);
    }
  }

`

In the code, the card is stolen and it's added to my hand, but on the visuals it remains on the stack of the original player and it no adds to my stack of cards.

I'm assuming it's something to do with the render of the elements on the screen, but I'm not founding it. Can you help me?

Thanks in advance!

fuyangli avatar Aug 25 '23 23:08 fuyangli