示例#1
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();
        }
示例#2
0
        void FightButtonClick(object sender, System.EventArgs e)
        {
            forwardButton.Enabled = false;
            leftTurnButton.Enabled = false;
            rightTurnButton.Enabled = false;
            closeCombatButton.Enabled = false;
            rangedCombatButton.Enabled = false;

            // Find if there is a baddie adjacent to activeHero, and if so set activeBaddie to it
            activeBaddie = null;
            foreach (Baddie baddie in baddies)
            {
                switch(activeHero.facing){
                    case Direction.North: if (!CheckAdjacencyAvailable(Direction.North, activeHero.location, baddie.location))
                                activeBaddie = baddie; break;
                    case Direction.East : if (!CheckAdjacencyAvailable(Direction.East, activeHero.location, baddie.location))
                                activeBaddie = baddie; break;
                    case Direction.South : if (!CheckAdjacencyAvailable(Direction.South, activeHero.location, baddie.location))
                                activeBaddie = baddie; break;
                    case Direction.West : if (!CheckAdjacencyAvailable(Direction.West, activeHero.location, baddie.location))
                                activeBaddie = baddie; break;
                }
            }

            // If there is a baddie infront of activeHero, kill it
            if (activeBaddie !=null)
            {
                successfulFightButton.Visible = true;
                this.score += 5;
                scoreTextBox.Clear();
                scoreTextBox.Text = score.ToString();

                // Draw dead baddie
                g.DrawImageUnscaled((Bitmap) resources.GetObject("dead_baddie"), activeBaddie.location);
                g.DrawRectangle (pen2, activeBaddie.location.X, activeBaddie.location.Y, 100, 100);

                // Remove baddie from baddies
                baddies.Remove(activeBaddie);
            } else failedFightButton.Visible = true;
        }