コード例 #1
0
 public Card GetChip()
 {
     if (slotForChip)
     {
         return(slotForChip.GetCard());
     }
     return(null);
 }
コード例 #2
0
ファイル: SlotGravity.cs プロジェクト: nick-yangzj/MyMatch1
        // Gravity iteration
        public void  GravityReaction()
        {
            if (!SessionControl.Instance.CanIGravity())
            {
                return;                                                     // Work is possible only in "Gravity" mode
            }
            chip = slotForChip.GetCard();

            if (chip == null)
            {
                return;                           // Work is possible only with the chips, otherwise nothing will move
            }
            if (!chip.can_move)
            {
                return;
            }

            if (chip == null || slot.transform.position != chip.transform.position)
            {
                return;                                                                                 // Work is possible only if the chip is physically clearly in the slot
            }
            if (slot[gravityDirection] == null ||
                !slot[gravityDirection].gravity)
            {
                return;                 // Work is possible only if there is another bottom slot
            }
            // provided that bottom neighbor doesn't contains chip, give him our chip
            if (slot[gravityDirection].GetChip() == null)
            {
                slot[gravityDirection].SetChipTemp(chip);
                GravityReaction();
                return;
            }

            // Otherwise, we try to give it to their neighbors from the bottom-left and bottom-right side
            if (Random.value > 0.5f)               // Direction priority is random
            {
                SlideLeft();
                SlideRight();
            }
            else
            {
                SlideRight();
                SlideLeft();
            }
        }