Skip to content
Using a random variable in C++
Profile icon
LoveFromSkyy

I'm working on the first level of my game and I want to know how I can make the monster use a random attack on the player AND use the correct number of damage. Here is the data that I wrote for this part (I'm not including the whole code because the rest is useless):

void LevelStart(int XP, int Lvl, int NewXP, int AddXP, int NewLvl){ int playerAttack; struct Hero player; struct Attacks playerAttacks; struct Attacks monsterAttacks; struct Monster easyLevelMonster; // Player attacks and stats player.health = 150; playerAttacks.attack1 = "FireBall"; playerAttacks.attack2 = "Fire Slash"; playerAttacks.attack3 = "Fire Barrage"; playerAttacks.attack4 = "Blue Flame Bomb"; playerAttacks.damageAttack1 = 4; playerAttacks.damageAttack2 = 9; playerAttacks.damageAttack3 = 14; playerAttacks.damageAttack4 = 19; // Monster attacks and stats easyLevelMonster.monsterCount = 1; easyLevelMonster.monsterType = "monster"; easyLevelMonster.monsterHealth = 100; monsterAttacks.attack1 = "bash"; monsterAttacks.attack2 = "Spin attack"; monsterAttacks.attack3 = "Heavy punch"; monsterAttacks.damageAttack1 = 10; monsterAttacks.damageAttack2 = 15; monsterAttacks.damageAttack3 = 20;

Tell me if you need more of the code to answer this. Please help me with this.

You are viewing a single comment. View All
Answered by 19wintersp [earned 5 cycles]
View Answer
Profile icon
LoveFromSkyy

Thank you! How can I implement this into my code? I looked stuff like this up but I don't want a random number, I'm looking for a random variable like

monsterAttacks.attack1 = "bash"; monsterAttacks.attack2 = "Spin attack"; monsterAttacks.attack3 = "Heavy punch";

@19wintersp