PDA

View Full Version : List of cards (Game programming)



dieter
1st February 2012, 19:22
http://www.quality-games.com/media/T/TopTenSolitaire-sc.jpg

I'm writing a "card engine" which means I have to reuse code for like every card game. The most difficult part for me
will be designing a decent user interface with Qt. I can do the basic stuff in Qt involving the normal widgets and
deriving a clicklabel from a label etc... But my question...

I want to design a list of cards, a hand or a game like the link above... The problem is... Qt has not much widgets I can pick and just
reuse ...

What would be the best option I can take to work with the qt designer, coding my game in c++... (list view will look ugly or not?)

How do I create the "widgets" myself or is there any other alternative... available resources or something

If someone could help me out,
I would really appreciate
:o

wysota
1st February 2012, 19:33
Use QGraphicsView, QGraphicsScene and related classes. Qt is something more than just widgets.

dieter
1st February 2012, 20:19
I have looked up them a bit... They are great for adding some rectangulars and other graphics...
But is it also a good way to have lists of Cards (clickable images sorted in lists) I mean I need
access to every item...
Anyway thx for the usefull post

wysota
1st February 2012, 23:01
They are great for adding some rectangulars and other graphics...
But is it also a good way to have lists of Cards (clickable images sorted in lists) I mean I need
access to every item...

To me a card is a "rectangular thing with other graphics" so graphics view seems perfect for the task.

The way you organize your objects doesn't depend on what classes represent those objects.

dieter
2nd February 2012, 16:59
So I need to drag from a QListWidget or something similar on to a QGraphicsScene. When I drop, I will create an new QGraphicsItem subclass at the drop location. How can I do this? setAcceptDrop is not even available for a QGraphicsScene.

wysota
2nd February 2012, 19:46
What do you need QListWidget for? Why do you need to drag anything?

d_stranz
4th February 2012, 18:34
@dieter: What are you asking for - a container object to hold your internal description of a "card" object, or a way to display the images contained in those card objects on the screen, or a way for your game users to interact with those images? As Wysota said, the internal representation of a card and a collection of cards has almost nothing to do with displaying and interacting with card images on the screen.

If you are looking for a completely generic representation of a card object and a "card deck" object, along with rules for the "value" of a card and how and when that card can be played, then you need to design that card game engine logic completely independently of your GUI. Likewise, your GUI should have minimum knowledge of the game and its rules, but knows how to ask the game engine about how to construct the display and whether an attempt to move a card from one place to another is allowed by the rules, etc.

If you don't keep the card game engine separate from the card GUI, you will likely end up with a mess of spaghetti code that might be able to play one kind of game, poorly, and no way to easily change it to accommodate a different game or different rules.

Ronayn
16th February 2012, 13:07
I am very interested in this topic.

I'd like to design a card game, but am unsure on how to represent the cards on the gui. I've designed an app where a card was represented by a widget. This way, I can use its built in drag/drop capabilities and also take advantage of the fact that a card could contain several clickable components (ie, other widgets).

However, wysota suggests using graphics views. Is that what is commonly used for representing cards in card games like Solatair, Texas Holdem, or online CCG's?

wysota
16th February 2012, 13:28
This way, I can use its built in drag/drop capabilities and also take advantage of the fact that a card could contain several clickable components (ie, other widgets).
You can do all that (and much more) with graphics view.

Think how you would e.g. rotate a card using widgets.