im implementing a not so simple board game, i have a way to do most stuff (start game handling,turn handling,combat system,movment etc).

im having a problem with spacial cards that players draw,the simple ones like "lose life" or "gain item" etc are simple change to one variable.

but i have rule changing ones ,something like "monster x you encounter have 2 more life, and if you pass a combat roll gain an item",the first part is just having monsters of said type have 2 more life(changing their stats for the duration of the card.

but changing the combat system to give item on success roll?

should i run an event list every combat move? i dont know how that will work at all. in real life board game you just do what the card says but in a computer vartion the game shold do it, and im not sure of the logics.

also there is no other resource to consult (ive searched google a lot).

please help me.

  • 1
    \$\begingroup\$ Is this question helpful for you? gamedev.stackexchange.com/questions/47077/… \$\endgroup\$ – Philipp Feb 23 '14 at 11:32
  • \$\begingroup\$ im not sure, from what i got they told him to use a "hook system" like wordpress where you can add plugins that affect stuff (like "head",or "on register") to add new functionality. about flux the card game, its not that hard to create a variable like "draw_cards = 10 or discard= 10 and play_cards=2" you can create respective methods that do that stuff with for loops... i have a bad experience with board game programing. so i don't want to waste time on something that might break. so combat func will look: do_combat() { combat_hooks(); combat code... } i dont know if it will work. \$\endgroup\$ – rolen Feb 23 '14 at 11:49
  • \$\begingroup\$ easy to implement: - turn by turn phase game play - movement and combat - monster movement - ancient one combat - skill checks - gate opening and closing hard to implement - some encounter card description is hard to implement - some mythos card is hard to implement \$\endgroup\$ – rolen Feb 23 '14 at 11:52
  • \$\begingroup\$ i can always do bruteforce , 100 if arguments for all the different cards...that would be dirty and unmintanble fun. \$\endgroup\$ – rolen Feb 23 '14 at 12:03

This is first of all about code organization, so there is many different ways of doing it, and what works depend both on the job and the skills and preferences of the programmer.

Try to imagine your card effects in a 2D grid, on one axis your cards are listed, on the other all the possible places where they may take effect are listed, the "hooks". Any number of the cells may contain a function, but most of them are probably going to be empty.

What you want is to slice up this grid so that all the effects of a single card are collected in one place, that is easy, you can just make an object containing the functions for each card:

var allcards={

Now the tricky part is calling them at the right time, for this purpose I suggest that you keep a list of all active cards, and that you make a function iterating over that list. Something like:

function effectiterator(hook,args){
    for(var card in listofactive){
        if(listofactive[card] && listofactive[card][hook]){

Where you would have to maintain the listofactive like so:

listofactive[cardid]=allcards[cardid] //Add to list
listofactive[cardid]=false //Remove from list

If you initialize the listofactive with all the possible keys you have in a specific order, that order will be the order in which the cards take effect, so you avoid unpredictable race conditions.

The args in this case should be an object referencing all the objects that are relevant to the event, so for instance in the onplay event you would include the object of the player playing the card so that the function may read and modify the attributes.

| improve this answer | |
  • \$\begingroup\$ thank you your hook system seems realy nice ill try it. but for now i decided to go with brute force,hundreds of if statments, i want results and dont care how. \$\endgroup\$ – rolen Feb 23 '14 at 15:51

Not the answer you're looking for? Browse other questions tagged or ask your own question.