Equals() public method

public Equals ( Rectangle other ) : bool
other Rectangle
return bool
Example #1
0
        //Contructs a tower. Throws exceptions for invalid ranges of values (18 lines)
        public Tower(String name, int health, int damage, int cost, int range, Rectangle location)
        {
            if (location.Equals(new Rectangle()))
                throw new ArgumentNullException();
            if (range <= 0)
                throw new ArgumentOutOfRangeException();
            if (damage < 0)
                throw new ArgumentOutOfRangeException();
            if (health <= 0)
                throw new ArgumentOutOfRangeException();
            if (cost < 0)
                throw new ArgumentOutOfRangeException();

            this.name = name;
            this.location = location;
            this.health = health;
            this.attackDamage = damage;
            this.cost = cost;
            this.range = range;
            this.updateCounter = 0;
            this.nearbyEnemies = new List<Enemy>();

            this.color = Color.White;
            switch (name)
            {
                case "path":
                    this.color = Color.Black;
                    break;
                case "slow":
                    this.color = Color.Blue;
                    break;
                case "dot":
                    this.color = Color.Red;
                    break;
                case "sniper":
                    this.color = Color.Green;
                    break;

            }

            if (color == Color.White)
                name = "basic";
        }
Example #2
0
        //Contructs a tower. Throws exceptions for invalid ranges of values (18 lines)
        public Tower(String name, int health, int damage, int cost, int range, Rectangle location)
        {
            if (location.Equals(new Rectangle()))
                throw new ArgumentNullException();
            if (range <= 0)
                throw new ArgumentOutOfRangeException();
            if (damage <= 0)
                throw new ArgumentOutOfRangeException();
            if (health <= 0)
                throw new ArgumentOutOfRangeException();

            if (cost <= 0)
                throw new ArgumentOutOfRangeException();

            this.name = name;
            this.location = location;
            this.health = health;
            this.attackDamage = damage;
            this.cost = cost;
            this.range = range;
            this.updateCounter = 0;
            this.nearbyEnemies = new List<Enemy>();
        }
Example #3
0
        //Constructs the Enemy class, throws 2 exceptions (ArgumentOurOfRangeException and ArgumentNullArgument) (15 lines)
        public Enemy(float health, double speed, String type, int gold, Rectangle location)
        {
            if (location.Equals(new Rectangle()))
                throw new ArgumentNullException();
            if (gold <= 0)
                throw new ArgumentOutOfRangeException();
            if (speed <= 0)
                throw new ArgumentOutOfRangeException();
            if (health <= 0)
                throw new ArgumentOutOfRangeException();

            if (type != "basic")
                throw new ArgumentException();

            this.maxHealth = health;
            this.health = health;
            this.speed = speed;
            this.type = type;
            this.gold = gold;

            this.location = location;

            this.inFiringRange = false;
        }
Example #4
0
 private void UpdateEnemyCollisions()
 {
     Rectangle rectangle1;
     Rectangle rectangle2;
     foreach (Enemy enemy1 in enemies.ToArray())
     {
         foreach (Enemy enemy2 in enemies.ToArray())
         {
             rectangle1 = new Rectangle((int)enemy1.getPosition.X, (int)enemy1.getPosition.Y, enemy1.Width, enemy1.Height);
             rectangle2 = new Rectangle((int)enemy2.getPosition.X, (int)enemy2.getPosition.Y, enemy2.Width, enemy2.Height);
             if (!rectangle1.Equals(rectangle2) && rectangle1.Intersects(rectangle2))
             {
                 enemy1.setActive(false);
                 enemy2.setActive(false);
             }
         }
     }
 }