コード例 #1
0
ファイル: Deck.cs プロジェクト: d4got10/CardGame
        IEnumerator StartGameCoroutine(int suitsCount)
        {
            _type = (GameSuitsCount)suitsCount;
            CreateDeck();
            var setup = _gameRuler.GetPlaceHoldersCardCountSetup();

            int sum = 0;

            foreach (int a in setup)
            {
                sum += a;
            }

            while (sum > 0)
            {
                for (int i = 0; i < setup.Length; i++)
                {
                    if (setup[i] > 0)
                    {
                        sum--;
                        setup[i]--;
                        Card card = Cards[0];
                        if (setup[i] == 0 || _allOpen)
                        {
                            card.Open();
                        }
                        _holders[i].ForcedStack(card);
                        Cards.RemoveAt(0);
                        yield return(new WaitForSeconds(_timeDelay));
                    }
                }
            }

            yield return(new WaitForSeconds(1));

            OnHasStartedGame.Invoke();
            HasStartedGame = true;

            if (Cards.Count == 0)
            {
                Destroy(gameObject);
            }
        }
コード例 #2
0
ファイル: Deck.cs プロジェクト: d4got10/CardGame
        public virtual void AddCards()
        {
            if (!HasStartedGame)
            {
                return;
            }

            bool eachIsNotEmpty = true;

            for (int i = 0; i < _holders.Length; i++)
            {
                if (_holders[i].StackedCard == null)
                {
                    eachIsNotEmpty = false;
                }
            }

            if (eachIsNotEmpty)
            {
                for (int i = 0; i < _holders.Length; i++)
                {
                    if (Cards.Count > 0)
                    {
                        Card card = Cards[0];
                        card.Open();
                        _holders[i].ForcedStack(card);
                        Cards.RemoveAt(0);
                    }
                }
            }

            if (Cards.Count == 0)
            {
                Destroy(gameObject);
            }
        }