I have my base game class and an enemy class.
When I instantiate an enemy using the base game I would like a integer to increase And when one dies I would need it to decrease the integer.
The end result being a new enemy spawns every few seconds so long as that integer is less than my MAX_ENEMIES
any way I'm currently clue less and was hoping someone could direct me with how I should arrange this ( do I have the enemies increase the number when they spawn? )
Here's the basic idea: use a Factory Method. You may want to handle some of the 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
{
get { return Enemies.Count(); }
}
}
public class Enemy
{
public string Name { get; set; }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With