Ejemplo n.º 1
0
        //evento di fine drag
        public void OnEndDrag(PointerEventData eventData)
        {
            if (GameManager.singleton.hand.drag)
            {
                List <Card> cardsDragged = new List <Card>(GameManager.singleton.hand.cards);
                CommandList commands     = new CommandList();
                foreach (Card card in cardsDragged)
                {
                    card.canvasGroup.blocksRaycasts = true;
                }
                bool newZone = prevZone != parentZone;
                //comando di movimento delle carte da dove si trovano alla nuova zona impostata nel parent dall'evento di drop della zone
                Move move = new Move(cardsDragged, prevZone, parentZone, true, newZone, newZone);
                commands.AddCommand(move);
                //se sto spostando da una colonna e l'ultima carta è coperta, la giro
                if (newZone && prevZone is ColumnZone && prevZone.cards.Count > 0)
                {
                    Card lastCard = prevZone.cards[prevZone.cards.Count - 1];
                    if (!lastCard.frontSide)
                    {
                        Flip flip = new Flip(lastCard, true);
                        commands.AddCommand(flip);
                    }
                }

                GameManager.singleton.hand.drag = false;
                GameManager.singleton.commandListQueue.Enqueue(commands);
            }
        }
Ejemplo n.º 2
0
        void PlaceStartingCardsInColumn()
        {
            bool sortCard = false;

            foreach (ColumnZone column in columnZones)
            {
                if (column.startingCards > column.cards.Count)
                {
                    sortCard = true;
                    Card card = deckZone.cards[deckZone.cards.Count - 1];
                    card.parentZone = column;
                    Move        move     = new Move(card, card.prevZone, card.parentZone, true, true, false);
                    CommandList commands = new CommandList();
                    commands.AddCommand(move);
                    commands.undo = false;
                    commandListQueue.Enqueue(commands);
                    //se è l'ultima carta, la giro
                    if (column.startingCards == column.cards.Count + 1)
                    {
                        Flip        flip      = new Flip(card, true);
                        CommandList commands2 = new CommandList();
                        commands2.AddCommand(flip);
                        commands2.undo = false;
                        commandListQueue.Enqueue(commands2);
                    }
                    break;
                }
            }
            startGame = sortCard;
        }
Ejemplo n.º 3
0
        void ShuffleCardsInDeck()
        {
            List <Card> deck    = new List <Card>(ObjectPool.singleton.cards);
            List <Card> shuffle = new List <Card>();

            //ricavo la lista di carte ordinata casualmente da inserire nel mazzo
            while (deck.Count > 0)
            {
                int  index = UnityEngine.Random.Range(0, deck.Count);
                Card card  = deck[index];
                card.parentZone = deckZone;
                shuffle.Add(card);
                deck.RemoveAt(index);
            }
            gameState.startingShuffle = shuffle;
            //muovo le carte nel mazzo
            Move move = new Move(shuffle, null, deckZone, true, false, false);
            //giro le carte a faccia coperta
            Flip        flip     = new Flip(shuffle, false);
            CommandList commands = new CommandList();

            commands.AddCommand(move);
            commands.AddCommand(flip);
            commands.undo = false;
            commandListQueue.Enqueue(commands);
        }
Ejemplo n.º 4
0
        public void AutoMove(Card card)
        {
            //posizione direttamente la carta nella zona corretta, dando priorità ai segni e poi alle colonne
            if (card.parentZone is DrawZone || card.parentZone is ColumnZone)
            {
                foreach (SuitZone suit in suitZones)
                {
                    if (suit.CheckValidDrop(card, suit.cards.Count - 1))
                    {
                        card.prevZone   = card.parentZone;
                        card.parentZone = suit;
                        Move        move     = new Move(card, card.prevZone, card.parentZone, true, true, true);
                        CommandList commands = new CommandList();
                        commands.AddCommand(move);
                        commands.undo = true;
                        //se la muovo dalla colonne e c'è una carta coperta, la giro
                        if (card.prevZone is ColumnZone && card.prevZone.cards.Count > 1)
                        {
                            Card lastCard = card.prevZone.cards[card.prevZone.cards.Count - 2];
                            if (!lastCard.frontSide)
                            {
                                Flip flip = new Flip(lastCard, true);
                                commands.AddCommand(flip);
                            }
                        }

                        commandListQueue.Enqueue(commands);
                        return;
                    }
                }
            }
            if (card.parentZone is DrawZone)
            {
                foreach (ColumnZone column in columnZones)
                {
                    if (column.CheckValidDrop(card, column.cards.Count - 1))
                    {
                        card.prevZone   = card.parentZone;
                        card.parentZone = column;
                        Move        move     = new Move(card, card.prevZone, card.parentZone, true, true, true);
                        CommandList commands = new CommandList();
                        commands.AddCommand(move);
                        commands.undo = true;
                        commandListQueue.Enqueue(commands);
                        return;
                    }
                }
            }
        }
Ejemplo n.º 5
0
        //se non ci sono più carte, recupero quelle dalla discard e draw zone, le giro e le riposizione in ordine contrario nel deck
        public void OnPointerClick(PointerEventData eventData)
        {
            List <Card> cards = new List <Card>(GameManager.singleton.discardZone.cards);

            foreach (Card card in GameManager.singleton.drawZone.cards)
            {
                cards.Add(card);
            }
            cards.Reverse();
            Move        move     = new Move(cards, GameManager.singleton.discardZone, this, true, false, false);
            Flip        flip     = new Flip(cards, false);
            CommandList commands = new CommandList();

            commands.AddCommand(move);
            commands.AddCommand(flip);
            commands.undo = false;
            GameManager.singleton.commandListQueue.Enqueue(commands);
        }
Ejemplo n.º 6
0
        public void OnPointerClick(PointerEventData eventData)
        {
            //se clicco una carta nel mazzo, la sposto nella zona di draw
            if (parentZone is DeckZone && GameManager.singleton.drawZone.cards.Count <= 3)
            {
                //a seconda dell'opzione draw3 pesco una o tre carte
                int cardNumber = (SessionManager.singleton.options.draw3) ? 3 : 1;
                if (cardNumber > GameManager.singleton.deckZone.cards.Count)
                {
                    cardNumber = GameManager.singleton.deckZone.cards.Count;
                }

                for (int i = 0; i < cardNumber; i++)
                {
                    Card card = GameManager.singleton.deckZone.cards[(GameManager.singleton.deckZone.cards.Count - 1) - i];
                    card.prevZone   = card.parentZone;
                    card.parentZone = GameManager.singleton.drawZone;
                    //sposto la carta nella zona di draw
                    Move move = new Move(card, card.prevZone, card.parentZone, true, true, true);
                    //giro la carta
                    Flip        flip     = new Flip(card, true);
                    CommandList commands = new CommandList();
                    commands.AddCommand(move);
                    commands.AddCommand(flip);
                    GameManager.singleton.commandListQueue.Enqueue(commands);
                }
            }
            //se doppio click su una carta, la sposto automaticamente nella zona corretta
            if (Time.time - lastClickTime < doubleClickTime)
            {
                if (parentZone.cards.IndexOf(this) == parentZone.cards.Count - 1)
                {
                    GameManager.singleton.AutoMove(this);
                }
            }
            lastClickTime = Time.time;
        }