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. How to implement a board game with a custom board and pieces
Forum Updated to NodeBB v4.3 + New Features

How to implement a board game with a custom board and pieces

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 4 Posters 488 Views 1 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.
  • N Offline
    N Offline
    NullFunction
    wrote on last edited by
    #1

    Hi all,

    I'm a Qt beginner and a bit overwhelmed by the size of the API. I'm looking to the following using C++ only, without QML or the WYSIWYG editor.

    I'm looking to implement a board game with two colors (like chess) but where, unlike chess, players have to put the pieces on the board themselves before the game starts.

    I'm wondering where I should look to:

    1. Create a board with alternate colors and which could be resized if the window is resized. I was thinking about using a Widget but I'm not sure how to make that resizable, should it rather be a table view?

    2. Create interactive pieces that can be either clicked on or drag-n-drop'ed to a new place on the board. This is definitely widget territory as far as I understand.

    3. Color my pieces and display their values: each piece has a color and a value that should be displayed, it signifies how "strong" a piece is. I'm lost as to how I can color those items and display a value on top of the color.

    The game logic is already implemented, it is called "Stratego" but I'm a bit lost as to how where I should look to implement the board, the pieces and not make insane design decisions.

    Thanks

    M 1 Reply Last reply
    0
    • S Offline
      S Offline
      saeed
      wrote on last edited by
      #2

      Game is 3D or 2D?
      if 2D, you can design your board in QML with Canves.
      https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API

      1 Reply Last reply
      0
      • N Offline
        N Offline
        NullFunction
        wrote on last edited by
        #3

        It's a 2D game and I'm to use C++, not QML.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          saeed
          wrote on last edited by
          #4

          @NullFunction you can use QPainter class.
          https://doc.qt.io/qt-5/qpainter.html#details

          1 Reply Last reply
          0
          • N NullFunction

            Hi all,

            I'm a Qt beginner and a bit overwhelmed by the size of the API. I'm looking to the following using C++ only, without QML or the WYSIWYG editor.

            I'm looking to implement a board game with two colors (like chess) but where, unlike chess, players have to put the pieces on the board themselves before the game starts.

            I'm wondering where I should look to:

            1. Create a board with alternate colors and which could be resized if the window is resized. I was thinking about using a Widget but I'm not sure how to make that resizable, should it rather be a table view?

            2. Create interactive pieces that can be either clicked on or drag-n-drop'ed to a new place on the board. This is definitely widget territory as far as I understand.

            3. Color my pieces and display their values: each piece has a color and a value that should be displayed, it signifies how "strong" a piece is. I'm lost as to how I can color those items and display a value on top of the color.

            The game logic is already implemented, it is called "Stratego" but I'm a bit lost as to how where I should look to implement the board, the pieces and not make insane design decisions.

            Thanks

            M Offline
            M Offline
            mpergand
            wrote on last edited by mpergand
            #5

            @NullFunction
            For the board, have a look at QGraphicsView and QGraphicsScene classes.

            N 1 Reply Last reply
            2
            • VRoninV Offline
              VRoninV Offline
              VRonin
              wrote on last edited by
              #6

              I don't know the game but it looks like a grid so you probably can use the model/view framework for that (this is an example of implementation of chess that another user asked help with, you might use that as a starting example).

              If you want something half-decent looking, however, use a proper game engine like Godot

              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
              ~Napoleon Bonaparte

              On a crusade to banish setIndexWidget() from the holy land of Qt

              N 1 Reply Last reply
              2
              • M mpergand

                @NullFunction
                For the board, have a look at QGraphicsView and QGraphicsScene classes.

                N Offline
                N Offline
                NullFunction
                wrote on last edited by
                #7

                @mpergand Thanks for the advice, is there any notable difference between the two? From the docs, it seems they do similar things but were introduced at different times, or at least in different parts of the API, is my understanding correct?

                VRoninV 1 Reply Last reply
                0
                • N NullFunction

                  @mpergand Thanks for the advice, is there any notable difference between the two? From the docs, it seems they do similar things but were introduced at different times, or at least in different parts of the API, is my understanding correct?

                  VRoninV Offline
                  VRoninV Offline
                  VRonin
                  wrote on last edited by
                  #8

                  @NullFunction said in How to implement a board game with a custom board and pieces:

                  is there any notable difference between the two?

                  No, they are the 2 main pieces of the graphical framework, they do different things: https://doc.qt.io/qt-6/graphicsview.html

                  "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                  ~Napoleon Bonaparte

                  On a crusade to banish setIndexWidget() from the holy land of Qt

                  1 Reply Last reply
                  0
                  • VRoninV VRonin

                    I don't know the game but it looks like a grid so you probably can use the model/view framework for that (this is an example of implementation of chess that another user asked help with, you might use that as a starting example).

                    If you want something half-decent looking, however, use a proper game engine like Godot

                    N Offline
                    N Offline
                    NullFunction
                    wrote on last edited by
                    #9

                    @VRonin Thank you, I'm not allowed to use a game engine, it it were up to me, I probably wouldn't be using Qt to make a game.

                    I'll probably use the M/V framework but the docs are somewhat confusing to me; different parts of the API are presented in different examples but there doesn't seem to be an overarching logic to the how and why of the examples.

                    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