Playing the Game

Let's back to our Game class to play the game. Now, create the invaders, towers, and levels.

try
{
    Path path = new Path(
        new[]
        {
            new MapLocation(0, 2, map),
            new MapLocation(1, 2, map),
            new MapLocation(2, 2, map),
            new MapLocation(3, 2, map),
            new MapLocation(4, 2, map),
            new MapLocation(5, 2, map),
            new MapLocation(6, 2, map),
            new MapLocation(7, 2, map)
        });

    Invader[] invaders =
    {
        new Invader(path),
        new Invader(path),
        new Invader(path),
        new Invader(path)
    };

    Tower[] towers = 
    {
        new Tower( new MapLocation(1,3,map)),
        new Tower( new MapLocation(3,3,map)),
        new Tower( new MapLocation(5,3,map))
    };

    Level level = new Level(invaders)
    {
        Towers = towers
    };
}

Now, let's print if player won the game or not.

bool playerWon = level.Play();

Console.WriteLine("Player " + (playerWon ? "won" : "lost"));

results matching ""

    No results matching ""