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
Post a Comment