card game programming framework
I am not a programmer. I can write a shell script and a little perl, but that's about it. I thought I would try a project.
I want to write a graphical tutorial program for some card games. Rather than reinvent the wheel, I thought some framework (or library, or whatever they're called) might already exist and I could start there. Does anything like that exist? I just mean something that contains the card images and has a basic card game structure that can be built on. Or is it better to just try to do it from scratch myself. If so what language (not to cryptic) would you recommend? Thanks |
|
You could use your shell scripting skills to get started. Use ANSI escape sequences for colors, and Unicode 6 glyphs for the cards. Run this Bash script to see if your terminal is UTF-8, and your preferred terminal font has the glyphs:
Code:
#!/bin/bash Put the SVG images in $HOME/.mycardgame/decks/default/, so that you can later let the user choose from different deck graphics. This will also help you put the rest of your game files in the correct place ($HOME/.mycardgame/ in every OS except Windows, but Windows sucks pebbles anyways). To be honest, I wrote the above shell script snippet because I wondered what on earth is a "basic card game structure". As far as I know, there is no such thing. All card games have cards, but that's about it. Some card games I know have one stack, some more, some none at all (because all cards are dealt to the players at the start of the game). Could you be more specific about what kind of card games you are talking about? Poker? |
Thank you both for the reply. By "basic card game structure" I meant something that displays a background of some sort, has card pictures, knows how to shuffle, and perhaps has some predefined method of inputting rules of the game.
I guess I just assumed that most programmers reuse existing code all the time. Programs seem more and more complicated. So I was expecting some sort of modular framework, so people don't have to rewrite the same basic code. My final plan is to write a gin rummy tutorial and practice program. But I might start with something simpler like "go fish", or "war". It depends on how far I want to go. Putting up some example hands with annotations is one thing. But writing a program that could actually play rummy with any skill might be asking to much at this early stage. I might try the shell script idea. It will give me a chance to work out some of the ideas. But I was a little curious about how programming in a graphical environment works. And again I just assumed that much of that is already modular. Unlike the early days, that I remember, when everything in X had to be configured by hand. |
To be honest, I think a library for something like this would be overkill.
First, you can use the playing cards from the Open Clip Art Library. They are licensed under CC0-1.0, which means they are completely free to use. For this example, you'll need four cards, as h_10.svg, h_j.svg, h_q.svg, and h_k.svg, in the same directory as the following Python file. You'll need Python and PyQt4 for this: Code:
#!/usr/bin/python Now, because I haven't done any testing, I have no idea whether the above is the best approach. You need to test to see! The main issue is how the cards are handled. (Should the card objects be manipulated directly as I do above, or should the "hands" be just strings describing the hands? Maybe lists of short strings? Lists of constants? Dicts? Or should the face shown in the window be completely detached from the concept of a card, and be something the display routines should handle? There are lots of options; you're definitely not bound to my approach above.) Since each card can exist only once on-screen, I think creating a QSvgWidget for each one is a good idea. You'd also need the maximum number of on-screen card backs as QSvgWidgets, too. The logical hand is separate from the visual hand. The visual hand is just the cards that are shown in the window. This approach makes it extremely easy to handle clicking and dragging cards; just add the relevant method or methods to the PlayingCard class. PyQt4 lets you override existing methods to provide new functionality -- like I've overridden the constructors (__init__) and the resizeEvent(). Also, you don't need to calculate coordinates like I did above if you don't want to; you can use the Qt4 containers to handle the layout for you. (If you want the cards to overlap, you might wish to do it like I do, however; the containers don't expect you to want to have items in them overlap.) The above is less than a hundred lines of Python. Hopefully, you can see that using a framework for something as simple as this would not reduce the amount of code you'd need to write that much, but it would certainly limit your approach. Do not tie yourself to arbitrary limitations by constraining yourself to existing frameworks! Liberate your creativity! |
All times are GMT -5. The time now is 10:43 AM. |