Beispiel #1
0
        /// <summary>
        /// Sorts the card by their suit
        /// </summary>
        /// <param name="pile"></param>
        /// <returns></returns>
        public static Pile SortBySuit(Pile pile)
        {
            System.Collections.ArrayList newHand = new System.Collections.ArrayList();

            System.Collections.ArrayList CardPile = (System.Collections.ArrayList)pile.CardPile;


            while (CardPile.Count > 0)
            {
                int        pos           = 0;                       // Position of minimal card.
                SpadesCard minSpadescard = (SpadesCard)CardPile[0]; // Minimal card.
                int        mincard       = (int)minSpadescard.CardIndex;
                for (int i = 1; i < CardPile.Count; i++)
                {
                    SpadesCard nextSpadescard = (SpadesCard)CardPile[i];
                    int        nextcard       = nextSpadescard.CardIndex;
                    if (Card.SuitFromCardIndex(nextcard) < Card.SuitFromCardIndex(mincard)
                        ||
                        (Card.SuitFromCardIndex(nextcard) == Card.SuitFromCardIndex(mincard) && Card.RankFromCardIndex(nextcard) < Card.RankFromCardIndex(mincard))
                        )
                    {
                        pos           = i;
                        mincard       = nextcard;
                        minSpadescard = nextSpadescard;
                    }
                }
                CardPile.RemoveAt(pos);
                newHand.Add(minSpadescard);
            }
            CardPile      = newHand;
            pile.CardPile = CardPile;

            return(pile);
        }
        private static Pile GetNewCardsPack(eCardColor[] colors, eCardValue[] values)
        {
            var pile = new Pile();

            for (int i = 0; i < colors.Length; i++)
            {
                for (int j = 0; j < values.Length; j++)
                {
                    var value = values[j];
                    var color = colors[i];
                    pile.Add(new Card(value, color));
                }
            }

            return(pile);
        }
Beispiel #3
0
        /// <summary>
        /// shuffles the card pile
        /// </summary>
        /// <param name="pile">Pile of card to shuffle</param>
        /// <returns></returns>

        public static Pile ShufflePile(Pile pile)
        {
            System.Collections.ArrayList CardPile = (System.Collections.ArrayList)pile.CardPile;

            if (CardPile.Count > 0)
            {
                //shuffle the cards
                System.Collections.ArrayList newArray = new System.Collections.ArrayList();
                bool[] used = new bool[CardPile.Count];

                for (int j = 0; j < CardPile.Count; j++)
                {
                    used[j] = false;
                }

                int seed = DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second + DateTime.Now.Millisecond;

                Random rnd    = new Random(seed);
                int    iCount = 0;
                int    iNum;

                while (iCount < CardPile.Count)
                {
                    iNum = rnd.Next(0, CardPile.Count); // between 0 and 51

                    if (used[iNum] == false)
                    {
                        newArray.Add(CardPile[iNum]);
                        used[iNum] = true;
                        iCount++;
                    }
                }
                // End of Shuffle Routine

                // Load original array with shuffled array
                CardPile = newArray;
            }

            pile.CardPile = CardPile;
            return(pile);
        }
Beispiel #4
0
        public void RayCast2DTrigger()
        {
            if (!Game.Ctx.BattleOperator.player.waitingForAction)
            {
                return;
            }
            if (!availability)
            {
                return;
            }
            if (!isDragged && !Game.Ctx.VfxOperator.draggedCard)
            {
                if (!GetComponent <CardRender>().visible)
                {
                    return;
                }

                if (Game.Ctx.BattleOperator.inSelectEnemyMode)
                {
                    return;
                }

                thisPile = Game.Ctx.CardOperator.GetCardPile(GetComponent <Card>());

                if (!thisPile.movable)
                {
                    return;
                }

                _cursorShift = transform.position - Camera.main.ScreenToWorldPoint(Input.mousePosition);
                _cursorShift = new Vector3(0f, 0f, _cursorShift.z);

                Game.Ctx.VfxOperator.draggedCard = GetComponent <Card>();
                GetComponent <CardRender>().SetOrder();

                if (thisPile == Game.Ctx.CardOperator.pileHand)
                {
                    Game.Ctx.CardOperator.pileHand.VirtualInitialize();
                }

                isDragged = true;
                GetComponent <CardRender>().OnSelectZoom();
            }
            else if (isDragged)
            {
                Card card = GetComponent <Card>();

                // thisPile == Game.Ctx.CardOperator.pileHand could also work

                if (thisPile.gameObject.name == "HandPile" && triggerPlayArea)
                {
                    Game.Ctx.CardOperator.AddCardToQueue(card);
                }
                else if (thisPile.gameObject.name == "PlayPile" && triggerHandArea)
                {
                    Game.Ctx.CardOperator.RemoveCardAndAfterFromQueue(card);
                }
                else
                {
                    if (thisPile.movable)
                    {
                        thisPile.AdjustAllPositions();
                    }
                }

                Game.Ctx.CardOperator.pileHand.VirtualDestroy(true);
                Game.Ctx.VfxOperator.draggedCard = null;

                thisPile  = null;
                isDragged = false;

                Game.Ctx.VfxOperator.ChangeMultiplierText(true, Game.Ctx.CardOperator.pilePlay.Count());
            }
        }