Esempio n. 1
0
 public Boolean WallCollision(Character character, Direction direction)
 {
     Boolean result = false;
     if (direction == Direction.North && character.location.Y == 0
         || direction == Direction.East && character.location.X == this.pixelsX - 100
         || direction == Direction.South && character.location.Y == this.pixelsY - 100
         || direction == Direction.West && character.location.X == 0)
     {
         result = true;
     }
     return result;
 }
Esempio n. 2
0
        void RangedCombatButtonClick(object sender, EventArgs e)
        {
            shotLocation = activeHero.location;
            activeBaddie = null;
            shotVictim = null;
            everybody = heroes.Concat(baddies);

            // Shoot in straight line until hit wall or other Character. If Character encountered, decide outcome based on Type.

            switch(activeHero.facing)
            {
                    case Direction.North:
                        while ((shotVictim == null) && (shotLocation.Y > 0))
                            {
                                foreach (Character potentialVictim in everybody)
                                {
                                    if (!CheckAdjacencyAvailable(Direction.North, shotLocation, potentialVictim.location))
                                    {
                                        shotVictim = potentialVictim;
                                        break;
                                    }
                                }
                            g.DrawRectangle(pen1, shotLocation.X, shotLocation.Y - 100, 100, 100);
                            shotLocation.Y -= 100;
                        } break;
                    case Direction.East:
                        while ((shotVictim == null) && (shotLocation.X < 400))
                            {
                                foreach (Character potentialVictim in everybody)
                                {
                                    if (!CheckAdjacencyAvailable(Direction.East, shotLocation, potentialVictim.location))
                                    {
                                        shotVictim = potentialVictim;
                                        break;
                                    }
                                }
                            g.DrawRectangle(pen1, shotLocation.X + 100, shotLocation.Y, 100, 100);
                            shotLocation.X += 100;
                        }
                        break;
                    case Direction.South:
                        while ((shotVictim == null) && (shotLocation.Y < 400))
                            {
                                foreach (Character potentialVictim in everybody)
                                {
                                    if (!CheckAdjacencyAvailable(Direction.South, shotLocation, potentialVictim.location))
                                    {
                                        shotVictim = potentialVictim;
                                        break;
                                    }
                                }
                            g.DrawRectangle(pen1, shotLocation.X, shotLocation.Y + 100, 100, 100);
                            shotLocation.Y += 100;
                        }
                        break;
                    case Direction.West:
                        while ((shotVictim == null) && (shotLocation.X > 0))
                            {
                                foreach (Character potentialVictim in everybody)
                                {
                                    if (!CheckAdjacencyAvailable(Direction.West, shotLocation, potentialVictim.location))
                                    {
                                        shotVictim = potentialVictim;
                                        break;
                                    }
                                }
                            g.DrawRectangle(pen1, shotLocation.X - 100, shotLocation.Y, 100, 100);
                            shotLocation.X -= 100;
                        }
                        break;
            }

            // If there is a shotVictim, check its type. If if it a Baddie, kill it! If it is a Hero, shot does nothing.
            if(shotVictim != null)
            {
                if (shotVictim.GetType() != activeHero.GetType())
                {
                    activeBaddie = (Baddie) shotVictim;
                    KillShot();
                } else FailShot();
            } else FailShot();
        }