Exemple #1
0
        private System.Collections.IEnumerator completeLoad()
        {
            yield return(new WaitUntil(() => sceneController.preloadLoaded));

            GameObject globalData = GameObject.Find("GlobalData");
            Deck       deck       = globalData.transform.Find("Deck1").GetComponent <Deck>();


            if (deck != null)
            {
                for (int i = 0; i < deck.cards.Count; i++)
                {
                    CardInstance c = Instantiate(cardTemplate);
                    c.owner = player1;
                    c.transformToCard(deck.cards[i]);
                    boardManager.addCardToBoard(c);
                    boardManager.playerDecks[0].addCard(c, 0);
                }

                for (int i = 0; i < deck.cards.Count; i++)
                {
                    CardInstance c = Instantiate(cardTemplate);
                    c.owner = player2;
                    c.transformToCard(deck.cards[i]);
                    boardManager.addCardToBoard(c);
                    boardManager.playerDecks[1].addCard(c, 0);
                }
            }
            boardManager.drawToHandFill();
            setTurn(0);
        }
Exemple #2
0
        public void dropDragCard()
        {
            if (dragCard == null)
            {
                return;
            }
            Square sq            = getNearestSquare(dragCard.transform.localPosition);
            bool   actionSuccess = false;

            if (dragCard.square.boardLocation == BoardLocationEnum.player1Hand || dragCard.square.boardLocation == BoardLocationEnum.player2Hand)
            {
                actionSuccess = initiateAction(dragCard, sq, BoardActionEnum.deploy);
            }
            else if (dragCard.square.boardLocation == BoardLocationEnum.board)
            {
                actionSuccess = initiateAction(dragCard, sq, BoardActionEnum.movement);
            }
            if (!actionSuccess && dragCard.square != null)
            {
                moveCardToSquare(dragCard, dragCard.square);
            }
            dragCard.GetComponent <SortingGroup>().sortingLayerName = "Default";
            dragCard = null;
            clearHighlightSquares();
        }
        public bool initiateMovementAction(CardInstance card, Square square)
        {
            if (!gameManager.isPlayerTurn(card.owner))
            {
                return(false);
            }
            if (square.boardLocation != BoardLocationEnum.board)
            {
                return(false);   //must move to square on board
            }
            ActionTargetingInfo tInfo = new ActionTargetingInfo {
                player        = card.owner,
                sourceCard    = card,
                targetSquares = new List <Square> {
                    square
                }
            };

            for (int i = 0; i < card.movementActions.Count; i++)
            {
                if (card.movementActions[i].execute(0, tInfo))
                {
                    return(true);
                }
            }

            return(false);
        }
        public CardInstance drawCard()
        {
            if (cards.Count == 0)
            {
                return(null);
            }
            CardInstance drawnCard = cards[cards.Count - 1];

            cards.RemoveAt(cards.Count - 1);
            return(drawnCard);
        }
Exemple #5
0
 protected bool allowedToDrag(CardInstance card)
 {
     if (card.square == null)
     {
         return(false);
     }
     if (card.square.boardLocation == BoardLocationEnum.board || card.square.boardLocation == BoardLocationEnum.player1Hand || card.square.boardLocation == BoardLocationEnum.player2Hand)
     {
         return(true);
     }
     return(false);
 }
 //index is from the back of the deck, so that drawing is more runtime efficient
 public void addCard(CardInstance card, int index)
 {
     if (index < 0 || index > cards.Count)
     {
         return;
     }
     else
     {
         cards.Insert(cards.Count - index, card);
     }
     if (boardManager != null)
     {
         boardManager.moveCardToSquare(card, this);
     }
 }
        public virtual bool drawCard(int playerIndex)
        {
            if (playerIndex >= playerHandSquares.Count || playerIndex >= playerDecks.Count)
            {
                return(false);
            }
            CardInstance drawnCard = playerDecks[playerIndex].drawCard();

            if (drawnCard == null)
            {
                return(false);
            }
            moveCardToSquare(drawnCard, playerHandSquares[playerIndex]);
            return(true);
        }
        public bool initiateMovementActionByPos(CardInstance card, int row, int col)
        {
            Square sq;

            if (col >= 0 && col < squares.Count && row >= 0 && row < squares[col].Count)
            {
                sq = squares[col][row];
            }
            else
            {
                return(false);
            }
            //throw new System.Exception("initiateMovementActionByPos: must deploy to square on board");

            return(initiateMovementAction(card, sq));
        }
        public virtual void moveCardToSquare(CardInstance card, Square square)
        {
            Square prevSquare = card.square;

            if (prevSquare == square || square == null)
            {
                return;
            }

            if (prevSquare != null)
            {
                prevSquare.cards.Remove(card);
            }
            square.cards.Add(card);
            card.square = square;
        }
Exemple #10
0
        public override void moveCardToSquare(CardInstance card, Square square)
        {
            Square prevSquare = card.square;

            base.moveCardToSquare(card, square);
            if (square == null)
            {
                card.transform.localPosition = prevSquare.transform.localPosition;
            }
            else if (square != playerHandSquares[0] && square != playerHandSquares[1])
            {
                card.transform.localPosition = square.transform.localPosition;
            }
            if (square == playerHandSquares[0] || prevSquare == playerHandSquares[0])
            {
                updateHandCardPositions(0);
            }
            if (square == playerHandSquares[1] || prevSquare == playerHandSquares[1])
            {
                updateHandCardPositions(1);
            }
        }
Exemple #11
0
        public void highlightValidSquares(CardInstance card, BoardActionEnum actionType)
        {
            ActionTargetingInfo targetInfo = new ActionTargetingInfo {
                player        = card.owner,
                sourceCard    = card,
                targetSquares = new List <Square> {
                    squares[0][0]
                }
            };

            for (int i = 0; i < squares.Count; i++)
            {
                for (int j = 0; j < squares[i].Count; j++)
                {
                    targetInfo.targetSquares[0] = squares[i][j];
                    if (card.isValidActionTarget(targetInfo, actionType))
                    {
                        ((ScreenSquare)squares[i][j]).setHighlight(true);
                    }
                }
            }
        }
Exemple #12
0
 public void setDragCard(CardInstance newCard)
 {
     if (!allowedToDrag(newCard))
     {
         return;
     }
     if (dragCard == null)
     {
         dragCard = newCard;
         dragCard.GetComponent <SortingGroup>().sortingLayerName = "DragCard";
         if (dragCard.square == null)
         {
         }
         else if (dragCard.square.boardLocation == BoardLocationEnum.board)
         {
             highlightValidSquares(dragCard, BoardActionEnum.movement);
         }
         else if (dragCard.square.boardLocation == BoardLocationEnum.player1Hand || dragCard.square.boardLocation == BoardLocationEnum.player2Hand)
         {
             highlightValidSquares(dragCard, BoardActionEnum.deploy);
         }
     }
 }
        public bool initiateAction(CardInstance card, Square square, BoardActionEnum actionType, bool endTurnOnSuccess = true)
        {
            if (square == null)
            {
                return(false);
            }
            bool success = false;

            if (actionType == BoardActionEnum.deploy)
            {
                success = initiateDeployAction(card, square);
            }
            else if (actionType == BoardActionEnum.movement)
            {
                success = initiateMovementAction(card, square);
            }
            if (endTurnOnSuccess && success)
            {
                gameManager.finishPlayerTurn(card.owner);
            }

            return(success);
        }
        //row == -1 for player 1 hand, -2 for player 2 hand
        public void moveCardToSquareByPos(CardInstance card, int row, int col)
        {
            Square sq;

            if (row == -1)
            {
                sq = playerHandSquares[0];
            }
            else if (row == -2)
            {
                sq = playerHandSquares[1];
            }
            else if (col >= 0 && col < squares.Count && row >= 0 && row < squares[col].Count)
            {
                sq = squares[col][row];
            }
            else
            {
                throw new System.Exception("moveCardToSquareByPos: invalid square position");
            }

            moveCardToSquare(card, sq);
        }
Exemple #15
0
        public override void addCardToBoard(CardInstance card)
        {
            card.transform.SetParent(canvas.transform, false);

            base.addCardToBoard(card);
        }
 public virtual void addCardToBoard(CardInstance card)
 {
     card.boardManager = this;
 }