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); }
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); }
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."); } }
public MapLocation(int x, int y, Map map) : base(x, y) { if (!map.OnMap(this)) { throw new OutOfBoundsException(this.ToString() + " is outside the map"); } }
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."); } }
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(); }
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."); } }
public Tower(MapLocation location, Map map) { _location = location; if (!map.OnMap(_location)) { throw new OutOfBoundsException("Towers cannot be placed on paths"); } }
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)); }
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."); } }
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); }
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(); }