There are some open-source (relatively) generic card game engines available which you could probably adapt, see for example:
https://github.com/WagicProject/wagic
http://gccg.sourceforge.net/
Only "shared source", but pretty cool is also this one:
http://www.wolfire.com/desperate-gods
(and you might get permission for a commercial license if you ask nicely).