Esempio n. 1
0
        // Function immediate swapping 2 chips
        public void SwapTwoItemNow(Card a, Card b)
        {
            if (!a || !b)
            {
                return;
            }
            if (a == b)
            {
                return;
            }
            if (a.parentSlot.slot.Block || b.parentSlot.slot.Block)
            {
                return;
            }

            //Vector3 posA = a.parentSlot.transform.position;
            //Vector3 posB = b.parentSlot.transform.position;

            //a.transform.position = posB;
            //b.transform.position = posA;

            a.movementID = SessionControl.Instance.GetMovementID();
            b.movementID = SessionControl.Instance.GetMovementID();

            SlotForCard slotA = a.parentSlot;
            SlotForCard slotB = b.parentSlot;

            slotB.SetChip(a);
            slotA.SetChip(b);
        }
Esempio n. 2
0
        // Make a bomb in the specified location with the ability to transform simple chips in a bomb
        public Card AddPowerup(int x, int y, SessionControl.PowerUps powerup)
        {
            SlotForCard slot = SlotManager.Instance.FindSlot(x, y).GetComponent <SlotForCard>();
            Card        chip = slot.card;
            int         id;

            if (chip)
            {
                id = chip.id;
            }
            else
            {
                id = Random.Range(0, LevelProfile.CurrentLevelProfile.CardCount);
            }

            if (chip)
            {
//				DebugUtil.Debug("destroy card:" + chip.gameObject.name);
                if (chip.move)
                {
                    chip.gravity = false;
                }

                Destroy(chip.gameObject);
            }

            chip = GetNewBomb(slot.slot.Row, slot.slot.Col, powerup, slot.transform.position, id);
            return(chip);
        }
Esempio n. 3
0
        // separation of the chips from the parent slot
        public void  ParentRemove()
        {
            if (!parentSlot)
            {
                return;
            }

            parentSlot.card = null;
            parentSlot      = null;
        }
Esempio n. 4
0
 void  Awake()
 {
     slotForChip  = GetComponent <SlotForCard>();
     slotGravity  = GetComponent <SlotGravity>();
     slotTeleport = GetComponent <SlotTeleport>();
 }
Esempio n. 5
0
 public void SetSlot(Slot slot)
 {
     this.Slot             = slot;
     this.Slot.IsGenerator = true;
     slotForChip           = GetComponent <SlotForCard>();
 }
Esempio n. 6
0
 void Awake()
 {
     Slot             = GetComponent <Slot>();
     Slot.IsGenerator = true;
     slotForChip      = GetComponent <SlotForCard>();
 }
Esempio n. 7
0
//		public SlotGravity(Slot slot,Side gravityDirection)
//		{
//			this.slot = slot;
//			this.gravityDirection = gravityDirection;
//		}

        void  Awake()
        {
            slot        = GetComponent <Slot>();
            slotForChip = GetComponent <SlotForCard>();
        }
Esempio n. 8
0
        // Coroutine swapping 2 chips
        IEnumerator SwapTwoItemRoutine(Card a, Card b, bool force)
        {
            if (!Iteraction)
            {
                a.SetBorder(false);
                b.SetBorder(false);
                yield break;
            }

            // cancellation terms
            if (swaping)
            {
                a.SetBorder(false);
                b.SetBorder(false);
                yield break;                 // If the process is already running
            }

            if (!a || !b)
            {
                if (a)
                {
                    a.SetBorder(false);
                }

                if (b)
                {
                    b.SetBorder(false);
                }

                yield break;                 // If one of the chips is missing
            }

            if (a.destroying || b.destroying)
            {
                a.SetBorder(false);
                b.SetBorder(false);

                yield break;
            }

            if (a.parentSlot.slot.Block != null || b.parentSlot.slot.Block != null)
            {
                a.SetBorder(false);
                b.SetBorder(false);

                yield break;                 // If one of the chips is blocked
            }

            if (!SessionControl.Instance.CanIAnimate())
            {
                a.SetBorder(false);
                b.SetBorder(false);

                yield break;                 // If the core prohibits animation
            }

            if (SessionControl.Instance.movesCount <= 0)
            {
                a.SetBorder(false);
                b.SetBorder(false);

                FightControl.Instance.ShowMsg(FightDefine.E_NoteMsgType.NoMoves);
                yield break;                 // If not enough moves
            }
            if (SessionControl.Instance.timeLeft <= 0)
            {
                a.SetBorder(false);
                b.SetBorder(false);

                yield break;                 // If not enough time
            }


            SessionControl.Mix mix = SessionControl.Instance.mixes.Find(x => x.Compare(a.chipType, b.chipType));

            int move = 0;             // Number of points movement which will be expend

            SessionControl.Instance.animate++;
            swaping = true;

            Vector3 posA = a.parentSlot.transform.position;
            Vector3 posB = b.parentSlot.transform.position;

            float progress = 0;

            Vector3 normal = a.parentSlot.slot.Row == b.parentSlot.slot.Row ? Vector3.right : Vector3.up;
            float   time   = 0;

            // Animation swapping 2 chips
            while (progress < swapDuration)
            {
                if (a == null || b == null)
                {
                    SessionControl.Instance.animate--;
                    swaping = false;

                    if (a)
                    {
                        a.SetBorder(false);
                    }

                    if (b)
                    {
                        b.SetBorder(false);
                    }

                    yield break;
                }

                time = EasingFunctions.easeInOutQuad(progress / swapDuration);
                a.transform.position = Vector3.Lerp(posA, posB, time) + normal * Mathf.Sin(3.14f * time) * 0.05f;
                if (mix == null)
                {
                    b.transform.position = Vector3.Lerp(posB, posA, time) - normal * Mathf.Sin(3.14f * time) * 0.05f;
                }

                progress += Time.deltaTime;

                yield return(0);
            }

            a.transform.position = posB;
            if (SessionControl.Instance.movesCount <= 0 || mix == null)
            {
                b.transform.position = posA;
            }

            a.movementID = SessionControl.Instance.GetMovementID();
            b.movementID = SessionControl.Instance.GetMovementID();

            if (SessionControl.Instance.movesCount > 0 && mix != null)
            {             // Scenario mix effect
                swaping = false;
                SessionControl.Instance.MixChips(a, b);
                a.SetBorder(false);
                b.SetBorder(false);

                yield return(new WaitForSeconds(0.3f));

                SessionControl.Instance.movesCount--;
                SessionControl.Instance.animate--;



                SessionControl.Instance.SuccessMoveCounter();
                yield break;
            }

            // Scenario the effect of swapping two chips
            SlotForCard slotA = a.parentSlot;
            SlotForCard slotB = b.parentSlot;

            slotB.SetChip(a);
            slotA.SetChip(b);

            move++;

            // searching for solutions of matching
            int count = 0;

            SessionControl.Solution solution;

            //todo yangzj
            solution = slotA.MatchAnaliz(false);
            if (solution != null)
            {
                count += solution.count;
            }

//			solution = slotA.MatchSquareAnaliz();
//			if (solution != null) count += solution.count;

            solution = slotB.MatchAnaliz(false);
            if (solution != null)
            {
                count += solution.count;
            }

//			solution = slotB.MatchSquareAnaliz();
//			if (solution != null) count += solution.count;

            // Scenario canceling of changing places of chips
            if (SessionControl.Instance.movesCount <= 0 || (count == 0 && !force))
            {
                if (SessionControl.Instance.movesCount <= 0)
                {
                    //显示不能移动提示
                    FightControl.Instance.ShowMsg(FightDefine.E_NoteMsgType.NoMoves);
                }

//				AudioAssistant.Shot("SwapFailed");
                while (progress > 0)
                {
                    time = EasingFunctions.easeInOutQuad(progress / swapDuration);
                    a.transform.position = Vector3.Lerp(posA, posB, time) - normal * Mathf.Sin(3.14f * time) * 0.05f;
                    b.transform.position = Vector3.Lerp(posB, posA, time) + normal * Mathf.Sin(3.14f * time) * 0.05f;

                    progress -= Time.deltaTime;

                    yield return(0);
                }

                a.transform.position = posA;
                b.transform.position = posB;

                a.movementID = SessionControl.Instance.GetMovementID();
                b.movementID = SessionControl.Instance.GetMovementID();

                slotB.SetChip(b);
                slotA.SetChip(a);

                a.transform.Find("Border").gameObject.SetActive(false);
                b.transform.Find("Border").gameObject.SetActive(false);

                move--;
            }
            else
            {
//				AudioAssistant.Shot("SwapSuccess");
                SessionControl.Instance.swapEvent++;

                SessionControl.Instance.SuccessMoveCounter();
            }

//			SessionControl.Instance.firstChipGeneration = false;

            SessionControl.Instance.movesCount -= move;
            SessionControl.Instance.EventCounter();

            SessionControl.Instance.animate--;

            a.SetBorder(false);
            b.SetBorder(false);

            swaping = false;
        }