Beispiel #1
0
        public void AnimateMoveTo(Chuzzle chuzzle, Vector3 targetPosition, float time = 0.3f)
        {
            if (chuzzle.IsDead)
            {
                return;
            }
            //Debug.Log("Move: "+name+" "+GetInstanceID());

            if (Vector3.Distance(targetPosition, chuzzle.transform.position) > 0.01f)
            {
                if (chuzzle.IsAnimationStarted)
                {
                    return;
                }
                chuzzle.InvokeAnimationStarted();
                iTween.MoveTo(chuzzle.gameObject,
                    iTween.Hash(
                        "x", targetPosition.x,
                        "y", targetPosition.y,
                        "z", targetPosition.z,
                        "time", time,
                        "easetype", iTween.EaseType.easeInOutQuad,
                        "oncomplete", new Action<object>(OnAnimateMoveEnd),
                        "oncompleteparams", chuzzle.gameObject
                        ));
            }
            else
            {
                chuzzle.transform.position = targetPosition;
            }
        }
Beispiel #2
0
 public static MoveDesc Create(Chuzzle chuzzle, Vector3 @from, Vector3 to)
 {
     return new MoveDesc()
     {
         Chuzzle = chuzzle,
         From = @from,
         To = to
     };
 }
        public static bool BetweenYCheck(Chuzzle chuzzle, IEnumerable<Chuzzle> allChuzzles)
        {
            var firstChuzzle = chuzzle;
            var secondChuzzle = allChuzzles.FirstOrDefault( ch =>
                                                            ch.Current.X == firstChuzzle.Current.X &&
                                                            ch.Current.Y == firstChuzzle.Current.Y + 2 &&
                                                            IsSameColor(ch, firstChuzzle));

            if (secondChuzzle == null || allChuzzles.Any(x => x.Current.Y == firstChuzzle.Current.Y + 1 && IsLock(x)))
                return false;

            return allChuzzles.Any(x => x.Current.Y == firstChuzzle.Current.Y + 1 && IsSameColor(x, firstChuzzle) );
        }
        // вертикальная и горизонтальная проверка для второго случая
        public static bool AnotherVerticalCheck(Chuzzle chuzzle, IEnumerable
                                                                     <Chuzzle> allChuzzles)
        {
            var firstChuzzle = chuzzle;
            var secondChuzzle =
                allChuzzles.FirstOrDefault(
                                           ch =>
                                           ch.Current.X == firstChuzzle.Current.X && ch.Current.Y == firstChuzzle.Current.Y + 1 &&
                                           IsSameColor(ch, firstChuzzle));

            if (secondChuzzle == null) return false;

            return
                allChuzzles.Where(
                                  ch =>
                                  Math.Abs(ch.Current.X - firstChuzzle.Current.X) == 1 || ch.Current.Y == firstChuzzle.Current.Y - 1 ||
                                  ch.Current.Y == firstChuzzle.Current.Y + 2).Any(ch => IsSameColor(ch, firstChuzzle));
        }
        private void OnTileDestroyed(Chuzzle destroyedChuzzle)
        {
            if (PlaceCoordinates.Count == 0 || destroyedChuzzle.IsReplacingOnDeath ||
                !GamefieldUtility.IsOrdinaryDestroyable(destroyedChuzzle))
            {
                return;
            }

            IntVector2 place =
                CurrentPlaceCoordinates.FirstOrDefault(
                    x => x.x == destroyedChuzzle.Current.X && x.y == destroyedChuzzle.Current.Y);
            if (place != null)
            {
                destroyedChuzzle.Current.IsPlace = false;
                CurrentPlaceCoordinates.Remove(place);
            }

            if (CurrentPlaceCoordinates.Count == 0)
            {
                IsWin = true;
            }
        }
Beispiel #6
0
 public void ReplaceWithRandom(Chuzzle toReplace)
 {
     CreateChuzzle(toReplace.Current);
     toReplace.Destroy(false, false, true);
 }
Beispiel #7
0
        public void ReplaceWithOtherColor(Chuzzle toReplace)
        {
            ChuzzleColor exceptColor = toReplace.Color;
            List<ChuzzleColor> possibleColors = ((ChuzzleColor[]) Enum.GetValues(typeof (ChuzzleColor))).ToList();
            possibleColors.Remove(exceptColor);

            ReplaceWithColor(toReplace, possibleColors[Random.Range(0, possibleColors.Count)]);
        }
 public static bool IsLock(Chuzzle chuzzle)
 {
     return chuzzle is LockChuzzle;
 }
Beispiel #9
0
 public void OnPointerDown(Chuzzle chuzzle)
 {
     FieldState.OnPointerDown(chuzzle);
 }
Beispiel #10
0
        private static Cell GetTopCell(IEnumerable<Cell> activeCells, Cell targetCell, Chuzzle c)
        {
            if (targetCell == null || targetCell.IsTemporary)
            {
                targetCell = GamefieldUtility.CellAt(activeCells, c.Current.X,
                    activeCells.Where(x => !x.IsTemporary).Min(x => x.Y));
                if (targetCell.Type == CellTypes.Block)
                {
                    targetCell = targetCell.GetTopWithType();
                }
            }
            else
            {
                targetCell = targetCell.GetTopWithType();

                if (targetCell == null)
                {
                    targetCell = GamefieldUtility.CellAt(activeCells, c.Current.X,
                        activeCells.Where(x => !x.IsTemporary).Min(x => x.Y));
                    if (targetCell.Type == CellTypes.Block)
                    {
                        targetCell = targetCell.GetTopWithType();
                    }
                }
            }
            return targetCell;
        }
Beispiel #11
0
 public void Reset()
 {
     foreach (Chuzzle selectedChuzzle in SelectedChuzzles)
     {
         selectedChuzzle.Tipping = false;
         selectedChuzzle.Teleportable.Hide();
     }
     SelectedChuzzles.Clear();
     CurrentChuzzle = null;
     _axisChozen = false;
     _isVerticalDrag = false;
     _isReturning = false;
 }
        public static void ShowArrow(Chuzzle from, IntVector2 to, TipArrow tipArrow)
        {
            //Debug.Log(string.Format("Arrow. From:{0} To:{1} ", from, to));
            if (@from.Current.X == to.x)
            {
                //vertical
                if (@from.Current.Y >= to.y)
                {
                    //to down
                    //do nothing
                    tipArrow.transform.rotation = Quaternion.Euler(0, 0, 0);
                }
                else
                {
                    //to up
                    //mirror vertical
                    tipArrow.transform.rotation = Quaternion.Euler(0, 0, 180);
                }
            }
            else
            {
                //horizontal
                if (@from.Current.X < to.x)
                {
                    //to right
                    tipArrow.transform.rotation = Quaternion.Euler(0, 0, 90);
                }
                else
                {
                    //to left
                    //to right
                    tipArrow.transform.rotation = Quaternion.Euler(0, 0, -90);
                }
            }

            tipArrow.Chuzzle = @from;
        }
        public static List<Chuzzle> RecursiveFind(Chuzzle chuzzle, List<Chuzzle> combination, IEnumerable<Chuzzle> chuzzles)
        {
            if (chuzzle == null || combination.Contains(chuzzle) || chuzzle.IsCheckedForSearch)
            {
                return new List<Chuzzle>();
            }
            combination.Add(chuzzle);
            chuzzle.IsCheckedForSearch = true;

            var left = GetLeftFor(chuzzle, chuzzles);
            if (left != null && IsSameColor(chuzzle, left))
            {
                var answer = RecursiveFind(left, combination, chuzzles);
                foreach (var a in answer)
                {
                    if (combination.Contains(a) == false)
                    {
                        combination.Add(a);
                    }
                }
            }

            var right = GetRightFor(chuzzle, chuzzles);
            if (right != null && IsSameColor(chuzzle, right))
            {
                var answer = RecursiveFind(right, combination, chuzzles);
                foreach (var a in answer)
                {
                    if (combination.Contains(a) == false)
                    {
                        combination.Add(a);
                    }
                }
            }

            var top = GetTopFor(chuzzle, chuzzles);
            if (top != null && IsSameColor(chuzzle,top))
            {
                var answer = RecursiveFind(top, combination, chuzzles);
                foreach (var a in answer)
                {
                    if (combination.Contains(a) == false)
                    {
                        combination.Add(a);
                    }
                }
            }

            var bottom = GetBottomFor(chuzzle, chuzzles);
            if (bottom != null && IsSameColor(chuzzle, bottom))
            {
                var answer = RecursiveFind(bottom, combination, chuzzles);
                foreach (var a in answer)
                {
                    if (combination.Contains(a) == false)
                    {
                        combination.Add(a);
                    }
                }
            }

            return combination;
        }
 public static bool IsUsual(Chuzzle chuzzle)
 {
     return chuzzle is ColorChuzzle;
 }
        public static bool IsSameColor(Chuzzle a, Chuzzle b)
        {
            if (a == null || b == null)
            {
                //Debug.LogError(String.Format("A or b is NULL. a: {0} b: {1}", a, b));
                return false;
            }

            if (a is InvaderChuzzle || b is InvaderChuzzle)
            {
                return false;
            }

            return a.Color == b.Color;
        }
 public static bool IsPowerUp(Chuzzle chuzzle)
 {
     return chuzzle is HorizontalLineChuzzle || chuzzle is VerticalLineChuzzle || chuzzle is BombChuzzle;
 }
 public static bool IsOrdinaryDestroyable(Chuzzle chuzzle)
 {
     return !(chuzzle is InvaderChuzzle);
 }
Beispiel #18
0
        public void OnPointerDown(Chuzzle chuzzle)
        {
            if (Gamefield.CurrentState != this)
                return;

            if (!IsWorking)
            {
                return;
            }

            if (_isReturning)
            {
                return;
            }

            CurrentChuzzle = chuzzle;
        }
Beispiel #19
0
        public void OnPointerUp(Chuzzle chuzzle)
        {
            if (Gamefield.CurrentState != this)
                return;

            DropDrag();
        }
        /// <summary>
        ///     Находит любую возможную комбинацию
        /// </summary>
        /// <param name="chuzzles">Список элементов в котором надо найти комбинацию</param>
        /// <returns>Список элементов которые составляют эту комбинацию</returns>
        public static List<Chuzzle> Tip(TilesCollection chuzzles, out IntVector2 isHorizontalMove, out Chuzzle chuzzleToMove)
        {
            var bottom =
                chuzzles.FirstOrDefault(
                                        x => BetweenYCheck(x, chuzzles));

            if (bottom != null && bottom.Current.Top != null && bottom.Current.Top.Type != CellTypes.Block)
            {
                var top = chuzzles.First(ch => ch.Current == bottom.Current.Top.Top);

                var bottomPart = RecursiveFind(bottom, new List<Chuzzle>(), chuzzles);
                var middlePart = GetHorizontalLineChuzzles(bottom.Current.Y + 1, bottom.Color, chuzzles);
                var topPart = RecursiveFind(top, new List<Chuzzle>(), chuzzles);

                var possibleCombination = new List<Chuzzle>();
                possibleCombination.AddRange(bottomPart);
                possibleCombination.AddRange(middlePart);
                possibleCombination.AddRange(topPart);

                //Debug.Log("Combination 1");
                isHorizontalMove = new IntVector2(bottom.Current.X, bottom.Current.Y + 1);
                chuzzleToMove = middlePart.First();
                //var target = possibleCombination.Aggregate("", (current, chuzzle) => current + (chuzzle + Environment.NewLine));
                //Debug.Log(target);
                return possibleCombination;
            }

            var left = chuzzles.FirstOrDefault(x => BetweenXCheck(x, chuzzles));

            if (left != null && left.Current.Right != null && left.Current.Right.Type != CellTypes.Block)
            {
                var right = chuzzles.First(ch => ch.Current == left.Current.Right.Right);

                var leftPart = RecursiveFind(left, new List<Chuzzle>(), chuzzles);
                var middlePart = GetVerticalLineChuzzles(left.Current.Right.X, left.Color, chuzzles);
                var rightPart = RecursiveFind(right, new List<Chuzzle>(), chuzzles);

                var possibleCombination = new List<Chuzzle>();
                possibleCombination.AddRange(leftPart);
                possibleCombination.AddRange(middlePart);
                possibleCombination.AddRange(rightPart);

                isHorizontalMove = new IntVector2(left.Current.X + 1, left.Current.Y);
                chuzzleToMove = middlePart.First();
                //Debug.Log("Combination 2: " + chuzzleToMove);
                //var target = possibleCombination.Aggregate("", (current, chuzzle) => current + (chuzzle + Environment.NewLine));
                //Debug.Log(target);
                return possibleCombination;
            }

            var combinations = FindCombinations(chuzzles, 2);

            foreach (var combination in combinations)
            {
                var first = combination[0];
                var second = combination[1];

                //vertical combination
                if (first.Current.X == second.Current.X)
                {
                    combination.Sort(CompareByY);
                    var topChuzzle = combination[0];
                    var bottomChuzzle = combination[1];
                    //try left
                    if ((topChuzzle.Current.Left != null && topChuzzle.Current.Left.Type != CellTypes.Block) ||
                        (bottomChuzzle.Current.Left != null && bottomChuzzle.Current.Left.Type != CellTypes.Block))
                    {
                        var leftPart = GetVerticalLineChuzzles(topChuzzle.Current.X - 1, topChuzzle.Color, chuzzles).ToList();
                        if (leftPart.Any())
                        {
                            var possibleCombination = new List<Chuzzle>();
                            possibleCombination.AddRange(combination);
                            possibleCombination.AddRange(leftPart);

                            //Debug.Log("Combination 3");
                            //var target = possibleCombination.Aggregate("", (current, chuzzle) => current + (chuzzle + Environment.NewLine));
                            //Debug.Log(target);
                            isHorizontalMove = new IntVector2(topChuzzle.Current.X - 1, topChuzzle.Current.Y);
                            chuzzleToMove = leftPart.First();
                            return possibleCombination;
                        }
                    }

                    //try right
                    if ((topChuzzle.Current.Right != null && topChuzzle.Current.Right.Type != CellTypes.Block) ||
                        (bottomChuzzle.Current.Right != null && bottomChuzzle.Current.Right.Type != CellTypes.Block))
                    {
                        var rightPart = GetVerticalLineChuzzles(topChuzzle.Current.X + 1, topChuzzle.Color, chuzzles).ToList();
                        if (rightPart.Any())
                        {
                            var possibleCombination = new List<Chuzzle>();
                            possibleCombination.AddRange(combination);
                            possibleCombination.AddRange(rightPart);

                            //Debug.Log("Combination 4");
                            //Svar target = possibleCombination.Aggregate("", (current, chuzzle) => current + (chuzzle + Environment.NewLine));
                            //Debug.Log(target);
                            isHorizontalMove = new IntVector2(topChuzzle.Current.X + 1, topChuzzle.Current.Y);
                            chuzzleToMove = rightPart.First();
                            return possibleCombination;
                        }
                    }

                    //try top
                    if (bottomChuzzle.Current.Top != null && bottomChuzzle.Current.Top.Type != CellTypes.Block &&
                        chuzzles.Any(x => x.Current == bottomChuzzle.Current.Top))
                    {
                        var topPart = GetHorizontalLineChuzzles(bottomChuzzle.Current.Top.Y, bottomChuzzle.Color, chuzzles).ToList();
                        if (topPart.Any())
                        {
                            var possibleCombination = new List<Chuzzle>();
                            possibleCombination.AddRange(combination);
                            possibleCombination.AddRange(topPart);

                            //Debug.Log("Combination 5");
                            //var target = possibleCombination.Aggregate("", (current, chuzzle) => current + (chuzzle + Environment.NewLine));
                            //Debug.Log(target);
                            isHorizontalMove = new IntVector2(bottomChuzzle.Current.X, bottomChuzzle.Current.Top.Y);
                            chuzzleToMove = topPart.First();
                            return possibleCombination;
                        }
                    }

                    //try bottom
                    if (topChuzzle.Current.Bottom != null && topChuzzle.Current.Bottom.Type != CellTypes.Block &&
                        chuzzles.Any(x => x.Current == topChuzzle.Current.Bottom))
                    {
                        var bottomPart = GetHorizontalLineChuzzles(topChuzzle.Current.Bottom.Y, topChuzzle.Color, chuzzles).ToList();
                        if (bottomPart.Any())
                        {
                            var possibleCombination = new List<Chuzzle>();
                            possibleCombination.AddRange(combination);
                            possibleCombination.AddRange(bottomPart);

                            //Debug.Log("Combination 6");
                            //var target = possibleCombination.Aggregate("", (current, chuzzle) => current + (chuzzle + Environment.NewLine));
                            //Debug.Log(target);
                            isHorizontalMove = new IntVector2(bottomChuzzle.Current.X, bottomChuzzle.Current.Bottom.Y);
                            chuzzleToMove = bottomPart.First();
                            return possibleCombination;
                        }
                    }
                }
                else
                {
                    combination.Sort(CompareByX);
                    var leftChuzzle = combination[0];
                    var rightChuzzle = combination[1];
                    //horizontal combinations

                    //try left
                    if (leftChuzzle.Current.Left != null && leftChuzzle.Current.Left.Type != CellTypes.Block)
                    {
                        var leftPart = GetVerticalLineChuzzles(leftChuzzle.Current.Left.X, leftChuzzle.Color, chuzzles).ToList();
                        if (leftPart.Any())
                        {
                            var possibleCombination = new List<Chuzzle>();
                            possibleCombination.AddRange(combination);
                            possibleCombination.AddRange(leftPart);

                            //  //Debug.Log("Left:"+leftChuzzle);
                            //  //Debug.Log("Right:"+rightChuzzle.ToString());

                            //Debug.Log("Combination 7");
                            //var target = possibleCombination.Aggregate("", (current, chuzzle) => current + (chuzzle + Environment.NewLine));
                            //Debug.Log(target);
                            isHorizontalMove = new IntVector2(leftChuzzle.Current.Left.X, leftChuzzle.Current.Y);
                            chuzzleToMove = leftPart.First();
                            return possibleCombination;
                        }
                    }

                    //try right
                    if (rightChuzzle.Current.Right != null && rightChuzzle.Current.Right.Type != CellTypes.Block)
                    {
                        var rightPart = GetVerticalLineChuzzles(rightChuzzle.Current.X + 1, rightChuzzle.Color, chuzzles).ToList();
                        if (rightPart.Any())
                        {
                            var possibleCombination = new List<Chuzzle>();
                            possibleCombination.AddRange(combination);
                            possibleCombination.AddRange(rightPart);

                            //Debug.Log("Combination 8");
                            //var target = possibleCombination.Aggregate("", (current, chuzzle) => current + (chuzzle + Environment.NewLine));
                            //Debug.Log(target);
                            isHorizontalMove = new IntVector2(rightChuzzle.Current.X + 1, rightChuzzle.Current.Y);
                            chuzzleToMove = rightPart.First();
                            return possibleCombination;
                        }
                    }

                    //try top
                    if (
                        (leftChuzzle.Current.Top != null && leftChuzzle.Current.Top.Type != CellTypes.Block &&
                         chuzzles.Any(x => x.Current == leftChuzzle.Current.Top)) ||
                        (rightChuzzle.Current.Top != null && rightChuzzle.Current.Top.Type != CellTypes.Block &&
                         chuzzles.Any(x => x.Current == rightChuzzle.Current.Top))
                        )
                    {
                        var topPart = GetHorizontalLineChuzzles(rightChuzzle.Current.Y + 1, rightChuzzle.Color, chuzzles).ToList();
                        if (topPart.Any())
                        {
                            var possibleCombination = new List<Chuzzle>();
                            possibleCombination.AddRange(combination);
                            possibleCombination.AddRange(topPart);

                            //Debug.Log("Combination 9");
                            //var target = possibleCombination.Aggregate("", (current, chuzzle) => current + (chuzzle + Environment.NewLine));
                            //Debug.Log(target);
                            isHorizontalMove = new IntVector2(rightChuzzle.Current.X, rightChuzzle.Current.Y + 1);
                            chuzzleToMove = topPart.First();
                            return possibleCombination;
                        }
                    }

                    //try bottom
                    if (
                        (leftChuzzle.Current.Bottom != null && leftChuzzle.Current.Bottom.Type != CellTypes.Block &&
                         chuzzles.Any(x => x.Current == leftChuzzle.Current.Bottom)) ||
                        (rightChuzzle.Current.Bottom != null && rightChuzzle.Current.Bottom.Type != CellTypes.Block &&
                         chuzzles.Any(x => x.Current == rightChuzzle.Current.Bottom))
                        )
                    {
                        var bottomPart = GetHorizontalLineChuzzles(leftChuzzle.Current.Y - 1, leftChuzzle.Color, chuzzles).ToList();
                        if (bottomPart.Any())
                        {
                            var possibleCombination = new List<Chuzzle>();
                            possibleCombination.AddRange(combination);
                            possibleCombination.AddRange(bottomPart);

                            //Debug.Log("Combination 10");
                            //var target = possibleCombination.Aggregate("", (current, chuzzle) => current + (chuzzle + Environment.NewLine));
                            //Debug.Log(target);
                            isHorizontalMove = new IntVector2(leftChuzzle.Current.X, leftChuzzle.Current.Y - 1);
                            chuzzleToMove = bottomPart.First();
                            return possibleCombination;
                        }
                    }
                }
            }
            //Debug.Log("Combination NOOOOOOOOOO 11");
            Repaint(chuzzles,100);
            Tip(chuzzles, out isHorizontalMove, out chuzzleToMove);

            isHorizontalMove = new IntVector2();
            chuzzleToMove = null;
            return new List<Chuzzle>();
        }
Beispiel #21
0
 private static Cell GetRightCell(IEnumerable<Cell> activeCells, Cell targetCell, Chuzzle c)
 {
     //if border
     if (targetCell == null)
     {
         targetCell = GamefieldUtility.CellAt(activeCells, activeCells.Min(x => x.X), c.Current.Y);
         if (targetCell.Type == CellTypes.Block)
         {
             targetCell = targetCell.GetRightWithType();
         }
     }
     else
     {
         targetCell = targetCell.GetRightWithType();
         if (targetCell == null)
         {
             targetCell = GamefieldUtility.CellAt(activeCells, activeCells.Min(x => x.X),
                 c.Current.Y);
             if (targetCell.Type == CellTypes.Block)
             {
                 targetCell = targetCell.GetRightWithType();
             }
         }
     }
     return targetCell;
 }
        public static int CompareByX(Chuzzle first, Chuzzle second)
        {
            if (first.Current.X == second.Current.X)
            {
                return 0;
            }

            return first.Current.X > second.Current.X ? 1 : -1;
        }
Beispiel #23
0
        private void CheckPossibleCombinations()
        {
            _targetPosition = null;
            _arrowChuzzle = null;
            int numberOfTries = 0;
            do
            {
                if (GamefieldUtility.Repaint(Gamefield.Level.Chuzzles, numberOfTries)) break;

                _possibleCombination = GamefieldUtility.Tip(Gamefield.Level.Chuzzles, out _targetPosition,
                    out _arrowChuzzle);
                // Debug.Log(string.Format("Tip. From: {0} To: {1}", _arrowChuzzle, _targetPosition));
                numberOfTries++;
            } while (!_possibleCombination.Any());
        }
Beispiel #24
0
 public void MoveTo(Chuzzle chuzzle, Vector3 from, Vector3 to, float time = 0.3f)
 {
     Moves.Add(MoveDesc.Create(chuzzle, from, to));
     AnimateMoveTo(chuzzle, to, time);
 }
Beispiel #25
0
 public void OnPointerUp(Chuzzle chuzzle)
 {
     FieldState.OnPointerUp(chuzzle);
 }
 public static Chuzzle GetTopFor(Chuzzle c, IEnumerable<Chuzzle> chuzzles)
 {
     return chuzzles.FirstOrDefault(x => x.Real == c.Real.Top);
 }
 public static IntVector2 ToRealCoordinates(Chuzzle chuzzle)
 {
     return new IntVector2(Mathf.RoundToInt(chuzzle.transform.position.x/Chuzzle.Scale.x),
                           Mathf.RoundToInt(chuzzle.transform.position.y/Chuzzle.Scale.y));
 }
 public static bool IsCounter(Chuzzle chuzzle)
 {
     return chuzzle is CounterChuzzle;
 }
Beispiel #29
0
 public void ReplaceWithColor(Chuzzle toReplace, ChuzzleColor color)
 {
     CreateChuzzle(toReplace.Current, color);
     toReplace.Destroy(false, false, true);
 }
        public static int CompareByY(Chuzzle first, Chuzzle second)
        {
            if (first.Current.Y == second.Current.Y)
            {
                return 0;
            }

            return first.Current.Y > second.Current.Y ? 1 : -1;
        }