outfrost / deckswipe

Single player card game skeleton based on Reigns and Lapse
MIT License
75 stars 29 forks source link

How to use card prerequisites? #35

Closed yeter1 closed 4 years ago

yeter1 commented 4 years ago

Hello sir, First of all ty for this awesome opportunity to learn. Can you give an example to use card Prerequisite?. For example, a card can only be drawn when Another card responded with left action before.

outfrost commented 4 years ago

To use card prerequisites, you would populate the prerequisites list in a Card instance. Each entry is an ICardPrerequisite, and has a Status property, which describes, as a bit field, what has to have happened to some other card, in order for the card holding the prerequisite to be shown.

In your example case:

Suppose we have some Card a whose id in storage is 6, and some Card b whose id is 9. We only want a to be shown to the player if the player has swiped b to the left before.

a.prerequisites will therefore contain at least one item, perhaps constructed like so:

    CardPrerequisite p = new CardPrerequisite();
    p.id = 9;
    p.status = CardStatus.LeftActionTaken;

(I didn't create a special constructor for CardPrerequisite and SpecialCardPrerequisite because they were usually imported from Google Sheets)

Prerequisites are checked during loading of player's progress. Then, whenever a card is shown or swiped, each of its dependent cards is checked, and added to the pool of drawable cards if its prerequisites are now satisfied.

yeter1 commented 4 years ago

Thank you again, your answer is exactly what i was trying to understand... Also is there a way to show a card only once?

outfrost commented 4 years ago

No, there isn't. Once a card is added to drawable ones, it's never removed. That is something you would have to implement yourself.

If you do, and would like to have it integrated here, I am accepting PRs :)