Health bar/Damage system

Hello,

I am stuck on how to make a health bar for an enemy. This does the opposite of what I want it do. Instead of taking away '#' for damage it adds it. How can I do it the other way?

Thanks in advance

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
        while(zombieAHealth>0) {

            std::cout << "Press enter to attack" << std::endl;
            std::cout << "..." << std::endl;
            std::cin.ignore();
            std::cin.get();
            system("clear");
            std::cout << std::endl;

            srand(time(0));
            int bat_weapon = rand()%(5-1 + 1) + 1;
            std::cout << "# You hit him with " << weaponChoice << " and do " << bat_weapon << " damage!" << std::endl;
            zombieAHealth-=bat_weapon;
            std::cout << "____________"  << std::endl;
            std::cout << "|Zombie HP |" << std::endl;

            for(int i=10; i>zombieAHealth; i--){
                std::cout << "#";
            }

            std::cout <<std::endl;
            std::cout << "|----------|" << std::endl;
            std:: cout << "HP: " << zombieAHealth << std::endl;

        }
Maybe
1
2
3
for(int i=0; i<zombieAHealth; i++){
    std::cout << "#";
}

?
@naaissus

No, I already tried that. It doesn't print anything out for the health bar.
naaissus is correct.

1
2
3
4
//For each health point, iterate once and output that particular health point
for(int healthPoint = 0; healthPoint < zombieAHealth; healthPoint++){
    std::cout << "#";
}


It would be cool if you displayed underscores for the remaining missing health so you could have some idea of how much damage you've done!
Last edited on
Oh shit, my bad didn't realize he had changed i=0 from i=10. Thanks both of you and my apologies!

@wizebin +1
@naaissus +1
No worries, I didn't catch it at first either. Keep up the zombie stuff!
Topic archived. No new replies allowed.