Beispiel #1
0
        private void CreateCardPile(int _dispX, int _dispY)
        {
            Entity oneCardPile = CreateGameEntity(new Vector2(_dispX, _dispY));

            oneCardPile.Tag = 80;
            oneCardPile.Add <PileDispComponent>();
            //BoxCollider bx = new BoxCollider(new Rectangle(0, 0, 75, 100));
            //oneCardPile.Add(bx);

            CardPileComponent cp = new CardPileComponent()
            {
                PileID = 0, CName = "DrawDisp", FannedDirection = 1
            };

            cp.CardsInPile.Clear();
            //
            // deal out 13 cards
            //
            for (int i = 0; i < 13; i++)
            {
                Entity card = CardDeck.DealACard(_enabled: true);     //enabled & faceup
                cp.CardsInPile.Add(card);
            }


            oneCardPile.Add(cp);
        }
Beispiel #2
0
        public void Card2Drag(Entity _entity)
        {
            CardPileComponent scDrag = DragDisp.GetComponent <CardPileComponent>();
            CardPileComponent scTemp = _entity.GetComponent <CardPileComponent>();

            if (scTemp == null)
            {
                return;         //not a Pile entity
            }
            if (scTemp.CardsInPile.Count == 0)
            {
                return;
            }

            Entity lastCardonPile = scTemp.CardsInPile.LastOrDefault();               //get last card

            scTemp.CardsInPile.Remove(lastCardonPile);

            Card lastCard = lastCardonPile.GetComponent <Card>();

            lastCard.IsFaceUp = true;


            scDrag.CardsInPile.Add(lastCardonPile);
            DragComponent sdc = new DragComponent()
            {
                EntityOrig = _entity
            };

            DragDisp.AddComponent <DragComponent>(sdc);
        }
Beispiel #3
0
        public void DragStackClear()
        {
            DragDisp.RemoveComponent <DragComponent>();
            CardPileComponent sc = DragDisp.GetComponent <CardPileComponent>();

            sc.CardsInPile.Clear();
        }
Beispiel #4
0
        private void DealCardsToPiles()
        {
            //
            // Card deck is created, shuffle it
            //
            CardDeck.Shuffle();
            CardPileComponent scDisp = DrawDisp.Get <CardPileComponent>();

            scDisp.CardsInPile.Clear();
            //
            // Play Stack 0 gets 1 card
            // Play Stack 1 gets 2 cards
            // .....
            // Play Stack 6 gets 7 cards
            //
            for (int i = 0; i < PlayStacks.Count; i++)
            {
                CardPileComponent sc = PlayStacks[i].GetComponent <CardPileComponent>();
                sc.CardsInPile.Clear();
                for (int j = 0; i >= j; j++)
                {
                    //
                    // Create a card Enitty (face down)
                    //
                    Entity card  = CardDeck.DealACard(false, false);
                    var    ccomp = card.GetComponent <Card>();
                    ccomp.CardStack   = sc.PileID;
                    ccomp.HoldingPile = sc;
                    sc.CardsInPile.Add(card);
                }
                //
                // Find last card in this stack and flip it face up
                //
                CardPileComponent scTemp          = PlayStacks[i].GetComponent <CardPileComponent>();
                Entity            lastCardonStack = scTemp.CardsInPile.LastOrDefault(); //get last card
                var ccompTemp = lastCardonStack.GetComponent <Card>();                  //turn it face up
                ccompTemp.IsFaceUp = true;
            }
            //
            // Deal Pile gets rest of cards (24 of them)
            //
            CardPileComponent scDeal = DealDeck.GetComponent <CardPileComponent>();

            scDeal.CardsInPile.Clear();
            for (int i = 0; i < 52; i++)
            {
                var card = CardDeck.DealACard(false, false);
                if (card == null)
                {
                    break;
                }
                var ccomp = card.GetComponent <Card>();
                ccomp.CardStack   = scDeal.PileID;
                ccomp.HoldingPile = scDeal;
                scDeal.CardsInPile.Add(card);
            }
        }
Beispiel #5
0
        public void Execute()
        {
            var MyScene = (Scene)Global.CurrentScene;

            if (MyScene.GetType().Name != "CardScene")
            {
                return;
            }

            var entities = Context <Default> .AllOf <PileDispComponent>().GetEntities();

            foreach (var entity in entities)
            {
                CardPileComponent cp = entity.GetComponent <CardPileComponent>();
                //
                // 0=Pile on top eachother, 1=right, 2=left, 3=up, 4=down
                //
                switch (cp.FannedDirection)
                {
                case 0:
                    fanOutDistannce = Vector2.Zero;
                    break;

                case 1:
                    fanOutDistannce = new Vector2(30f, 0);
                    break;

                case 2:
                    fanOutDistannce = new Vector2(-30f, 0);
                    break;

                case 3:
                    fanOutDistannce = new Vector2(0, -30f);
                    break;

                case 4:
                    fanOutDistannce = new Vector2(0, 30f);
                    break;
                }
                //
                // All cards are Entities in this stack
                //
                int ind = 0;                            //cards number in stack

                for (int i = 0; i < cp.CardsInPile.Count; i++)
                {
                    Entity cardEntity = cp.CardsInPile[i];
                    cardEntity.Get <Transform>().Enabled  = true;
                    cardEntity.Get <Transform>().Position = entity.Get <Transform>().Position + fanOutDistannce * new Vector2(ind, ind);

                    cardEntity.Get <Card>().RenderLayer = 100 + ind;
                    ind += 1;
                }
            }
        }
Beispiel #6
0
        public void TakeCards2Drag(Entity _entity)
        {
            DragDisp.Get <Transform>().Visiable = true;
            //
            // Get the top card from 1-7 play stacks (_entity is a card)
            //
            Card _cc = _entity.GetComponent <Card>();

            if (_cc == null)
            {
                return;
            }

            CardPileComponent scTemp     = _cc.HoldingPile;
            Entity            fromEntity = scTemp.CompEntity;
            //
            // Find the card in the pile, then get all cards from that on down
            //
            int cInd = scTemp.CardsInPile.FindIndex(x => x.Tag == _entity.Tag);
            CardPileComponent scDrag = DragDisp.GetComponent <CardPileComponent>();

            //
            // if cInd is less than zero, then something is wrong
            //
            if (cInd < 0)
            {
                return;
            }

            for (int i = cInd; i <= scTemp.CardsInPile.Count - 1; i++)
            {
                Entity lastCard = scTemp.CardsInPile[i];
                Card   cc       = lastCard.GetComponent <Card>();
                //cc.IsFaceUp = true;
                scDrag.CardsInPile.Add(lastCard);
            }
            //
            // remove cards from original play Pile
            //
            for (int i = 0; i < scDrag.CardsInPile.Count; i++)
            {
                Entity lastCard = scDrag.CardsInPile[i];
                scTemp.CardsInPile.Remove(lastCard);
            }
            //
            // add cards to DispDrag
            //
            DragComponent sdc = new DragComponent()
            {
                EntityOrig = fromEntity
            };

            DragDisp.AddComponent <DragComponent>(sdc);
        }
        public PileOfCards(Entity _cardStack)
        {
            //
            // Stack entity holding cards
            //
            Tag             = _cardStack.Tag;
            StackComp       = new CardPileComponent();
            LastCardonStack = new Entity();

            StackComp = _cardStack.Get <CardPileComponent>();
            if (StackComp == null)
            {
                return;
            }

            if (StackComp.CardsInPile.Count == 0)
            {
                return;
            }
            else
            {
                TotalCards = StackComp.CardsInPile.Count;
            }

            LastCardonStack = StackComp.CardsInPile.LastOrDefault();
            CardsInThisPile = StackComp.CardsInPile;
            FannedDirection = StackComp.FannedDirection;
            switch (FannedDirection)
            {
            case 0:
                FanOutDistannce = Vector2.Zero;
                break;

            case 1:
                FanOutDistannce = new Vector2(30f, 0);
                break;

            case 2:
                FanOutDistannce = new Vector2(-30f, 0);
                break;

            case 3:
                FanOutDistannce = new Vector2(0, -30f);
                break;

            case 4:
                FanOutDistannce = new Vector2(0, 30f);
                break;
            }
        }
Beispiel #8
0
        public void ReturnCardFromDrag2Stack()
        {
            DragComponent scDragComp = DragDisp.GetComponent <DragComponent>();

            if (scDragComp == null)
            {
                return;
            }

            Entity            fromEntity = scDragComp.EntityOrig;
            CardPileComponent scDrag     = DragDisp.GetComponent <CardPileComponent>();       //cards being dragged
            CardPileComponent scFrom     = fromEntity.GetComponent <CardPileComponent>();     //cards to give back

            for (int i = 0; i < scDrag.CardsInPile.Count; i++)
            {
                scFrom.CardsInPile.Add(scDrag.CardsInPile[i]);
            }
            DragStackClear();
        }
Beispiel #9
0
        public void DealCard2Disp(Entity _entity)
        {
            //
            // take last card from the deal deck
            //
            CardPileComponent scDisp = DrawDisp.GetComponent <CardPileComponent>();
            CardPileComponent scTemp = DealDeck.GetComponent <CardPileComponent>();

            if (scTemp == null)
            {
                return;         //not a Pile entity
            }
            //
            // if deal deck is empty, put all face up cards back in deal deck
            //
            if (scTemp.CardsInPile.Count <= 0)
            {
                //
                // We are recycling the waste cards back in the deal deal deck
                //
                UpdateScore(-20);

                for (int i = scDisp.CardsInPile.Count - 1; i >= 0; i--)
                {
                    Card _card = scDisp.CardsInPile[i].GetComponent <Card>();
                    _card.IsFaceUp = false;
                    scTemp.CardsInPile.Add(scDisp.CardsInPile[i]);
                }
                scDisp.CardsInPile.Clear();
                return;
            }

            Entity lastCardonPile = scTemp.CardsInPile.LastOrDefault();               //get last card

            scTemp.CardsInPile.Remove(lastCardonPile);

            Card lastCard = lastCardonPile.GetComponent <Card>();

            lastCard.IsFaceUp = true;


            scDisp.CardsInPile.Add(lastCardonPile);
        }
Beispiel #10
0
        public void DropCardFromDrag2AceStack(Entity _playStack)
        {
            //
            // Ace statck is known as "foundation" pile
            //

            CardPileComponent scDrag = DragDisp.GetComponent <CardPileComponent>();            //cards being dragged

            if (scDrag.CardsInPile.Count != 1)
            {
                ReturnCardFromDrag2Stack();
                return;
            }
            DragComponent scDragComp = DragDisp.GetComponent <DragComponent>();

            if (scDragComp.EntityOrig == _playStack)
            {
                ReturnCardFromDrag2Stack();
                return;
            }

            CardPileComponent scPlay = _playStack.GetComponent <CardPileComponent>();            //cards being dropped
            //
            // first card of drag needs to match last card of drop
            //
            Entity firstCardonStack = scDrag.CardsInPile[0];               //get first card of drag
            Card   firstCard        = firstCardonStack.GetComponent <Card>();

            //
            // Make sure this stack is not empty
            //
            if (scPlay.CardsInPile.Count == 0)
            {
                if (firstCard.FaceImage != 1)          //only an ACE will sit on empty stack
                {
                    ReturnCardFromDrag2Stack();
                    return;
                }
                //
                //  first card of drap is ACE, drop it
                //
                for (int i = 0; i < scDrag.CardsInPile.Count; i++)
                {
                    scPlay.CardsInPile.Add(scDrag.CardsInPile[i]);
                    CardDeck.Score += scDrag.GetCardFaceImageValue(i);       //card added, calc score
                }
                UpdateScore(10);
                DragStackClear();
                return;
            }
            //
            // play stack is NOT empty, test cards
            //
            Entity lastCardonStack = scPlay.CardsInPile.LastOrDefault();               //get last card
            Card   lastCard        = lastCardonStack.GetComponent <Card>();

            if (TestCardsForAceStack(firstCard, lastCard))
            {
                for (int i = 0; i < scDrag.CardsInPile.Count; i++)
                {
                    scPlay.CardsInPile.Add(scDrag.CardsInPile[i]);
                    CardDeck.Score += scDrag.GetCardFaceImageValue(i);       //card added, calc score
                }
                UpdateScore(10);
                DragStackClear();
            }
            else
            {
                ReturnCardFromDrag2Stack();
            }
        }
Beispiel #11
0
        public void DropCardFromDrag2PlayStack(Entity _playStack)
        {
            CardPileComponent scDrag = DragDisp.GetComponent <CardPileComponent>();            //cards being dragged
            CardPileComponent scPlay = _playStack.GetComponent <CardPileComponent>();          //cards being dropped

            if (scDrag.CardsInPile.Count == 0)
            {
                return;
            }
            //
            // first card of drag needs to match last card of drop
            //
            Entity firstCardonStack = scDrag.CardsInPile[0];               //get first card
            Card   firstCard        = firstCardonStack.GetComponent <Card>();

            //
            // Make sure this stack is not empty
            //
            if (scPlay.CardsInPile.Count == 0)
            {
                if (firstCard.FaceImage < 13)          //only a king will sit on empty stack
                {
                    ReturnCardFromDrag2Stack();
                    return;
                }
                //
                //  first card of drop is king, drop all of them
                //
                for (int i = 0; i < scDrag.CardsInPile.Count; i++)
                {
                    scPlay.CardsInPile.Add(scDrag.CardsInPile[i]);
                }
                //
                // set the holding stack for this card pile
                //
                for (int i = 0; i < scPlay.CardsInPile.Count; i++)
                {
                    Card _cc = scPlay.CardsInPile[i].GetComponent <Card>();
                    _cc.HoldingPile = scPlay;
                }
                UpdateScore(possibleScoreValue);
                DragStackClear();
                return;
            }
            //
            // play stack is NOT empty, test cards
            //
            Entity lastCardonStack = scPlay.CardsInPile.LastOrDefault();               //get last card
            Card   lastCard        = lastCardonStack.GetComponent <Card>();

            if (TestCardsForPlayStack(firstCard, lastCard))
            {
                for (int i = 0; i < scDrag.CardsInPile.Count; i++)
                {
                    scPlay.CardsInPile.Add(scDrag.CardsInPile[i]);
                }
                //
                // set the holding stack for this card pile
                //
                for (int i = 0; i < scPlay.CardsInPile.Count; i++)
                {
                    Card _cc = scPlay.CardsInPile[i].GetComponent <Card>();
                    _cc.HoldingPile = scPlay;
                }
                UpdateScore(possibleScoreValue);
                DragStackClear();
            }
            else
            {
                //
                // -1000 means we are flipping a card in play stack
                //
                if (possibleScoreValue == -1000)
                {
                    UpdateScore(5);
                }
                ReturnCardFromDrag2Stack();
            }
        }
Beispiel #12
0
        public void Execute()
        {
            var tmpScene = (Scene)Global.CurrentScene;

            if (tmpScene.GetType().Name != "CardScene")
            {
                return;
            }

            MyScene = (CardScene)tmpScene;
            var entities = Context <Default> .AllOf <DragComponent>().GetEntities();

            foreach (var entity in entities)
            {
                //
                // We have a DragDisp entity (holds all cards entities)
                //
                CardPileComponent sc = entity.GetComponent <CardPileComponent>();
                if (sc != null)
                {
                    if (sc.CardsInPile.Count <= 0)
                    {
                        return;                         //no cards to drag
                    }
                }

                var _mouseCollider = entity.GetComponent <BoxCollider>();
                PrevMouse    = CurrentMouse;
                CurrentMouse = Global.GetMousePosition();
                //
                // Current location of the mouse used for the hand icon
                //
                entity.Get <Transform>().Position = CurrentMouse;

                Entity lastCardonStack = sc.CardsInPile.LastOrDefault();
                //
                // Display of stack by fan out direction
                //
                switch (sc.FannedDirection)
                {
                case 0:
                    fanOutDistannce = Vector2.Zero;
                    break;

                case 1:
                    fanOutDistannce = new Vector2(30f, 0);
                    break;

                case 2:
                    fanOutDistannce = new Vector2(-30f, 0);
                    break;

                case 3:
                    fanOutDistannce = new Vector2(0, -30f);
                    break;

                case 4:
                    fanOutDistannce = new Vector2(0, 30f);
                    break;
                }
                //
                // All cards are Entities in this stack
                //
                int ind = 0;                            //cars number in stack
                for (int i = 0; i < sc.CardsInPile.Count; i++)
                {
                    Entity cardEntity = sc.CardsInPile[i];
                    cardEntity.Get <Transform>().Enabled  = true;
                    cardEntity.Get <Transform>().Position = entity.Get <Transform>().Position + fanOutDistannce * ind;
                    //
                    // Get the sprite (face/back)
                    //
                    //cardEntity.GetComponent<Card>().RenderLayer = (ind * 1000);
                    //cardEntity.GetComponent<Card>().RenderLayer = Global.CURSOR_LAYER - ind;
                    cardEntity.GetComponent <Card>().RenderLayer = Global.CURSOR_LAYER - ind;
                    ind += 1;
                }
            }
        }