Ejemplo n.º 1
0
        public void Main()
        {
            Map   map   = new Map(8, 5);
            Point point = new Point(4, 2);
            // int area = map.Width * map.Height;
            bool  isOnMap = map.OnMap(point);
            Tower tower   = new Tower();

            Console.WriteLine(isOnMap);

            point   = new Point(8, 5);
            isOnMap = map.OnMap(point);
        }
Ejemplo n.º 2
0
        public static void Main()
        {
            Map map = new Map(8, 5);

            Point point   = new Point(4, 2);
            bool  isOnMap = map.OnMap(point);

            Console.WriteLine(isOnMap);

            point   = new Point(8, 5);
            isOnMap = map.OnMap(point);
            Console.WriteLine(isOnMap);
        }
Ejemplo n.º 3
0
 public MapLocation(int x, int y, Map map) : base(x, y)
 {
     if (!map.OnMap(this))
     {
         throw new OutOfBoundsExeption(x + "," + y + " is outside the boundaries of the map.");
     }
 }
Ejemplo n.º 4
0
 public MapLocation(int x, int y, Map map) : base(x, y)
 {
     if (!map.OnMap(this))
     {
         throw new OutOfBoundsException(this.ToString() + " is outside the map");
     }
 }
Ejemplo n.º 5
0
 public MapLocation(int x, int y, Map map) : base(x, y)
 {
     if (!map.OnMap(this))
     {
         throw new OutOfBoundsException($"The map location {x}, {y} is not on the map.");
     }
 }
Ejemplo n.º 6
0
        public static void Main()
        {
            Map map = new Map(8, 5);

            Point point   = new Point(4, 2);
            bool  isOnMap = map.OnMap(point);

            Console.WriteLine(isOnMap);
            //int distance = point.DistanceTo(point);
            //Console.WriteLine(DistanceTo);

            point   = new Point(8, 5);
            isOnMap = map.OnMap(point);
            Console.WriteLine(isOnMap);
            //Console.WriteLine(point);
            Console.ReadLine();
        }
Ejemplo n.º 7
0
 public MapLocation(int x, int y, Map map) : base(x, y)
 {
     if (!map.OnMap(this))
     {
         throw new OutOfBoundsException(this + " is outside of the boundaries of the" +
                                        " map.");
     }
 }
Ejemplo n.º 8
0
        public Tower(MapLocation location, Map map)
        {
            _location = location;

            if (!map.OnMap(_location))
            {
                throw new OutOfBoundsException("Towers cannot be placed on paths");
            }
        }
Ejemplo n.º 9
0
        public static void Main()
        {
            Map map = new Map(8, 5);

            //create a point in square (4,2)
            Point point   = new Point(4, 2);
            bool  isOnMap = map.OnMap(point);

            Console.WriteLine(isOnMap);


            //test with a point we know is off map, change value of point to this point
            point   = new Point(8, 5);
            isOnMap = map.OnMap(point);
            Console.WriteLine(isOnMap);

            //Get the distance between the point 4,2 and 5,5
            point = new Point(4, 2);
            Console.WriteLine(point.DistanceTo(5, 5));
        }
Ejemplo n.º 10
0
        public Tower(MapLocation location, Map map)
        {
            _location = location;

            /*validation for whether the tower is on the Map.
             * Uses the OnMap method which valides a point
             * The location variable is a MapLocation which is a sub-class
             * of the point class which makes this work*/
            if (!map.OnMap(this._location))
            {
                throw new OutOfBoundsException("Tower is outside of the map.");
            }
        }
Ejemplo n.º 11
0
        public static void Main()
        {
            Map map = new Map(8, 5);

            Point x = new MapLocation(4, 2);

            Point p = x;

            map.OnMap(new MapLocation(0, 0));

            Console.WriteLine(x.DistanceTo(5, 5));

            Console.WriteLine(x is MapLocation);
            Console.WriteLine(x is Point);

            Point point = new Point(0, 0);

            Console.WriteLine(point is MapLocation);
        }
Ejemplo n.º 12
0
        static void Main()
        {
            // convention is to name classes with upper case first letter, so you can name the object by their type (class)
            //object is an instance of a class
            Tower tower = new Tower();

            Map map = new Map(8, 5);
            // map.Width = 8;  //can not do, due to readonly access

            Point point  = new Point(9, 6);
            Point point2 = new Point(2, 3);


            Console.WriteLine(map.Width);
            Console.WriteLine(map.OnMap(point));    //not in bound
            Console.WriteLine(map.OnMap(point2));   //in bound

            Console.WriteLine("---------Overload----------");
            Console.WriteLine(point.DistanceTo(2, 3));
            Console.WriteLine(point.DistanceTo(point2));


            Console.WriteLine("---------Inheritance----------");
            MapLocation mappoint = new MapLocation(4, 2, map);

            Console.WriteLine("MapLocation using Point class's distance to: " + mappoint.DistanceTo(point2));
            Console.WriteLine(mappoint is MapLocation);
            Console.WriteLine(mappoint is Point);

            Console.WriteLine("----------Exception---------");
            //exception
            try
            {
                //maplocation throws exception in the constructor (MapLocation.cs)
                MapLocation mapLocation = new MapLocation(1000, 1000, map);
            }
            catch (OutOfBoundsException o_ex)
            {
                Console.WriteLine(o_ex.Message);
            }
            catch (TreehouseDefenseException)
            {
                Console.WriteLine("Unhandled TreehouseDefenseException");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            Console.WriteLine("----------Level---------");
            Path path = new Path(
                new[]
            {
                new MapLocation(0, 2, map),
                new MapLocation(1, 1, map)
            }
                );

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

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

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

            bool playerWon = level.Play();


            Console.ReadLine();
        }