Solved Give me a head start please!
-
@peteritv Let me alloborate further: My object "Card" may have many representations... On screen it will be a pixmap (Club Ace will be represented by CA.png), but for a document it will be represented by the HTML value "♣A" or maybe even "CA"
Now I not really that newby that doesn't know the difference, I just don't know how things like that work in Qt.
And Preferrably is such a way that QML knows about it too. -
@peteritv said in Give me a head start please!:
@peteritv Let me alloborate further: My object "Card" may have many representations... On screen it will be a pixmap (Club Ace will be represented by CA.png), but for a document it will be represented by the HTML value "♣A" or maybe even "CA"
Now I not really that newby that doesn't know the difference, I just don't know how things like that work in Qt.
And Preferrably is such a way that QML knows about it too.So suppose I have a Class "Card" with attributes "int Suit" and "int Rank".
Simple class right?How do I expose views that show the onScreen , onPDF, etc variants?
-
@peteritv said in Give me a head start please!:
@peteritv said in Give me a head start please!:
@peteritv Let me alloborate further: My object "Card" may have many representations... On screen it will be a pixmap (Club Ace will be represented by CA.png), but for a document it will be represented by the HTML value "♣A" or maybe even "CA"
Now I not really that newby that doesn't know the difference, I just don't know how things like that work in Qt.
And Preferrably is such a way that QML knows about it too.So suppose I have a Class "Card" with attributes "int Suit" and "int Rank".
Simple class right?How do I expose views that show the onScreen , onPDF, etc variants?
So I have some kind of list of "Cards"
Preferrably some kind of sorting on it...And a player plays a card...
-
@peteritv said in Give me a head start please!:
@peteritv said in Give me a head start please!:
@peteritv said in Give me a head start please!:
@peteritv Let me alloborate further: My object "Card" may have many representations... On screen it will be a pixmap (Club Ace will be represented by CA.png), but for a document it will be represented by the HTML value "♣A" or maybe even "CA"
Now I not really that newby that doesn't know the difference, I just don't know how things like that work in Qt.
And Preferrably is such a way that QML knows about it too.So suppose I have a Class "Card" with attributes "int Suit" and "int Rank".
Simple class right?How do I expose views that show the onScreen , onPDF, etc variants?
So I have some kind of list of "Cards"
Preferrably some kind of sorting on it...And a player plays a card...
For the game of "Bridge"
Let's say we have 4 players: "North", "East", "South" and "West"How do I define that so that QML knows about it?
-
@peteritv said in Give me a head start please!:
@peteritv said in Give me a head start please!:
@peteritv said in Give me a head start please!:
@peteritv said in Give me a head start please!:
@peteritv Let me alloborate further: My object "Card" may have many representations... On screen it will be a pixmap (Club Ace will be represented by CA.png), but for a document it will be represented by the HTML value "♣A" or maybe even "CA"
Now I not really that newby that doesn't know the difference, I just don't know how things like that work in Qt.
And Preferrably is such a way that QML knows about it too.So suppose I have a Class "Card" with attributes "int Suit" and "int Rank".
Simple class right?How do I expose views that show the onScreen , onPDF, etc variants?
So I have some kind of list of "Cards"
Preferrably some kind of sorting on it...And a player plays a card...
For the game of "Bridge"
Let's say we have 4 players: "North", "East", "South" and "West"How do I define that so that QML knows about it?
But to start with:
How do I know what "Game" to start with?A "CardGame" may be a local thing, may be referenced by a Single person or an onLine thing....
Let's focus on "CardGame" being a local thing.
And let's say that "Bridge" is our focus of cardgames.
"Bridge" has rules:
For instance:
Ace is highest
2 is lowest
Trump is highestI think that summons up the ruler of a "Bridge" trick,
right?So: If not trumped, Ace is highest
But if Trumped: -
Maybe v-play could give you some help, it provide a decent card game example.
-
@tham
V_play seems nice, but does it support card games?And it is NOT free?
-
@peteritv said in Give me a head start please!:
Please bear with me!
I am super newby to Qt, QML and C++ (and OO in general)I want to develop a general card game suit of classes, for instance for the (derived) games of bridge, "Belote" or poker.
Base class (Card) will be a card, with attributes suit (Clubs - Spades) and rank (2 - Ace, I don't think about jokers right now, but suggestions are welcome!).
For some games, ranks may be different, for instance, the Ace may rank as lowest (as in Ace-2-3), highest (as in Q-K-Ace), or even both.
How do I deal with that, keeping things as general as possible (Ace can have only 1 id, but many different meanings)?Trump J(ack) may be the absolute highest card, followed by trump 9, etc... (see https://en.wikipedia.org/wiki/Belote)
Many card games, all different rules...I want to make a class CardDeck that defines the range of Card to be used, so for Bridge it will be 52 cards, suits Club to Spade, range 2 to Ace(highest)
For "Belote" it will be suits Club to Spade, range 7 to Ace(highest),
Other games may have suits Club to Spades with range Ace(lowest) to Ace(highest)...The thing is:
- Cards can have different views (for instance: QString as in "C4", HTML as in "<♣4>", or an image...)
A card may be shown as:
- Text literal ("C4")
- HTML (♣4)
- an image
You get my drift...
Now how do I start to set this up, with remark that all should be accesible by both C++ (which will probably handle the data and model) and QML (which will probaly handle views)?
I have read all the stories, but get lost ...
-
@peteritv
A simple thing as a "Card" (with just a suit and rank) does not know anything about how it is supposed to be viewed, right?The "Card" itself is just data.
This data needs to go into some model, that processes the data.
Since the "Card" itself will never change, I am thinking about a "QItemStandardModel"
Just to hold the "Card" instances and being able to sort/add/delete a "Card"...So, the model contains "Cards" (with multiple instances of "Card")
And there will be multiple views to show that.
Basiccaly a "Deck of cards" will be a "TableView" I guess, since there is 2 dimensional data namely suit and rank.When a trick is played (game of Bridge for example) there will be 4 "Card" instances that will leave the "Complete" model and enter some new model of "Played".
Right?When you think about "Card"s
It is hard to NOT think about views, but fact is that sometimes you want just "♣4" and sometimes you want the full PNG image...The goal of this topic is (and was from the beginning) how to setup things in Qt (and/or QML) so that both C++ and QML know that a "Card" has been played, and can adjust the new actions to take.
-
@peteritv said in Give me a head start please!:
@peteritv
A simple thing as a "Card" (with just a suit and rank) does not know anything about how it is supposed to be viewed, right?The "Card" itself is just data.
This data needs to go into some model, that processes the data.
Since the "Card" itself will never change, I am thinking about a "QItemStandardModel"
Just to hold the "Card" instances and being able to sort/add/delete a "Card"...So, the model contains "Cards" (with multiple instances of "Card")
And there will be multiple views to show that.
Basiccaly a "Deck of cards" will be a "TableView" I guess, since there is 2 dimensional data namely suit and rank.When a trick is played (game of Bridge for example) there will be 4 "Card" instances that will leave the "Complete" model and enter some new model of "Played".
Right?When you think about "Card"s
It is hard to NOT think about views, but fact is that sometimes you want just "♣4" and sometimes you want the full PNG image...The goal of this topic is (and was from the beginning) how to setup things in Qt (and/or QML) so that both C++ and QML know that a "Card" has been played, and can adjust the new actions to take.
Referencing me to some (paid) extension does not help me to understand how to solve this problem in Qt.
-
The
Card
you are rerefercing here can be a class based on QQuickPaintedItem so that you can paint different PNG's on it. Apart from that this class will hold various state's of the card. These can be defined asQ_PROPERTY
so that they can be easily accessible from the QML.
Register this class using qmlRegisterType to make it available to the QML and to make it instantiable from ther eif required.Now to hold a list of these cards you can create a class based on QAbstractListModel. Make it available as model to QML by setting it as a contextProperty.
To show a deck of cards you can use a Repeater and set this model as its model and as adelegate
you instantiateCard
class which was registered earlier.
Im not sure how a table where the cards are placed can be viewed but I think a custom view
which can support drag and drag could be used. -
@peteritv said in Give me a head start please!:
@tham
V_play seems nice, but does it support card games?Of course, you can check the example([http://v-play.net/onu-mobile/](link url))
And it is NOT free?
It depend on what do you want to do, v-play offer free license for small game too(but do not support some features).
If you are running out of time, I strongly suggest you give v-play a shot, this lib could help you create the game faster.
If you have a lot of times and want to learn c++, Qt and qml more systematically, I would suggest you give the book Programming-principles and practice Using c++ second edition
After that, study this book--Game programming using Qt.
If you want to know more about c++, stack overflow introduce a lot of good books. c++ is a huge language, at the beginning you may find it very complicated, but if you follow the guide of Programming-principles and practice, everything should be fine. Make sure you fully understand the concept of RAII and the parent, child relationship of Qt, these mechanism hugely reduce codes complexity of c++ and make resource management even more easier to handle than those language with gc in most of the times.
There are many solutions to make things work. For me, I use qml to handle all of the front end(cards, deck, depot, music, animation etc) without model and view(I place the card on specific locations by simple math), use c++ to handle some of the game logic(with unit test, unit test is the main reason I pick c++ rather than js).
-
AFAICS, you are currently trying to do too few encapsulations e.g. in a classic multiplayer card game you have:
- One stack full of cards to shuffle.
At the start of the game:
- One hand of cards per player (from 0 to X cards)
- One stack of card to draw from (from card count minus (number of players times hand size) to 0)
While playing:
- Cards currently played on the table (depends on the game)
- A stack of won cards per player or teams of players (again depends on the game)
That's the kind of thing you should first draw before going with the coding part.
-