Beispiel #1
0
        public override Collection<Field> GetPlaceableFields(Field field)
        {
            if (field == null)
            {
                return null;
            }

            Collection<Field> fields = base.GetPlaceableFields(field);
            if (field.RightField != null && field.ParentTile == field.RightField.ParentTile)
            {
                fields.Add(field.RightField);
            }

            if (field.BottomField != null && field.ParentTile == field.BottomField.ParentTile)
            {
                fields.Add(field.BottomField);
            }

            if (field.BottomRightField != null && field.ParentTile == field.BottomRightField.ParentTile)
            {
                fields.Add(field.BottomRightField);
            }

            return fields.Count < 4 ? null : fields;
        }
Beispiel #2
0
        /// <summary>
        /// Get all fields with any character on in adjected to given field
        /// </summary>
        /// <param name="field">field from which check adjected fields</param>
        /// <returns>list of fields with character on it</returns>
        public static List<Field> GetAllAdjectedFieldsWithCharacter(Field field)
        {
            List<Field> result = new List<Field>();

            foreach (var res in GetAllAdjectedFields(field))
            {
                if (res.GetCharacterOnSelf() != null)
                {
                    result.Add(res);
                }
            }

            return result;
        }
Beispiel #3
0
        /// <summary>
        /// Get all fields adjected to given field
        /// </summary>
        /// <param name="field">field from which we want all adjected fields</param>
        /// <returns>list of all adjected fields</returns>
        public static List<Field> GetAllAdjectedFields(Field field)
        {
            List<Field> result = new List<Field>();
            if (field.LeftField != null)
            {
                result.Add(field.LeftField);
            }

            if (field.RightField != null)
            {
                result.Add(field.RightField);
            }

            if (field.BottomField != null)
            {
                result.Add(field.BottomField);
            }

            if (field.TopField != null)
            {
                result.Add(field.TopField);
            }

            if (field.TopLeftField != null)
            {
                result.Add(field.TopLeftField);
            }

            if (field.TopRightField != null)
            {
                result.Add(field.TopRightField);
            }

            if (field.BottomLeftField != null)
            {
                result.Add(field.BottomLeftField);
            }

            if (field.BottomRightField != null)
            {
                result.Add(field.BottomRightField);
            }
            return result;
        }
Beispiel #4
0
        private Dictionary<int, HashSet<Field>> GetFieldsInRadius(Field original, int radius, FieldsRetriver retriver, bool includeSelf = false)
        {
            if (includeSelf)
            {
                searchResult.Add(0, new HashSet<Field>() { original });
            }
            else
            {
                searchResult.Add(0, new HashSet<Field>() { });
            }

            alreadyVisited.Add(original);
            HashSet<Field> radiusfields;

            Stack<Field> stack = new Stack<Field>();
            stack.Push(original);
            var i = 1;

            while (stack.Count > 0 && i <= radius)
            {
                if (!searchResult.ContainsKey(i))
                {
                    searchResult.Add(i, new HashSet<Field>() { });
                }
                searchResult.TryGetValue(i, out radiusfields);

                HashSet<Field> tmp = retriver(stack, i);
                radiusfields.UnionWith(tmp);

                foreach (var f in tmp)
                {
                    stack.Push(f);
                    alreadyVisited.Add(f);
                }
                i++;
            }

            return searchResult;
        }
Beispiel #5
0
 public FieldFocusedEvent(object source, Field field)
 {
     Field = field;
 }
Beispiel #6
0
        /// <summary>
        /// Rotate field to reflect tile rotation
        /// </summary>
        /// <param name="field">field to rotate</param>
        /// <param name="rotation">rotation - 0 / 90 / 180 / 270 degrees</param>
        /// <param name="width">tile width</param>
        /// <param name="height">tile height</param>
        public static void RotateField(Field field, TileRotation rotation, int width, int height)
        {
            var newVector = MapVector.GetInversedVector(new Vector2(field.Rect.X, field.Rect.Y), width, height, rotation);
            var newX = (int)newVector.Value.X;
            var newY = (int)newVector.Value.Y;

            var tempOpenLeft = field.OpenLeft;
            var tempOpenRight = field.OpenRight;
            var tempOpenTop = field.OpenTop;
            var tempOpenBottom = field.OpenBottom;

            var tempTopField = field.TopField;
            var tempBottomField = field.BottomField;
            var tempLeftField = field.LeftField;
            var tempRightField = field.RightField;
            var tempTopRightField = field.TopRightField;
            var tempTopLeftField = field.TopLeftField;
            var tempBottomLeftField = field.BottomLeftField;
            var tempBottomRightField = field.BottomRightField;

            switch (rotation)
            {
                case TileRotation.DEGREE_90:
                    newX -= field.Rect.Width;
                    field.OpenLeft = tempOpenBottom;
                    field.OpenRight = tempOpenTop;
                    field.OpenTop = tempOpenLeft;
                    field.OpenBottom = tempOpenRight;

                    field.TopField = tempLeftField;
                    field.BottomField = tempRightField;
                    field.LeftField = tempBottomField;
                    field.RightField = tempTopField;

                    field.TopLeftField = tempBottomLeftField;
                    field.TopRightField = tempTopLeftField;
                    field.BottomRightField = tempTopRightField;
                    field.BottomLeftField = tempBottomRightField;
                    break;
                case TileRotation.DEGREE_180:
                    newX -= field.Rect.Width;
                    newY -= field.Rect.Height;
                    field.OpenLeft = tempOpenRight;
                    field.OpenRight = tempOpenLeft;
                    field.OpenTop = tempOpenBottom;
                    field.OpenBottom = tempOpenTop;

                    field.LeftField = tempRightField;
                    field.RightField = tempLeftField;
                    field.TopField = tempBottomField;
                    field.BottomField = tempTopField;

                    field.TopLeftField = tempBottomRightField;
                    field.TopRightField = tempBottomLeftField;
                    field.BottomRightField = tempTopLeftField;
                    field.BottomLeftField = tempTopRightField;
                    break;
                case TileRotation.DEGREE_270:
                    newY -= field.Rect.Height;
                    field.OpenLeft = tempOpenTop;
                    field.OpenRight = tempOpenBottom;
                    field.OpenTop = tempOpenRight;
                    field.OpenBottom = tempOpenLeft;

                    field.LeftField = tempTopField;
                    field.RightField = tempBottomField;
                    field.TopField = tempRightField;
                    field.BottomField = tempLeftField;

                    field.TopLeftField = tempTopRightField;
                    field.TopRightField = tempBottomRightField;
                    field.BottomRightField = tempBottomLeftField;
                    field.BottomLeftField = tempTopLeftField;
                    break;
            }

            field.Rect = new Rectangle(newX, newY, field.Rect.Width, field.Rect.Height);
            field.OriginRect = field.Rect;
        }
Beispiel #7
0
 public void MoveToField(Field field)
 {
     if (field != null && RemainingMovement >= Position.DistanceFrom(field))
     {
         var movementUsed = Position.DistanceFrom(field);
         Position.ObjectsOnField.Remove(this);
         field.ObjectsOnField.Add(this);
         Position = field;
         RemainingMovement -= movementUsed;
     }
 }
Beispiel #8
0
 public void Draw(SpriteBatch spriteBatch, Field field = null)
 {
     if (Position != null)
     {
         spriteBatch.Draw(ImageProvider.Instance.GetImage(GetMapToken()), GameCamera.Instance.GetMovedVector(Position.GetVector()));
     }
     else if (field != null)
     {
         spriteBatch.Draw(ImageProvider.Instance.GetOpaqueImage(GetMapToken(), 100), GameCamera.Instance.GetMovedVector(field.GetVector()));
     }
 }
Beispiel #9
0
 public virtual Collection<Field> GetPlaceableFields(Field field)
 {
     if (field == null)
     {
         return null;
     }
     return new Collection<Field>() { field };
 }
Beispiel #10
0
 public Dictionary<int, HashSet<Field>> GetFieldsInRadiusForMove(Field original, int radius)
 {
     return GetFieldsInRadius(original, radius, GetAllAdjectedFieldsForMove, false);
 }
Beispiel #11
0
        private void processField(Field item, Field adjected, int radius, HashSet<Field> result)
        {
            HashSet<Field> waterFields = new HashSet<Field>();

            if (!alreadyVisited.Contains(adjected))
            {
                result.Add(adjected);
            }
        }
Beispiel #12
0
 public Dictionary<int, HashSet<Field>> GetFieldsInRadius(Field original, int radius, bool includeSelf = false)
 {
     return GetFieldsInRadius(original, radius, GetAllAdjectedFields, includeSelf);
 }
Beispiel #13
0
 public int DistanceFrom(Field field)
 {
     return (int)Vector2.Distance(GetVector(), field.GetVector()) / 64;
 }
Beispiel #14
0
 public SearchToken(Field position)
 {
     Position = position;
 }