Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Give me a head start please!
Forum Updated to NodeBB v4.3 + New Features

Give me a head start please!

Scheduled Pinned Locked Moved Solved General and Desktop
28 Posts 4 Posters 9.4k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • thamT tham

    Maybe v-play could give you some help, it provide a decent card game example.

    P Offline
    P Offline
    peteritv
    wrote on last edited by
    #21

    @tham
    V_play seems nice, but does it support card games?

    And it is NOT free?

    thamT 1 Reply Last reply
    0
    • P peteritv

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

      P Offline
      P Offline
      peteritv
      wrote on last edited by
      #22

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

      P 1 Reply Last reply
      0
      • P peteritv

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

        P Offline
        P Offline
        peteritv
        wrote on last edited by
        #23

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

        P 1 Reply Last reply
        0
        • P peteritv

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

          P Offline
          P Offline
          peteritv
          wrote on last edited by
          #24

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

          1 Reply Last reply
          0
          • p3c0P Offline
            p3c0P Offline
            p3c0
            Moderators
            wrote on last edited by
            #25

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

            157

            1 Reply Last reply
            1
            • P peteritv

              @tham
              V_play seems nice, but does it support card games?

              And it is NOT free?

              thamT Offline
              thamT Offline
              tham
              wrote on last edited by tham
              #26

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

              1 Reply Last reply
              1
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #27

                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.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • P Offline
                  P Offline
                  peteritv
                  wrote on last edited by
                  #28

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

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved