0

I want to do something like if image name (which are currently in picture box) = enemy1 do this and if image name = enemy2 do something else

       case 1:
              Image enemy1 = zaverpol.Properties.Resources._1tier_enemy;
                    this.pictureBox_enemy.Image = enemy1;
                    enemyhealth = 10; enemyattack = 5;
                    ActualizationEnemyStats();
                    break;
       case 2:
              Image enemy2 = zaverpol.Properties.Resources._2tier_enemy;
                    this.pictureBox_enemy.Image = enemy2;

1 Answers1

0

Everytime you set the image in the PictureBox, set the Tag to a string with the image name as well.

Then:

Image enemy;

switch(this.pictureBox_enemy.Tag) 
{
    case "1":
        enemy = zaverpol.Properties.Resources._1tier_enemy;
        enemyhealth = 10; enemyattack = 5;
        this.pictureBox_enemy.Image = enemy;
        break;
    case "2":
        enemy = zaverpol.Properties.Resources._2tier_enemy;
        enemyhealth = 20; enemyattack = 10; // example values?
        this.pictureBox_enemy.Image = enemy;
        break;
    ///...
}
ActualizationEnemyStats();
Attersson
  • 4,755
  • 1
  • 15
  • 29