Exemple #1
0
 /// <summary>
 /// Is position A adjacent to position B?
 /// </summary>
 /// <param name="a"></param>
 /// <param name="b"></param>
 /// <returns>True if A is Adjacent to B</returns>
 public static bool IsAdjacent(MapPosition a, MapPosition b)
 {
     // Not exactly optimized
     foreach (Direction d in Enum.GetValues(typeof(Direction)))
     {
         MapPosition indir   = a.InDirection(d);
         bool        IsEqual = b == indir;
         if (a.InDirection(d) == b)
         {
             return(true);
         }
     }
     return(false);
 }
Exemple #2
0
    // Returns the target to attack if we decide to attack.
    // TODO: Possibility of multiple targets, should return the most prioritised target
    public CreatureStats GetAttackTarget()
    {
        attackDirections.Sort();
        foreach (Direction dir in attackDirections)
        {
            CreatureStats possibleTarget = CombatManager.GetCreatureAt(GridPosition.InDirection(dir));
            if (possibleTarget)
            {
                return(possibleTarget);
            }
        }

        // This probably should never happen
        return(CombatManager.GetCreatureAt(GetForward()));
    }
Exemple #3
0
    //Util map functions
    public static List <MapPosition> GetAdjacent(MapPosition position)
    {
        var adj = new List <MapPosition>();

        // Iterate over all the directions and check if they are valid positions
        foreach (Direction dir in Enum.GetValues(typeof(Direction)))
        {
            MapPosition tile = position.InDirection(dir);
            if (!OutOfBounds(tile))
            {
                adj.Add(tile);
            }
        }

        return(adj);
    }
    /// <summary>
    /// Returns the default tile for a creature to move in. This will always be x+1 or x-1 unless the creature is at the end of the lane and need to advance towards the general by switching lane.
    /// </summary>
    public static MapPosition GetAdvancingMovement(MapPosition position, Owner faction)
    {
        // If we are not at the end of the lane, just move forward.
        if (!Utils.IsAtEndOfLane(position, faction))
        {
            switch (faction)
            {
            case Owner.PLAYER:
                return(position.InDirection(Direction.RIGHT));

            case Owner.ENEMY:
                return(position.InDirection(Direction.LEFT));
            }
        }

        if (position.y <= 2)
        {
            switch (faction)
            {
            case Owner.PLAYER:
                if (position.y != 1)
                {
                    return(position.InDirection(Direction.DOWNRIGHT));
                }
                else
                {
                    return(position.InDirection(Direction.DOWNLEFT));
                }

            case Owner.ENEMY:
                if (position.y != 1)
                {
                    return(position.InDirection(Direction.DOWNLEFT));
                }
                else
                {
                    return(position.InDirection(Direction.DOWNRIGHT));
                }
            }
        }
        else
        {
            switch (faction)
            {
            case Owner.PLAYER:
                if (position.y == 3)
                {
                    return(position.InDirection(Direction.UPLEFT));
                }
                else
                {
                    return(position.InDirection(Direction.UPRIGHT));
                }

            case Owner.ENEMY:
                if (position.y == 3)
                {
                    return(position.InDirection(Direction.UPRIGHT));
                }
                else
                {
                    return(position.InDirection(Direction.UPLEFT));
                }
            }
        }
        throw new Exception("Error finding advancing move. Invalid faction? " + faction + ", " + position);
    }