Last active
June 15, 2022 16:47
-
-
Save andrewljohnson/28750cf1374ceca9f51772cf6bd2c873 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
// Current Cards | |
// Mountain | |
// Future Cards | |
// Forest | |
// Lightning Bolt, Giant Growth, Earthquake | |
// Kird Ape, Granite Gargoyle, Llanowar Elf | |
// effects get mapped to EffectDef functions when cards are instantiated for a deck | |
struct Effect { | |
string name; // flying, mana_red, mana_green, damage, change_power_toughness | |
int amount; | |
string amountType; // any_amount | |
string targetType; // any_player_or_creature, all_non_flyers, self | |
string trigger; // on_choose_blockers (for flying), on_cast, on_activate, | |
// on_owner_lands_change (for kird ape) | |
}; | |
// a struct, based on player actions, that gets passed into an EffectDef function | |
struct TargetInfo { | |
int amount; | |
string targetType; // creature, player, all_non_flyers | |
int targetId; // the id of the creature or player | |
}; | |
// map all of a Card's Effects into functions of this signature when cards are instantiated for a deck | |
typedef void (*EffectDef) (int effectOwner, Effect e, TargetInfo targetInfo); | |
struct Card { | |
int id; // assign when card is instantiated for a deck | |
string name; // human readadble name | |
string cardType; // land, instant, sorcery, creature | |
// reallocate these as needed because C++ doesn't have flexiable arrays | |
// https://stackoverflow.com/a/4413035 | |
Effect effects[0]; | |
// when a card is instantiated, turn each of effects into a function | |
EffectDef activatedEffectDefs[0]; | |
}; | |
void doManaEffect(int effectOwner, Effect e, TargetInfo t) { | |
// add mana to a player's pool | |
// do Effect e for Card c based on TargetInfo t | |
} | |
int main() { | |
int lastCardId = 0; | |
// make a card with one effect | |
struct Card* m = (struct Card*) malloc( sizeof(struct Card) + sizeof(Effect) + sizeof(EffectDef)); | |
m->id = lastCardId; | |
m->name = "Mountain"; | |
m->cardType = "land"; | |
Effect mManaEffect; | |
mManaEffect.name = "mana_red"; | |
mManaEffect.amount = 1; | |
mManaEffect.targetType = "self"; | |
mManaEffect.trigger = "on_activate"; | |
m->effects[0] = mManaEffect; | |
m->activatedEffectDefs[0] = doManaEffect; | |
cout << "Card " << m->name << " is a " << m->cardType; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment