Putting It All Together
We have a really nice set of classes, but nothing ties them all together yet. Now, we will write the code of how the game runs.
Now, let's create another class called Level class. This class correlated with Invader and getting and setting the Tower class. And don't forget of using constructor.
class Level
{
private readonly Invader[] _invaders;
public Tower[] Towers { get; set; }
public Level (Invader[] invaders)
{
_invaders = invaders;
}
}
Now, we create Play
method. Play method consists of method to keep looping until there are no invaders or the invaders reach the end of map.
This is the sketch of out Play() method.
public bool Play()
{
// run until all invaders are neutralized or reach the end of map
// each tower has opportunity to fire on invaders
// count and move the invaders that are still active
}
public bool Play()
{
// run until all invaders are neutralized or reach the end of map
int remainingInvaders = _invaders.Length;
// each tower has opportunity to fire on invaders
// count and move the invaders that are still active
}