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)

    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 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)

    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 ...

    Even: some games may rank a specific card to be highest (e.g. Q of spades) and next in line second ( e.g. J of clubs)
    How to deal with that?



  • @peteritv said in Give me a head start please!:

    @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)

    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 ...

    Even: some games may rank a specific card to be highest (e.g. Q of spades) and next in line second ( e.g. J of clubs)
    How to deal with that?

    OK, In a trump game, there is a natural order (cardStart to cardEnd) with possibly a enum or so that defines things.
    The highest order wins the trick.



  • @peteritv said in Give me a head start please!:

    @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)

    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 ...

    Even: some games may rank a specific card to be highest (e.g. Q of spades) and next in line second ( e.g. J of clubs)
    How to deal with that?

    Last 2 examples where just card values, NOT card ranks...

    If a player takes a trick, and Q of spades happens to be among the cards played, then some extra actions should be possible



  • Suppose we start with an fixed array of cards...

    Suits: 0-3 Meaning Clubs to Spades
    Ranks: 0-12 Meaning 2 to ace



  • I get lost in all the tal about QAbstract* and QItem* talk



  • @peteritv said in Give me a head start please!:

    I get lost in all the tal about QAbstract* and QItem* talk

    Can Someone please advise me how to start, with in mind that every change (every card played) should be kept in a database?


  • Lifetime Qt Champion

    Hi,

    Not a direct answer but you may find the KPatience game interesting to help you get started.

    Hope it helps.



  • @peteritv said in Give me a head start please!:

    @peteritv said in Give me a head start please!:

    I get lost in all the tal about QAbstract* and QItem* talk

    Can Someone please advise me how to start, with in mind that every change (every card played) should be kept in a database?

    I started out with:

    Class Card{
    <some_enum> suit;
    <some_enum> rank;
    }

    Everything should be acessible to C=++:

    So is it better to write this in QML?



  • @SGaist Hi SGaist, KPatience shows promise, but does not explain anything, right? :(

    I need to find a way to tell the system to when to print a Card as PDF (for example, using the HTML view), or to put it on screen using the picture view.

    Sorry I am such a beginner...


  • Lifetime Qt Champion

    Something like QPdfWriter ?



  • @peteritv
    For example:

    In a PDF I want to display how a game was played, using something like:

    "Trick 1: ♠5 ♣4 ♥6 ♠8""
    Trick was won by ♠8



  • @peteritv said in Give me a head start please!:

    @peteritv
    For example:

    In a PDF I want to display how a game was played, using something like:

    "Trick 1: ♠5 ♣4 ♥6 ♠8""
    Trick was won by ♠8

    While in the mean time, with the same setup, on screen the correct images (pixmap 100x150 or so) of the cards are shown.



  • @peteritv
    I will have something like a "Trick" Class, that shows what 4 cards (4 players) are being played onScreen...
    It will show images of the 4 cards involved into specific "Seats".

    So suppose Players "North", "East", "South" and "West",
    When a Card is played, onscreen I want to see the image (CA.png for club ace), but in PDF I want to see <♣A>

    It will show images of the cards being played (the pixmaps), and when I want to document, I want to show the HTML view



  • @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 highest

    I 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.


  • Moderators

    @peteritv

    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 as Q_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 a delegate you instantiate Card 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).


  • Lifetime Qt Champion

    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.



  • @SGaist and @tham : Thanks for the tips! I just installed V-Play, and it sure has a lot of very usefull stuff in it!
    Since I am currently unemployed, I have all the time in the world to study Qt, QML, C++ and now V-Play :)

    I'll get back to you guys when I get further along the road, OK?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.