V
V
V Sh.2016-07-11 09:24:30
C++ / C#
V Sh., 2016-07-11 09:24:30

How to correctly calculate bonuses in a card game?

Good day, Toaster!
To improve his knowledge, he started developing a collectible card game. As planned, it should be something in between Heartstone and Gwint. Two players, each with their own deck and hand (cards in quick access, so to speak), there is a playing field divided into four lines for each player. Each card has its own characteristics and special bonuses. Everything, in general, is standard. Having more or less marked the balance of the game, I started development and ran into a number of problems, where the calculation of bonuses for each card stands apart. For example, if two cards with the same bonus lie side by side, then each card has a certain characteristic increased by several points.
Now I have a Card class with the characteristics of a card, a Field class (player's playing field). The problem is that I don't know how best to calculate bonuses. So far, the idea is this: add a list of bonuses that apply to this card to the Card class and recalculate this list for all cards on any action.
But something tells me that it can be done easier. Maybe someone has developed something similar and can help with good advice? Well, I will always be happy with high-quality literature on computer game programming.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
T
terrier, 2016-07-11
@terrier

Looks like a PubSub challenge. Let's say we have a card "King of Goblins" 5/5 taunt, class - goblins.
When we put it on the table, it (in the sense of the corresponding object) unsubscribes from the channel "for those who lie in the hand" and subscribes to the channels "We lie on the table", "Class - goblins", "Cards with taunt" and te de.
And sends a message to the appropriate channels - "I'm a 5/5 goblin came to the table at such and such a position."
This way we can buff goblins, destroy enemy taunts or buff table neighbors without going through all the cards. Well, adding new effects also happens with less pain.

A
Alexey Pavlov, 2016-07-11
@lexxpavlov

I think it's better to handle it on the other side - in the playing field, have a list of cards and a list of applied bonuses. When using a card, change the characteristics of both the card itself and the playing field. And it is possible that you will have to recalculate each card (depending on the applied card). By taking a card and processing it, the game state will immediately become changed, and there will be no need to recheck the state of each card at each check.

D
Dmitry Kovalsky, 2016-07-11
@dmitryKovalskiy

If you decide a little on the forehead. Suppose you do not have a Card class, but a hierarchy of ICard classes for each class or type of card (there is already a lot of imagination for implementation). And this whole zoo of classes implements the IBonus interface with the StartBonusEffect method, which receives a reference to the environment as input (board class from which you can draw your cards or opponent, the lives of each player, etc.). And in the implementation of this method, you can already swagger as you want. Win, lose, kill all opponents, make your own imbs, etc. etc.
Well, it's on the knee if you sketch.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question