예제 #1
0
        private void Item_PlayerWantToChooseThisItem(Item item)
        {
            LastTimePlayerInterract = PlayTime;

            int count = PlayerChosenItems.Count;

            if (count == 0)
            {
                PlayerChooseRight();
                return;
            }

            Item lastItem = PlayerChosenItems[count - 1];

            // Sẽ kiểm tra 2 thứ:
            // 1. Là Id phải trùng nhau
            // 2. Là tọa độ phải gần nhau (tổng chênh lệch x+y không lớn hơn 1)

            if (!IsTheSameId(item, lastItem))
            {
                PlayerChooseWrong();
                return;
            }

            if (!IsItemsNearBy(item, lastItem))
            {
                PlayerChooseWrong();
                return;
            }

            PlayerChooseRight();

            void PlayerChooseWrong()
            {
                Item.ReleaseAll();
                item.UnChooseThisItem();
                PlayerChosenItems.ForEach(x => x.UnChooseThisItem());
                PlayerChosenItems.Clear();
                ScoreCalculator.Instance.LoseBonus();
            }

            void PlayerChooseRight()
            {
                PlayerChosenItems.Add(item);
                item.ChooseThisItem();
            }
        }