Esempio n. 1
0
 //Returns a list of tiles containing a valid target in range of the given ability
 //That list is stored on the ability object and is cleared with each new (non-recursive) call to this method
 public List<Tile> checkRange(Tile origin, Ability ability, int range, Piece user)
 {
     //Clears the list if this is the initial call because the parameter "range" will only equal ability.range if this is the first call
     if (ability.getRange() == range)
     {
         validTargets = new List<Tile>();
     }
     List<Tile> frontier = getNeighbors(origin, new List<Tile>());
     if (!origin.isEmpty())
     {
         //If ability targets enemies & the tile contains a unit from the other faction & if the tile is not already in the list THEN the tile is added
         if (ability.getTargetType().Equals("Enemy") && !(origin.getResident().getFaction().Equals(user.getFaction())) && !validTargets.Contains(origin))
         {
             validTargets.Add(origin);
         }
         //If ability targets friendlies & the tile contains a unit from the same faction & if the tile is not already in the list THEN the tile is added
         else if (ability.getTargetType().Equals("Friendly") && (origin.getResident().getFaction().Equals(user.getFaction())) && !validTargets.Contains(origin))
         {
             validTargets.Add(origin);
         }
     }
     //decrement range for the next round of checks
     int nRange = range - 1;
     if (nRange >= 0)
     {
         for (int i = 0; i < frontier.Count(); i++)
         {
             checkRange(frontier[i], ability, nRange, user);
         }
     }
     return validTargets;
 }
Esempio n. 2
0
        private void findMoves(Tile location, int ap, Piece piece)
        {
            int remainingPoints = ap;
            List<Tile> neighbors = getNeighbors(location, new List<Tile>());

            for (int i = 0; i < neighbors.Count; i++)
            {
                Tile tile = neighbors[i];
                int cost;
                if (tile.getTerrain().Equals("Plain"))
                {
                    cost = 1;
                }
                else if (tile.getTerrain().Equals("Woods"))
                {
                    cost = 2;
                }
                else if (tile.getTerrain().Equals("Mountain"))
                {
                    cost = 4;
                }
                else
                {
                    cost = 999;
                }
                if (remainingPoints >= cost && !piece.validMoves.Contains(neighbors[i]))
                {
                    if (neighbors[i].isEmpty())
                    {
                        piece.validMoves.Add(neighbors[i]);
                        findMoves(neighbors[i], remainingPoints - cost, piece);
                        return;
                    }
                    else
                    {
                        if (neighbors[i].getResident().getFaction().Equals(piece.getFaction()))
                        {
                            findMoves(neighbors[i], remainingPoints - cost, piece);
                            return;
                        }
                        else
                        {
                            return;
                        }
                    }
                }
                else
                {
                    return;
                }
            }
        }
Esempio n. 3
0
        public void findTargets(Tile location, int range, Piece piece)
        {
            int remainingRange = range;
            List<Tile> neighbors = getNeighbors(location, new List<Tile>());

            for (int i = 0; i < neighbors.Count; i++)
            {
                //If there is sufficient ap and validMoves does not already hold that tile
                if (remainingRange >= 1 && !validTargets.Contains(neighbors[i]))
                {
                    //If the tile is empty it is not added to the list and another call made
                    if (neighbors[i].isEmpty())
                    {
                        //validTargets.Add(neighbors[i]);
                        findTargets(neighbors[i], remainingRange - 1, piece);
                    }
                    else
                    {
                        //if the tile is occupied BUT is occupied by a friendly another call is made but the tile is not added, the tile is not a valid target
                        //but the search still "paths" through it
                        if (neighbors[i].getResident().getFaction().Equals(piece.getFaction()))
                        {
                            findTargets(neighbors[i], remainingRange - 1, piece);
                        }
                        //if the tile is occupied by an enemy faction, add it to validTargets
                        else
                        {
                            validTargets.Add(neighbors[i]);
                            findTargets(neighbors[i], remainingRange - 1, piece);
                        }
                    }
                }
            }
        }
Esempio n. 4
0
        private void findMoves(Tile location, int ap, Piece piece)
        {
            int remainingPoints = ap;
            List<Tile> neighbors = getNeighbors(location, new List<Tile>());

            for (int i = 0; i < neighbors.Count; i++)
            {
                Tile tile = neighbors[i];
                int cost;
                if (tile.getTerrain().Equals("Plain"))
                {
                    cost = 1;
                }
                else if (tile.getTerrain().Equals("Woods"))
                {
                    cost = 2;
                }
                else if (tile.getTerrain().Equals("Mountain"))
                {
                    cost = 4;
                }
                else
                {
                    cost = 999;
                }
                //If there is sufficient ap
                if (remainingPoints >= cost)
                {
                    //If the tile is empty it is added to the list and another call made
                    if (neighbors[i].isEmpty())
                    {
                        //if validMoves does not already hold the tile
                        if (!validMoves.Contains(neighbors[i]))
                        {
                            validMoves.Add(neighbors[i]);
                        }
                        findMoves(neighbors[i], remainingPoints - cost, piece);
                    }
                    else
                    {
                        //if the tile is occupied BUT is occupied by a friendly another call is made but the tile is not added, the tile is not a valid move
                        //but the search still "paths" through it
                        if (neighbors[i].getResident().getFaction().Equals(piece.getFaction()))
                        {
                            findMoves(neighbors[i], remainingPoints - cost, piece);
                        }
                    }
                }
            }
        }
Esempio n. 5
0
        public override String execute(Piece user, Piece target)
        {
            String result;
            Random r = new Random();
            int chanceToHit;

            if (user.getName().Equals("Nomad") || user.getName().Equals("Archer"))
            {
                result = user.getFaction() + " " + user.getName();
                if (user.getName().Equals("Archer"))
                {
                    chanceToHit = 99 - 5 * (target.getDefense()/2 - user.getAttack());
                }
                else
                {
                    chanceToHit = 99 - 5 * (target.getDefense() - user.getAttack());
                }

                if (r.Next(100) < chanceToHit)
                {
                    result += " hits for " + user.getDamage();
                    target.applyDamage(user.getDamage());
                }
                else
                    result += " misses";
                if (target.getHealth() < 1)
                {
                    result += ", " + target.getFaction() + " " + target.getName();
                    result += " is killed";
                }
            }
            else
            {
                if (target.getName().Equals("Pikeman") && !user.getName().Equals("Pikeman"))
                {
                    result = target.getFaction() + " " + target.getName();
                    chanceToHit = 99 - 5 * (user.getDefense() - target.getAttack());

                    if (r.Next(100) < chanceToHit)
                    {
                        if (user.hasPieceMoved())
                        {
                            result += " hits for " + target.getDamage() * 2;
                            user.applyDamage(target.getDamage() * 2);
                        }
                        else
                        {
                            result += " hits for " + target.getDamage();
                            user.applyDamage(target.getDamage());
                        }
                    }
                    else
                        result += " misses";
                    result += ", " + user.getFaction() + " " + user.getName();
                    if (user.getHealth() > 0)
                    {
                        chanceToHit = 99 - 5 * (target.getDefense() - user.getAttack());
                        result += "'s retailiation";
                        if (r.Next(100) < chanceToHit)
                        {
                            result += " hits for " + user.getDamage() / 2;
                            target.applyDamage(user.getDamage() / 2);
                        }
                        else
                            result += " misses";
                    }
                    else
                        result += " is killed";
                }
                else if (user.getName().Equals("Swordsman"))
                {
                    result = user.getFaction() + " " + user.getName();
                    chanceToHit = 99 - 5 * (target.getDefense() - user.getAttack());

                    if (r.Next(100) < chanceToHit)
                    {
                        result += " hits for " + user.getDamage();
                        target.applyDamage(user.getDamage());
                    }
                    else
                        result += " misses";
                    result += ", " + target.getFaction() + " " + target.getName();
                    if (target.getHealth() > 0)
                    {
                        chanceToHit = 99 - 5 * (user.getDefense() - target.getAttack());
                        result += "'s retailiation";
                        if (r.Next(100) < chanceToHit)
                        {
                            result += " hits for " + target.getDamage() / 2;
                            user.applyDamage(target.getDamage() / 2);
                        }
                        else
                            result += " misses";
                        if (user.getHealth() < 1)
                        {
                            result += ", " + user.getFaction() + " " + user.getName();
                            result += " is killed";
                        }
                    }
                    else
                        result += " is killed";

                    result += user.getFaction() + " " + user.getName();
                    chanceToHit = 99 - 5 * (target.getDefense() - user.getAttack());

                    if (r.Next(100) < chanceToHit)
                    {
                        result += " hits for " + user.getDamage();
                        target.applyDamage(user.getDamage());
                    }
                    else
                        result += " misses";
                    if (target.getHealth() < 1)
                    {
                        result += ", " + target.getFaction() + " " + target.getName();
                        result += " is killed";
                    }
                }
                else if (user.getName().Equals("Knight"))
                {
                    result = user.getFaction() + " " + user.getName();
                    chanceToHit = 99 - 5 * (target.getDefense() - user.getAttack());

                    if (r.Next(100) < chanceToHit)
                    {
                        result += " hits for " + user.getDamage();
                        target.applyDamage(user.getDamage());
                    }
                    else
                        result += " misses";
                    result += ", " + target.getFaction() + " " + target.getName();
                    if (target.getHealth() > 0)
                    {
                        if (!(user.hasPieceMoved() && r.Next(2) == 1))
                        {
                            chanceToHit = 99 - 5 * (user.getDefense() - target.getAttack());
                            result += "'s retailiation";
                            if (r.Next(100) < chanceToHit)
                            {
                                result += " hits for " + target.getDamage() / 2;
                                user.applyDamage(target.getDamage() / 2);
                            }
                            else
                                result += " misses";
                            if (user.getHealth() < 1)
                            {
                                result += ", " + user.getFaction() + " " + user.getName();
                                result += " is killed";
                            }
                        }
                        else
                            result += "loses retailiation to charge";
                    }
                    else
                        result += " is killed";
                }
                else
                {
                    result = user.getFaction() + " " + user.getName();
                    chanceToHit = 99 - 5 * (target.getDefense() - user.getAttack());

                    if (r.Next(100) < chanceToHit)
                    {
                        result += " hits for " + user.getDamage();
                        target.applyDamage(user.getDamage());
                    }
                    else
                        result += " misses";
                    result += ", " + target.getFaction() + " " + target.getName();
                    if (target.getHealth() > 0)
                    {
                        chanceToHit = 99 - 5 * (user.getDefense() - target.getAttack());
                        result += "'s retailiation";
                        if (r.Next(100) < chanceToHit)
                        {
                            result += " hits for " + target.getDamage() / 2;
                            user.applyDamage(target.getDamage() / 2);
                        }
                        else
                            result += " misses";
                        if (user.getHealth() < 1)
                        {
                            result += ", " + user.getFaction() + " " + user.getName();
                            result += " is killed";
                        }
                    }
                    else
                        result += " is killed";
                }

            }

            if (target.getHealth() < 1)         //if target dies give user extra xp, else give the target xp. Prevents reviving dead units with lvling up
                user.addXP(80 * target.getLevel());         //amount of xp is determined by level
            else
                target.addXP(10 * user.getLevel());

            if (user.getHealth() < 1)
                target.addXP(55 * user.getLevel());
            else
                user.addXP(40 * target.getLevel());

            return result;
        }