public static void Main()
        {
            Map map = new Map(8, 5);

            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)
                }
                    );
                IInvader[] invaders =
                {
                    new ShieldedInvader(path),
                    new FastInvader(path),
                    new StrongInvader(path),
                    new BasicInvader(path),
                    new ResurrectingInvader(path)
                };
                Tower[] towers =
                {
                    new PowerfulTower(new MapLocation(1, 1, map)),
                    new SuperTower(new MapLocation(1,    1, map)),
                    new Tower(new MapLocation(1,         1, map))
                };
                Level level = new Level(invaders)
                {
                    Towers = towers
                };

                bool playerWon = level.Play();

                Console.WriteLine("Player " + (playerWon? "won" : "lost"));
                MapLocation p = new MapLocation(7, 0, map);
                if (path.IsOnPath(p))
                {
                    Console.WriteLine(p + " is on path.");
                }
            }
            catch (OutOfBoundsException ex) {
                Console.WriteLine("OutOfBoundsException: " + ex.Message);
            }
            catch (TreehouseDefenseException) {
                Console.WriteLine("Unhandled TreehouseDefenseException");
            }
            catch (Exception ex) {
                Console.WriteLine("Unhandled Exception: " + ex);
            }
        }
Exemple #2
0
 public Tower(MapLocation location, Map map, Path path)
 {
     _map  = map;
     _path = path;
     if (!map.IsOnMap(location))
     {
         throw new OutOfBoundsException($"({location.X},{location.Y}) is not on the map!");
     }
     else if (!path.IsOnPath(location))
     {
         _location = location;
     }
     else
     {
         throw new OnPathException($"({location.X},{location.Y}) cannot be placed on the path!");
     }
 }
Exemple #3
0
        public static void Main()
        {
            Map map = new Map(8, 5);

            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)
                }
                    );

                MapLocation location = new MapLocation(0, 2, map);

                if (path.IsOnPath(location))
                {
                    Console.WriteLine(location + " is on the path");
                    return;
                }

                Invader[] invaders =
                {
                    new ShieldedInvader(path),
                    new FastInvader(path),
                    new StrongInvader(path),
                    new BasicInvader(path)
                };

                Tower[] towers =
                {
                    new Tower(new MapLocation(1,          3, map)),
                    new PowerfulTower(new MapLocation(3,  3, map)),
                    new SniperTower(new MapLocation(5,    3, map)),
                    new LongrangeTower(new MapLocation(2, 4, map))
                };

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

                bool playerWon = level.Play();

                Console.WriteLine("Player " + (playerWon ? "won" : "lost"));
            }
            catch (OutOfBoundsException ex)
            {
                Console.WriteLine(ex.Message);
            }
            catch (TreeHouseDefenseException)
            {
                Console.WriteLine("Unhandled TreeHouseDefenseException");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Unhandled Exception: " + ex.Message);
            }
        }