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); }
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 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(); }
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(); } }