Card Game Framework
Card Game Framework
I'm going to be making a card game in Love2d, so I figure if I'm doing that, might as well make a framework others might find useful as well. Any ideas on features people might think are interesting? Fire away here.
Re: Card Game Framework
What a coincidence, I am currently making a card game as well! Mine is in the style of TCGs like Yu-Gi-Oh as opposed to casino games or Cards Against Humanity. I don't have much experience with programming (I'm doing this as my final project for the Intro to CS course, CS50x) so I'm doing most of the work by trial-and-error. So yeah I think it's a great idea to come up with a card game framework!
Off the top of my head, here are some of the features I encountered / had trouble with:
(Note: If by 'features' you meant features of the program and not the card game itself, continue reading. Else, I completely misunderstood your question so you can just ignore me haha.)
Card Database
There are I think one or two posts about card games in the forum, one of which was about loading card information via a SQL database. The replies went along the lines of "it's not that much data, you could just parse it", so that's what I'm currently doing for my card database, parsing a text file. You'll probably find a more elegant way to do it haha
Card Dragging
I am currently using Michael Ebens' (https://ebens.me/post/mouse-dragging-in-love2d) way of dragging cards. It works great save for one potential issue which is tied to the next question.
Mouse
I'm not sure what type of card game you were looking to make, but I assume it will involve a lot of clicking and/or dragging cards? Is there a way to keep main.lua from getting too crowded under love.mousepressed and love.mousereleased? I tried to clean it up a bit by making the dragging inherent to the card itself, but love.mouse.isDown isn't working as intended. I don't mean to ask you to solve this problem, of course, but if you are going to allow dragging cards at least you know one person who will need that feature haha.
Card Effects
We might not be thinking of the same card game type here, but a feature I am slowly approaching is card effects/interactions.
In a simple game like Uno, there are only a handful of possible keywords ("reverse", "skip", "wild card", etc.) which could be relatively easy to implement, but in a more complex game like Yu-Gi-Oh, there are so many potential card effects that require information about other cards or affect other elements of the game ("if you have card X in your [graveyard], [banish] it so [summon] Y", "if you have X amount of [life points] [more] than your opponent, do Y", etc.).
There are so many kinds of interactions that I imagine will result in a heck of a lot of nested if statements. For a card game framework, it would be super amazing to have a scalable implementation of 'card effects', such that it would work for games like Uno but could also handle complicated games if needed. It seems impossible just typing it ...
Sorry for the wall of text, I just got really excited that someone is thinking of making a framework for card games.
Off the top of my head, here are some of the features I encountered / had trouble with:
(Note: If by 'features' you meant features of the program and not the card game itself, continue reading. Else, I completely misunderstood your question so you can just ignore me haha.)
Card Database
There are I think one or two posts about card games in the forum, one of which was about loading card information via a SQL database. The replies went along the lines of "it's not that much data, you could just parse it", so that's what I'm currently doing for my card database, parsing a text file. You'll probably find a more elegant way to do it haha
Card Dragging
I am currently using Michael Ebens' (https://ebens.me/post/mouse-dragging-in-love2d) way of dragging cards. It works great save for one potential issue which is tied to the next question.
Mouse
I'm not sure what type of card game you were looking to make, but I assume it will involve a lot of clicking and/or dragging cards? Is there a way to keep main.lua from getting too crowded under love.mousepressed and love.mousereleased? I tried to clean it up a bit by making the dragging inherent to the card itself, but love.mouse.isDown isn't working as intended. I don't mean to ask you to solve this problem, of course, but if you are going to allow dragging cards at least you know one person who will need that feature haha.
Card Effects
We might not be thinking of the same card game type here, but a feature I am slowly approaching is card effects/interactions.
In a simple game like Uno, there are only a handful of possible keywords ("reverse", "skip", "wild card", etc.) which could be relatively easy to implement, but in a more complex game like Yu-Gi-Oh, there are so many potential card effects that require information about other cards or affect other elements of the game ("if you have card X in your [graveyard], [banish] it so [summon] Y", "if you have X amount of [life points] [more] than your opponent, do Y", etc.).
There are so many kinds of interactions that I imagine will result in a heck of a lot of nested if statements. For a card game framework, it would be super amazing to have a scalable implementation of 'card effects', such that it would work for games like Uno but could also handle complicated games if needed. It seems impossible just typing it ...
Sorry for the wall of text, I just got really excited that someone is thinking of making a framework for card games.
- NobodysSon
- Prole
- Posts: 33
- Joined: Tue Oct 30, 2012 10:37 pm
Re: Card Game Framework
I don't have any solutions but I am watching with curiosity to see what you come up with.
Re: Card Game Framework
AlyAsh, you are totally talking about the stuff I want to discuss in this thread. I'm talking about useful features in the framework (program skeleton), not the game itself. I've got an idea for a card game, and looking to make it virtually before I bother to design a functional table-top version.
In regards to your programming questions above, there are a lot of ways to break code out of the main LUA file. I'll be using common class (hump class) which allows you to load class code from other LUA files. I'm not going to delve deep into it, but there are many ways to avoid complicated nested if/then statements, that is outside the scope of this thread. (I'm no programming expert, but I've been doing it as a hobby for decades)
The UI stuff, with mouse, dragging, etc is for sure very important. Visually how the cards are portrayed with zoom (maybe hover) etc, already planned. I hadn't thought about the card database deal much. Using the common class above, implementing cards are classes (in code) would be pretty trivial. If you haven't looked into OO programming and classes, check it out sometime.
Multiplayer is a big deal to me, as I don't see my game working well with AI/Bot (Though time will tell). So I am exploring integrating the Discord API right now, that seems like a sensible way for the framework to find other players, etc.
I'll keep asking questions and posting updates here as I go.
In regards to your programming questions above, there are a lot of ways to break code out of the main LUA file. I'll be using common class (hump class) which allows you to load class code from other LUA files. I'm not going to delve deep into it, but there are many ways to avoid complicated nested if/then statements, that is outside the scope of this thread. (I'm no programming expert, but I've been doing it as a hobby for decades)
The UI stuff, with mouse, dragging, etc is for sure very important. Visually how the cards are portrayed with zoom (maybe hover) etc, already planned. I hadn't thought about the card database deal much. Using the common class above, implementing cards are classes (in code) would be pretty trivial. If you haven't looked into OO programming and classes, check it out sometime.
This is going to be a thing for sure. I think my initial plan will be to tackle it with classes of "rules" which are triggered by "conditions". Rules classes put into an array that is traversed for card plays makes sense to me at first blush.In a simple game like Uno, there are only a handful of possible keywords ("reverse", "skip", "wild card", etc.) which could be relatively easy to implement, but in a more complex game like Yu-Gi-Oh, there are so many potential card effects that require information about other cards or affect other elements of the game ("if you have card X in your [graveyard], [banish] it so [summon] Y", "if you have X amount of [life points] [more] than your opponent, do Y", etc.).
Multiplayer is a big deal to me, as I don't see my game working well with AI/Bot (Though time will tell). So I am exploring integrating the Discord API right now, that seems like a sensible way for the framework to find other players, etc.
I'll keep asking questions and posting updates here as I go.
Re: Card Game Framework
Hi Jason, I forgot to mention that I use a class library. I was hoping to be able to implement dragging within the class itself, but no luck. I put that on the back-burner for now while I just power through with implementing other features.
Game Phases
Draw Phase, Set Phase, etc. It results in a lot of if/then statements because certain actions can only be done during a certain phase.
Card Effects
Since my last message, for card effects I decided to ask my friend (he comes up with all the card info) to compile a master list of effect 'keywords' that exist in the game with a list of 'arguments' that the keywords affect. I wonder if this was what you meant by "rules" and "conditions".
For example, the keyword for a card whose effect is to "increase the strength of type X cards by amount Y" would be increase. In the cards database (text file), my friend would put under 'keyword': 'increase' and under 'arguments': 'X,strength,Y'. I will write the functionality for increase.
Whenever the card's effect is activated in-game, call the function run(keyword, arguments), which takes card.keyword and card.arguments and does an if/then matching for all the function-keywords to execute them manually.
For more complicated effects, the keyword is likely going to be something whose one argument is another keyword which would be called with run. For example, if a card only activates increase during a certain phase, instead of increase its keyword would be something like checkphase, which takes 'arguments' = 'phase,keyword,{arguments}...'.
It's going to be time-consuming since I'd need to know all possible card effects and manually list the arguments, but it's the solution I have so far.
Player 2
I completely agree. I figured programming an AI would be whole endeavor in itself and it doesn't seem better than player vs. player to test my game's code so why bother. I am so far from finishing the basic game though, so I probably won't be looking into the Discord API for a long while haha.
Best of luck!
Game Phases
Draw Phase, Set Phase, etc. It results in a lot of if/then statements because certain actions can only be done during a certain phase.
Card Effects
Since my last message, for card effects I decided to ask my friend (he comes up with all the card info) to compile a master list of effect 'keywords' that exist in the game with a list of 'arguments' that the keywords affect. I wonder if this was what you meant by "rules" and "conditions".
For example, the keyword for a card whose effect is to "increase the strength of type X cards by amount Y" would be increase. In the cards database (text file), my friend would put under 'keyword': 'increase' and under 'arguments': 'X,strength,Y'. I will write the functionality for increase.
Whenever the card's effect is activated in-game, call the function run(keyword, arguments), which takes card.keyword and card.arguments and does an if/then matching for all the function-keywords to execute them manually.
Code: Select all
function run(keyword, arguments)
if keyword == 'increase' then
increase(arguments[1], arguments[2], arguments[3])
elseif keyword == ... then
...
end
end
Code: Select all
function run(keyword,arguments)
if keyword == 'checkphase' then
checkphase(arguments[1], arguments[2], arguments[3], arguments[4], arguments[5])
elseif keyword == 'increase' then
...
elseif
...
end
end
function checkphase(phase, keyword, argument1, argument2, ...)
if gamePhase == phase then
run(keyword, argument1, argument2, ...)
end
end
Player 2
I completely agree. I figured programming an AI would be whole endeavor in itself and it doesn't seem better than player vs. player to test my game's code so why bother. I am so far from finishing the basic game though, so I probably won't be looking into the Discord API for a long while haha.
Best of luck!
Re: Card Game Framework
I don't want to break this thread down into a LUA programming class, but I can show you what I'm thinking about for handling the card rules, and maybe that will show you another style of handling the rules mess without a lot of "if/then" statements.
Functions are values in LUA, and Tables are indexed by strings. So, creating a rules table and assigning a function to an entry is easy peasy.
Also, args here will be a table containing all the arguments needed by the handler function. Passing tables is faster than sequences of arguments in a stack based language such as LUA.
Functions are values in LUA, and Tables are indexed by strings. So, creating a rules table and assigning a function to an entry is easy peasy.
Code: Select all
HandlerTable['increase'] = function(args)
-- put logic in here
end
function HandleKeyword(keyword,args)
local entry = HandlerTable[keyword]
if (type(entry) == "function") then entry(args) end
end
- zorg
- Party member
- Posts: 3468
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: Card Game Framework
Technically, tables can be indexed by anything except nil, not just strings... also, it's not an acronym, just lua.
Eventually you should profile whether creating tons of garbage with tables being created to avoid multiple arguments is really worth it.
Eventually you should profile whether creating tons of garbage with tables being created to avoid multiple arguments is really worth it.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Who is online
Users browsing this forum: No registered users and 2 guests