Пример #1
0
        void SpellExplodeButtonClick(object sender, EventArgs e)
        {
            // Only cast spell if wizard has some spell uses left!
            // TODO make this a high strength attack.

            if((activeHero as Wizard).spellExplodeRemaining != 0)
                {

                // See if there is an adjacent Tile in activeHero.facing direction, next to activeHero.location
                //   if (adjacent = null), fail shot
                //	 if (adjacent != null) see who is in location
                //   	if(nobody) continue shot
                //		if baddie, add to hit list
                //		add any other adjacent baddies to hit list
                //		resolve damage on hit list characters
                //	TODO when Heroes are damageable, add Heroes to hit list
                //	TODO add diagonals

                shotLocation = activeHero.location;
                Boolean shotOver = false;
                activeBaddie = null;
                shotVictim = null;
                everybody = heroes.Concat(visibleBaddies);
                spellVictims = new List<Baddie>();

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

                while (!shotOver){
                    if(shotLocation.Adjacent(activeHero.facing) == null) shotOver = true;
                    else
                    {
                        shotLocation = shotLocation.Adjacent(activeHero.facing);
                        foreach(Character potentialVictim in everybody)
                        {
                            if(potentialVictim.location == shotLocation)
                            {
                                shotVictim = potentialVictim;
                                shotOver = true;
                                break;
                            }
                        }
                        // Draw a square round the location to show it is the shot path, and add to redraw list
                        g.DrawImage((Bitmap) resources.GetObject("square_blue"),
                                new Rectangle((shotLocation.tileLocation.X*scale)+origin.X, (shotLocation.tileLocation.Y*scale)+origin.Y, scale, scale));
                        tilesForRedraw.Add(shotLocation);
                    }
                }

                // If there is a shotVictim, check its type. If it is a Baddie, add it to hitlist! If it is a Hero, shot does nothing.
                if(shotVictim != null)
                {
                    if (shotVictim is Baddie)
                    {
                        spellVictims.Add((Baddie) shotVictim);
                        // Get adjacent baddies (if any)

                        if(shotVictim.location.Adjacent(Direction.North) != null)
                        {
                            foreach(Character potentialVictim in everybody)
                            {
                                if(potentialVictim.location == shotVictim.location.Adjacent(Direction.North))
                                {
                                    if (potentialVictim is Baddie)
                                    {
                                        spellVictims.Add((Baddie) potentialVictim);
                                    }
                                }
                            }
                        }
                        if(shotVictim.location.Adjacent(Direction.East) != null)
                        {
                            foreach(Character potentialVictim in everybody)
                            {
                                if(potentialVictim.location == shotVictim.location.Adjacent(Direction.East))
                                {
                                    if (potentialVictim is Baddie)
                                    {
                                        spellVictims.Add((Baddie) potentialVictim);
                                    }
                                }
                            }
                        }
                        if(shotVictim.location.Adjacent(Direction.South) != null)
                        {
                            foreach(Character potentialVictim in everybody)
                            {
                                if(potentialVictim.location == shotVictim.location.Adjacent(Direction.South))
                                {
                                    if (potentialVictim is Baddie)
                                    {
                                        spellVictims.Add((Baddie) potentialVictim);
                                    }
                                }
                            }
                        }
                        if(shotVictim.location.Adjacent(Direction.West) != null)
                        {
                            foreach(Character potentialVictim in everybody)
                            {
                                if(potentialVictim.location == shotVictim.location.Adjacent(Direction.West))
                                {
                                    if (potentialVictim is Baddie)
                                    {
                                        spellVictims.Add((Baddie) potentialVictim);
                                    }
                                }
                            }
                        }

                        // Hit all baddies in spellVictims list!
                        foreach(Baddie victim in spellVictims)
                            {
                                activeBaddie = victim;
                                charactersForRedraw.Add(shotVictim);
                                HitBaddie();
                            }
                    }
                    else
                    {
                        // shotVictim is a Hero, so add to redraw list.
                        charactersForRedraw.Add(shotVictim);
                        FailShot();
                    }
                }
                else FailShot();

                // Deplete wizard remaining uses and update spell action button if appropriate.
                (activeHero as Wizard).spellExplodeRemaining--;
                if((activeHero as Wizard).spellExplodeRemaining == 0)
                {
                    spellExplodeButton.Image = Dungeons.Images.spell_explode_used;
                    DrawActionButtons();
                }
            }
        }
Пример #2
0
        void RangedCombatButtonClick(object sender, EventArgs e)
        {
            // See if there is an adjacent Tile in activeHero.facing direction, next to activeHero.location
            //   if (adjacent = null), fail shot
            //	 if (adjacent != null) see who is in location
            //   	if(nobody) continue shot
            //		if baddie, kill it
            //		if hero, fail shot

            shotLocation = activeHero.location;
            Boolean shotOver = false;
            activeBaddie = null;
            shotVictim = null;
            everybody = heroes.Concat(visibleBaddies);

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

            while (!shotOver){
                if(shotLocation.Adjacent(activeHero.facing) == null) shotOver = true;
                else
                {
                    shotLocation = shotLocation.Adjacent(activeHero.facing);
                    foreach(Character potentialVictim in everybody)
                    {
                        if(potentialVictim.location == shotLocation)
                        {
                            shotVictim = potentialVictim;
                            shotOver = true;
                            break;
                        }
                    }
                    // Draw a square round the location to show it is the shot path, and add to redraw list
                    g.DrawImage((Bitmap) resources.GetObject("square_blue"),
                            new Rectangle((shotLocation.tileLocation.X*scale)+origin.X, (shotLocation.tileLocation.Y*scale)+origin.Y, scale, scale));
                    tilesForRedraw.Add(shotLocation);
                }
            }

            // If there is a shotVictim, check its type. If it is a Baddie, kill it! If it is a Hero, shot does nothing.
            if(shotVictim != null)
            {
                if (shotVictim.GetType() != activeHero.GetType())
                {
                    activeBaddie = (Baddie) shotVictim;
                    HitBaddie();
                }
                else
                {
                    // shotVictim is a Hero, so add to redraw list.
                    charactersForRedraw.Add(shotVictim);
                    FailShot();
                }
            }
            else FailShot();
        }