C# way of telling how many enemies alive -


i have base game class , enemy class.

when instantiate enemy using base game integer increase , when 1 dies need decrease integer.

the end result being new enemy spawns every few seconds long integer less max_enemies

any way i'm clue less , hoping direct me how should arrange ( have enemies increase number when spawn? )

here's basic idea: use factory method. may want handle of specifics differently.

void main() {     var game = new game();     game.createenemy("blinky");     console.writeline(game.enemycount);     game.createenemy("clyde");     console.writeline(game.enemycount);     game.destroyenemy(game.enemies[0]);     console.writeline(game.enemycount); }  public class game {     public list<enemy> enemies = new list<enemy>();      public void createenemy(string name)     {         if (enemycount >= max_enemies) return;         var enemy = new enemy { name = name};         enemies.add(enemy);     }      public void destroyenemy(enemy enemy)     {         enemies.remove(enemy);     }      public int enemycount     {         { return enemies.count(); }     } }  public class enemy {     public string name { get; set; } } 

Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -