I am creating a game using a 2D array grid, with the player controlling a character with enemies (with different stats/values) around the area. When the character is on the same grid as an enemy, the program initiates a battle function which contains large amounts of code that dictates how the battle works . However, since I want enemies to have different stats, I've been using structures in order to organize character/enemy stats.

For example:

```
struct Character { //character stats
    int hp;
    int atk;
    int warpstk;
    int heal;
    int mana;
    int money;
};

struct Enemy { //enemy stats
    int mhp;
    int matk;
    int mwarpstk;
    int mheal;
};

Character Player =
{
    50, //Player.hp
    10, //Player.atk
    18, //Player.warpstk
    12,  //Player.heal
    30, //Player.mana
    50, //Player.money
};

Enemy Goblin =
{
    40, //Goblin.mhp
    10, //Goblin.matk
    12, //Goblin.mwarpstk
    8, //Goblin.heal
};

Enemy Dragon = 
{
    100, //Goblin.mhp
    50, //Goblin.matk
    70, //Goblin.mwarpstk
    15, //Goblin.heal
};

//I want to modify the follow function so that it would change who the player is fighting depending on the grid placement.

void battleSequence(){
   while (Player.hp > 0 && Goblin.hp > 0)
   {
    //randon battle code
   }
int main()
{
  if (player.x == goblin.x && player.y == goblin.y)
        {

            battleSequence();

            if (Goblin.mhp < 1)
            {
                goblin.x = 25; //gave the goblin coordinates an out of bounds coordinate to leave loop
                goblin.y = 25; //gave the goblin coordinates an out of bounds coordinate to leave loop
                system("cls");
            }
        }
  //Probably gonna do the same conditional for the dragon, but it entirely depends on the battle function
}

```

However, if I were to call the battle sequence function when my character is on the same grid as a goblin, how would I do it so it would be unnecessary to create a battle function of each and every enemy? How would I be able to avoid duplicate code lying around my program? Because so far, I have one function which uses only two variables for player stats: Player and Goblin, and I would hate to create another function for Player and Dragon, due to the length of the function (which is not shown here).

In other words, how would I be able to create ONE general battle sequence function that is accessable for every enemy, but I would only be fighting a "dragon" if I were on their grid, and only a "goblin" if I were on their grid?

(If you need more clarity, please do ask since it is pretty hard to comprehend my question. Ask if you need github repository of my current progress)