Beispiel #1
0
        private bool ThrowWhenNotOwnParty(Card cardThrown)
        {
            // If there are no cards already thrown we can not throw
                if (DescPairs.Count == 0)
                    return false;

                var lastIndex = DescPairs.Count - 1;

                if (DescPairs[lastIndex].LowerCard.CardSuit == Trump &&
                    cardThrown.CardSuit != Trump)
                    return false;

                if (DescPairs[lastIndex].LowerCard.CardSuit != Trump &&
                    cardThrown.CardSuit == Trump)
                    return true;

                if ((DescPairs[lastIndex].LowerCard.CardSuit == Trump &&
                    cardThrown.CardSuit == Trump) ||
                    (DescPairs[lastIndex].LowerCard.CardSuit != Trump &&
                    cardThrown.CardSuit != Trump))
                    return (cardThrown.CardSuit == DescPairs[lastIndex].LowerCard.CardSuit) &&
                       ((int)DescPairs[lastIndex].LowerCard.CardType < (int)cardThrown.CardType);

                return false;
        }
Beispiel #2
0
        private bool ThrowWhenOwnParty(Card cardThrown)
        {
            // If there are no cards already thrown we can throw
                if (DescPairs.Count == 0)
                    return true;

                // Get list of cards thrown
                List<Card> cards = new List<Card> { };
                foreach (var card in DescPairs)
                {
                    cards.Add((Card)card.LowerCard);

                    if (card.UpperCard != null)
                        cards.Add((Card)card.UpperCard);
                }

                // Can card be thrown or not...
                bool canThrow = false;
                foreach (var card in cards)
                {
                    if (cardThrown.CardType == card.CardType)
                    {
                        canThrow = true; break;
                    }
                }

                return canThrow;
        }
Beispiel #3
0
        private Card? GetMinTrump(List<Card> cardList)
        {
            if (cardList.Count == 0)
                return null;

            Card min = new Card();
            bool found = false;

            foreach (var card in cardList)
            {
                if (card.CardSuit == Trump)
                {
                    min = card;
                    found = true;
                    break;
                }
            }

            if (found)
            {
                foreach (var card in cardList)
                {
                    if ((int)card.CardType < (int)min.CardType)
                    {
                        min = card;
                    }
                }
            }
            else return null;

            return min;
        }
Beispiel #4
0
        private int GetCardPriority(Card card)
        {
            if (card.CardSuit == Trump) return 100000;

            switch (card.CardSuit)
            {
                case CardSuit.Heart: return 10;
                case CardSuit.Diamond: return 100;
                case CardSuit.Club: return 1000;
                case CardSuit.Spade: return 10000;
                default: return 1;
            }
        }
Beispiel #5
0
        private void CreateDeck()
        {
            // Create Deck
            for (int i = 0; i < MaxCardTypeIndex; i++)
            {
                for (int j = 0; j < MaxCardSuitIndex; j++)
                {
                    Card card = new Card();
                    if (Enum.IsDefined(typeof(CardType), i))
                    {
                        card.CardType = (CardType)i;
                    }
                    else
                    {
                        if (OnGameError != null) OnGameError(GameError.FatalError, "Card index not found"); return;
                    }

                    if (Enum.IsDefined(typeof(CardSuit), j))
                    {
                        card.CardSuit = (CardSuit)j;
                    }
                    else
                    {
                        if (OnGameError != null) OnGameError(GameError.FatalError, "Card index not found"); return;
                    }

                    Deck.Add(card);
                }
            }

            // Shuffle cards
            for (int i = 1; i < Deck.Count; i++)
            {
                int pos = _rnd.Next(i + 1);
                var x = Deck[i];
                Deck[i] = Deck[pos];
                Deck[pos] = x;
            }

            // The first card suit in the deck is a trump suit
            Trump = Deck[0].CardSuit;

            if (OnDeckCreated != null) OnDeckCreated();
        }
Beispiel #6
0
        public void ThrowCard(PlayerType player, Card card)
        {
            // There are 4 possible variations and 2 types of rules
                //
                // First (1'st type): when that is player's party and player's throw.
                // In this case we shall see for equivalent cards on desc and allow only these,
                // which are equal by type with cards already thrown.
                //
                // Second (1'st type): when that is enemy's party and enemy's throw.
                // In this case we shall see for equivalent cards on desc and allow only these,
                // which are equal by type with cards already thrown.
                //
                // Third (2'nd type): when that is player's party and enemy's throw.
                // In this case we shall find out, could the thrown card beat the card, which was
                // thrown by player. Otherwise we refuse throwing.
                //
                // Fourth (2'nd type): when that is enemy's party and player's throw.
                // In this case we shall find out, could the thrown card beat the card, which was
                // thrown by player. Otherwise we refuse throwing.

                if (IsBlocked) return;
                switch (GameState)
                {
                    case GameState.Ready: GameState = GameState.Playing; break;
                    case GameState.Finished: return;
                    case GameState.Playing: break;
                    default: return;
                }

                if (player == PlayerType.Player && WhoseParty == PlayerType.Player)
                {
                    if (!PlayerCards.Contains(card))
                    {
                        if (OnActionRefused != null) OnActionRefused(GameAction.Throw, GameError.Warning, "You has no such card");
                        return;
                    }

                    if (!ThrowWhenOwnParty(card))
                    {
                        if (OnActionRefused != null) OnActionRefused(GameAction.Throw, GameError.ActionRefused, "You can't throw that card");
                        return;
                    }
                    else
                    {
                        PlayerCards.Remove(card);
                        DescPairs.Add(new CardPair { LowerCard = card });

                        if (OnThrowCard != null) OnThrowCard(player, card);
                        WhoseTurn = PlayerType.Enemy;
                        CheckGameState();
                        return;
                    }
                }
                if (player == PlayerType.Enemy && WhoseParty == PlayerType.Enemy)
                {
                    if (!EnemyCards.Contains(card))
                    {
                        if (OnActionRefused != null) OnActionRefused(GameAction.Throw, GameError.Warning, "You has no such card");
                        return;
                    }

                    if (!ThrowWhenOwnParty(card))
                    {
                        if (OnActionRefused != null) OnActionRefused(GameAction.Throw, GameError.ActionRefused, "You can't throw that card");
                        return;
                    }
                    else
                    {
                        EnemyCards.Remove(card);
                        DescPairs.Add(new CardPair { LowerCard = card });

                        if (OnThrowCard != null) OnThrowCard(player, card);
                        WhoseTurn = PlayerType.Player;
                        CheckGameState();
                        return;
                    }
                }

                if (player == PlayerType.Player && WhoseParty == PlayerType.Enemy)
                {
                    if (!PlayerCards.Contains(card))
                    {
                        if (OnActionRefused != null) OnActionRefused(GameAction.Throw, GameError.Warning, "You has no such card");
                        return;
                    }

                    if (!ThrowWhenNotOwnParty(card))
                    {
                        if (OnActionRefused != null) OnActionRefused(GameAction.Throw, GameError.ActionRefused, "You can't throw that card");
                        return;
                    }
                    else
                    {
                        PlayerCards.Remove(card);
                        DescPairs[DescPairs.Count - 1].UpperCard = card;

                        if (OnThrowCard != null) OnThrowCard(player, card);
                        WhoseTurn = PlayerType.Enemy;
                        CheckGameState();
                        return;
                    }
                }
                if (player == PlayerType.Enemy && WhoseParty == PlayerType.Player)
                {
                    if (!EnemyCards.Contains(card))
                    {
                        if (OnActionRefused != null) OnActionRefused(GameAction.Throw, GameError.Warning, "You has no such card");
                        return;
                    }

                    if (!ThrowWhenNotOwnParty(card))
                    {
                        if (OnActionRefused != null) OnActionRefused(GameAction.Throw, GameError.ActionRefused, "You can't throw that card");
                        return;
                    }
                    else
                    {
                        EnemyCards.Remove(card);
                        DescPairs[DescPairs.Count - 1].UpperCard = card;

                        if (OnThrowCard != null) OnThrowCard(player, card);
                        WhoseTurn = PlayerType.Player;
                        CheckGameState();
                        return;
                    }
                }
        }
Beispiel #7
0
 private void RenewWindowHandler(PlayerType playerType, Card card)
 {
     _player.GamePackage = gameDesktop.GetGameData();
     _enemy.GamePackage = gameDesktop.GetGameData();
     SpriteManager.RenewWindowPackage(GameDesktop.GetGameData());
 }