Exemplo n.º 1
0
        private bool PlaceCard(CardClass card, int x, int y, int transX, int transY, uint ID, bool place)
        {
            if ( x >= 0 && y >= 0 && x < map.GetLength(1) && y < map.GetLength(0))
            {
                CardClass replacedCard = map[y, x];
                CardClass winner = card;
                int modifier = 0;
                bool forwardMove = false;
                if (!(transX == 0 && transY == 0))
                {
                    modifier = card.GetMove()[transY, transX].modifier;
                    forwardMove = card.GetMove()[transY, transX].y == transX;
                }

                if (replacedCard != null && replacedCard.player != card.player)
                    // Check to see which one wins in this battle.
                    winner = replacedCard.GetCardType().GetStat() <= card.GetCardType().GetStat() + modifier ? card : replacedCard;
                else if (replacedCard != null)
                {
                    string type = card.GetCardType().typeName.Substring(0, card.GetCardType().typeName.Length - 1);
                    string replaceType = replacedCard.GetCardType().typeName.Substring(0, replacedCard.GetCardType().typeName.Length - 1);
                    string lastLetter = card.GetCardType().typeName.Substring(card.GetCardType().typeName.Length - 1);
                    if (type.Equals("Soldier") && replaceType.Equals("Soldier") && place)
                    {
                        foreach (CardType ct in cardTypes)
                        {
                            if (ct.typeName.ToLower().ToString().Equals("stack" + lastLetter.ToLower()))
                            {
                                winner = new CardClass(ct, card.player);
                                winner.SetLocation(replacedCard.GetLoc(), true);
                                break;
                            }
                        }

                        if (winner == null)
                            return false;
                    }
                    else
                        // tried to move onto own card.
                        return false;
                }

                if (y == activeTurn.GateLane())
                    return false;

                // Check for movement into the gates
                Turn other = turns.Find(delegate(Turn t) { return t != activeTurn; });
                if (other != null && y == other.GateLane())
                {
                    if (!forwardMove || x != 3)
                    {
                        return false;
                    }
                }

                Vector2 oldLoc = ConvertScreenCoordToMap(card.GetPrevLocation());
                // Cards can't move into their old position.
                if ((int)oldLoc.X == x && (int)oldLoc.Y == y)
                    return false;

                if (place)
                {
                    MoveList ml = new MoveList();
                    ml.moveID = ID;
                    ml.movedCard = card;
                    ml.replacedCard = (winner == replacedCard ? card : replacedCard);
                    ml.cardPrevLoc = winner.GetPrevLocation();
                    Vector2 newLoc = center + new Vector2(x * (CardClass.cardWidth + spacing), y * (CardClass.cardHeight + spacing));
                    ml.toLoc = newLoc;
                    ml.startLoc = winner.GetLoc();

                    moveStack.Push(ml);
                    map[y, x] = winner;
                    Vector2 clear = ConvertScreenCoordToMap(card.GetLoc());
                    if (clear.Y >= 0 && clear.X >= 0)
                        map[(int)clear.Y, (int)clear.X] = null;
                    winner.SetLocation(newLoc, true);

                    if (card.player == PlayerTurn.Player1)
                        turns[0].RemoveCardFromHand(card);
                    else if (card.player == PlayerTurn.Player2)
                        turns[1].RemoveCardFromHand(card);
                }

                return (place ? true : winner == card);
            }

            return false;
        }
Exemplo n.º 2
0
        private void SetupCardMovementAnimation(CardClass card, int offsetX, int offsetY, Vector2 cardLoc)
        {
            moveCard = card;
            MoveLocation[,] map = card.GetMove();
            moveStartLoc = ConvertMapCoordToScreen((int)cardLoc.X, (int)cardLoc.Y) + center;
            MoveLocation currentLoc = map[offsetY, offsetX];
            movementSteps.Clear();
            movementSteps.Push(new MoveSteps(offsetX, offsetY));
            while (currentLoc.x >= 0 && currentLoc.y >= 0 && !(currentLoc.x == 2 && currentLoc.y == 2))
            {
                movementSteps.Push(new MoveSteps(currentLoc.y, currentLoc.x));
                currentLoc = map[currentLoc.x, currentLoc.y];
            }

            moveCard.SetMoving(moveStartLoc);
            moving = true;
        }
Exemplo n.º 3
0
        protected bool MoveCard(CardClass card, int x, int y, int depthOffset, bool aiTest)
        {
            Vector2 mapLoc = new Vector2(x, y);
            // Can't move to the sides.
            if (mapLoc.X == 0 || mapLoc.X == map.GetLength(0) - 1)
                return false;

            if (card == null)
                return false;

            Vector2 cardLoc = ConvertScreenCoordToMap(card.GetLoc());

            bool good = false;

            // Handle first card placement.
            if (cardLoc.X == -1 && cardLoc.Y == -1)
            {
                // placing a new card.
                if (activeTurn.InDeploymentZone(mapLoc) && map[(int)mapLoc.Y, (int)mapLoc.X] == null && PlaceCard(card, (int)mapLoc.X, (int)mapLoc.Y, moveID))
                {
                    moveID++;
                    good = true;
                    if (aiTest)
                    {
                        SwitchTurns();
                    }
                }
                else
                    ResetSelectedCard();
            }
            // Handle card movement.
            else if ((deploy - depthOffset) <= 0 && mapLoc.X >= 0 && mapLoc.Y >= 0 && mapLoc.X < map.GetLength(0) && mapLoc.Y < map.GetLength(1) && (card.player == activeTurn.GetPlayerTurn() || !aiTest))
            {
                MoveLocation[,] moveOption = card.GetMove();
                int transX = (int)(mapLoc.X - cardLoc.X) + 2;
                int transY = (int)(mapLoc.Y - cardLoc.Y) + 2;

                if (transX == 2 && transY == 2) // center of the move map IE Early out
                    return false;

                // Check for the actual move.
                if (transX >= 0 && transY >= 0 && transX < moveOption.GetLength(0) && transY < moveOption.GetLength(1) && moveOption[transY, transX] != null)
                {
                    good = RecursiveCardMovement(card, cardLoc, moveOption[transY, transX], moveOption, transX, transY, moveID);
                    if (good)
                    {
                        moveID++;
                        if (aiTest)
                        {
                            SetupCardMovementAnimation(card, transX, transY, cardLoc);
                            SwitchTurns();
                        }
                    }
                }
                else
                {
                    ResetSelectedCard();
                }
            }
            else
            {
                ResetSelectedCard();
            }

            return good;
        }