Update 2: Creating Cards
It's down to the wire.
You've fought hard to get this far. The wolhound that's been terrorizing the town snarls at you, blood and spit flying from its teeth. You're both wounded, that much is clear. You just need one final blow...
You draw your next card.
Is it an attack card? A heal? A buff, poison, or spell? An attack will need to deal damage, buffs and poisons need to be applied to their targets. So how does one card differentiate itself from another? When you use that heal card to save yourself from the savage wolhound, how do you know it won't actually deal damage?
Creating Cards
A deck is composed of cards, and cards can be many different things in a card based RPG like Dark Miasma. Between damaging attacks, buffs, heals, card draw, and other properties, cards need to have a variety of functions and behaviours while still being, well, cards. Luckily, there are a number of ways to solve this issue.
The Trivial Answer - Dangerous in the long run
Just put a bunch of booleans on your cards that describe what it does! Attack = true would say that your card is an attack card and should deal damage. While this option may be the most straightforward, in the long run it leads to code that can be difficult to maintain and very prone to bugs. So what alternatives are there?
Polymorphism - We're close!
Polymorphism is a computer science term for saying that a specific type of object can actually be many different types of objects. For example, a cat is an animal, but so are dogs, cows, and turtles.
This is exactly the way we want to describe our cards! By using polymorphism we can create an Attack card, Heal card, Draw card, Buff card, etc, and they'll all still be "cards". But this is a card game. These types of cards are well and good, but we want something more complex. An attack card that also draws three cards. A buff card that also heals you. If we just extend our "Card" into other types, we'll need to create a new class of cards for every variation and combination of behaviours that we want. That's not ideal.
But what if we could take the behaviour of an attack card, and combine it with the behaviour of a draw card?
Components - Our Final Answer
Instead of saying that "An Attack card is a type of Card," what if we said that "A Card has Components" and "An Attack is a type of Component"? This would mean there would only be one type of Card, but each Card would have Components that describe its behaviour. Since a Component could be an Attack, Card Draw, Buff, Heal, Poison, or any other behaviour, we can mix and match our Components together to create many different kinds of cards!
An attack that draws a card? Just add an Attack component and a Card Draw component.
A buff that heals? A Buff and Heal component.
With a flexible system like this, we can create all kinds of cards with unique and fun interactions. And if we want something new, adding a new type of Component is easy! Since a card doesn't need to know what kinds of Components exist, we can just... make a new Component and add it. Easy. The Component pattern makes the behaviour of cards easy to understand, easy to add to, easy to organize, and easy to fix if something goes wrong.
Closing
Hey, thanks for reading this update blog! I apologize if this or the last blog post were too technical for some of you. In the future, I think I'll find some way of indicating that a post is technical or create subsections that talk about technical specifics. If you have any questions, feel free to post in the comments, and if you want to keep up with our development process, we have a subscribe button that should email you whenever we release a new post!
That's all for today! Bye for now.
Comments
Post a Comment