Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Game Development
  4. how to make a turn-based battle system

how to make a turn-based battle system

Scheduled Pinned Locked Moved Unsolved Game Development
8 Posts 4 Posters 997 Views
  • 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.
  • milhaoM Offline
    milhaoM Offline
    milhao
    wrote on last edited by
    #1

    Hi, I wanted to know how to make a turn-based battle system?

    JonBJ D 2 Replies Last reply
    0
    • milhaoM milhao

      Hi, I wanted to know how to make a turn-based battle system?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @milhao What sort of an answer are you expecting to such a question?

      1 Reply Last reply
      1
      • Chris KawaC Offline
        Chris KawaC Offline
        Chris Kawa
        Lifetime Qt Champion
        wrote on last edited by
        #3
        class BattleSystem
        {
        public:
            void turn() {  /* implement */ }
        };
        

        Sorry for being snarky, but there's probably a book to be written about the subject. What exactly do you have a problem with? Have you researched the subject or tried to implement anything?

        milhaoM 1 Reply Last reply
        2
        • Chris KawaC Chris Kawa
          class BattleSystem
          {
          public:
              void turn() {  /* implement */ }
          };
          

          Sorry for being snarky, but there's probably a book to be written about the subject. What exactly do you have a problem with? Have you researched the subject or tried to implement anything?

          milhaoM Offline
          milhaoM Offline
          milhao
          wrote on last edited by
          #4

          @Chris-Kawa how to define player and enemy turns

          Chris KawaC 1 Reply Last reply
          0
          • milhaoM milhao

            @Chris-Kawa how to define player and enemy turns

            Chris KawaC Offline
            Chris KawaC Offline
            Chris Kawa
            Lifetime Qt Champion
            wrote on last edited by Chris Kawa
            #5

            @milhao If those are very different you can do something simple like

            while(someBattleEndCondition())
            {
               playerTurn();
               enemyTurn();
            }
            

            or you can have a common interface for player and the enemy and do something like

            class Unit {  ... };
            class Player : public Unit { ... };
            class Enemy : public Unit { ... };
            
            std::vector<Unit*> units {  new Player(), new Enemy() , new Enemy(), new Enemy(), ... };
            
            while(someBattleEndCondition())
            {
                for (auto unit : units)
                    turn(unit);
            }
            

            You could also model your game as a state machine using QStateMachine and define QStates like battle start, player turn, enemy turn, player won, player lost etc. and define transitions between those states based on your game logic.

            ...and gazillion other possibilities. There's really no single right or wrong solution to this. It all depends on your game structure.

            1 Reply Last reply
            3
            • milhaoM milhao

              Hi, I wanted to know how to make a turn-based battle system?

              D Offline
              D Offline
              DaShubWubDub
              wrote on last edited by
              #6

              @milhao
              So you could use QPainter to load and position images on screen, you can use this to hint to the customer what it is that your trying to convey through text/manuals, audio narration. I believe QPAinter has draw text and position options. Next you want to build a system by means of remembering to code in that style and or build a class that can have timers within them that will trigger displaying text and moving images in proper order.
              QOpenGL can do what QPainter does although it will use the graphics card instead of the customers CPU

              1 Reply Last reply
              0
              • D Offline
                D Offline
                DaShubWubDub
                wrote on last edited by DaShubWubDub
                #7

                You could have game elements proverbial “living” as a specific class, that class will emit an action Everytime the game changes.

                You can have a

                class character {
                 Public:
                   Int health = 100;
                   Int aggression = 3;
                
                int magic_resistance = 2;
                
                   Void apply_magic_attack_to_character(int attack_power, int mana)
                {
                
                //apply resistance subtract result
                 Health = health - (attack_power * (mana / magic_resistance ));
                
                Emit character_health_result_affected(this)
                }
                }
                
                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  DaShubWubDub
                  wrote on last edited by DaShubWubDub
                  #8

                  The signal emitted can be caught by a class that controls the QPainter, the slot can be as such

                  Class visualizer
                  {
                  Public slot:
                    Void character_health_affected
                  {
                    //show blood or shake effect styled images 
                  
                  //timeout the blood, hide/delete blood effects after a few seconds
                  }
                  }
                  
                  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