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

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

I made the Arrays for attacks and attack damage. How do I pick a random attack to be used?