コード例 #1
0
 //Lets the player play a card(s) if they choose.
 private void PlayCard()
 {
     //hasthought = true here or something
     players[whosTurn].HasFinishedTurn = false;
     players[whosTurn].HasPlayedCard   = true;
     lastPlay = players[whosTurn].Play(GetLivingPlayers(), PlayType.Normal);     //When the player originally plays a card.
     if (lastPlay != null)
     {
         //If the chosen card to play was for the table, then equip it.
         if (lastPlay.CType == CardType.Schofield || lastPlay.CType == CardType.Winchester || lastPlay.CType == CardType.Mustang ||
             lastPlay.CType == CardType.Remington || lastPlay.CType == CardType.RevCarabine || lastPlay.CType == CardType.Scope ||
             lastPlay.CType == CardType.Barrel)
         {
             EquipCard();
         }
         //Otherwise, the card goes to the discards.
         else
         {
             AddVisual(new TravelingCard(players[whosTurn].Hand, lastPlay.Index, discardPile, speed, CardState.FaceUp, 0));
         }
         WriteCardToChat(players[whosTurn], lastPlay.Who, lastPlay.CType);
     }
     else
     {
         players[whosTurn].HasFinishedTurn = true;
     }
 }
コード例 #2
0
ファイル: CPU.cs プロジェクト: ryanwwest/bang-card-game
        //Discards extra cards at the end of a turn (max cards == current life)
        public override PlayCard[] DiscardExtras(Player[] players)
        {
            if (hand.Size <= life)
            {
                return(null);
            }

            bool[] usedIndex = new bool[hand.Size];

            PlayCard[] p         = new PlayCard[hand.Size - life];
            int[]      indexes   = new int[1];
            int        numFilled = 0;

            if (players.Length <= 2 && hand.Contains(CardType.Beer, out indexes))
            {
                for (int i = 0; i < indexes.Length && numFilled < p.Length; i++)
                {
                    p[numFilled] = new PlayCard(indexes[i], null, hand[indexes[i]]); usedIndex[indexes[i]] = true; numFilled++;
                }
            }
            if (tableCards.Contains(CardType.Schofield) && hand.Contains(CardType.Schofield, out indexes))
            {
                for (int i = 0; i < indexes.Length && numFilled < p.Length; i++)
                {
                    p[numFilled] = new PlayCard(indexes[i], null, hand[indexes[i]]); usedIndex[indexes[i]] = true; numFilled++;
                }
            }
            if (hand.Contains(CardType.Bang, out indexes))
            {
                for (int i = 0; i < indexes.Length && numFilled < p.Length; i++)
                {
                    p[numFilled] = new PlayCard(indexes[i], null, hand[indexes[i]]); usedIndex[indexes[i]] = true; numFilled++;
                }
            }
            if (hand.Contains(CardType.Missed, out indexes))
            {
                for (int i = 0; i < indexes.Length && numFilled < p.Length; i++)
                {
                    p[numFilled] = new PlayCard(indexes[i], null, hand[indexes[i]]); usedIndex[indexes[i]] = true; numFilled++;
                }
            }

            int rand = 0; //Pick random cards afterwords, making sure to not pick the same card twice.

            while (numFilled < p.Length)
            {
                rand = MainProgram.random.Next(hand.Size);

                if (!usedIndex[rand])
                {
                    p[numFilled]    = new PlayCard(rand, null, hand[rand]);
                    usedIndex[rand] = true;
                    numFilled++;
                }
            }

            return(p);
        }
コード例 #3
0
        //Handles effects of cards played by the current player (bang requires missed, etc.)
        private void HandlePlayCardEffects()
        {
            PlayCard[] secondary      = new PlayCard[players.Length];
            bool       effectFinished = true; //This must be set to false each time to prevent current effect (barrel) from finishing.

            switch (lastPlay.CType)
            {
            case CardType.Bang:
                if (!UseBarrel(out effectFinished))
                {
                    secondary[0] = lastPlay.Who.Play(null, PlayType.BangResponse);
                }
                if (secondary[0] != null)
                {
                    AddVisual(new TravelingCard(lastPlay.Who.Hand, secondary[0].Index, discardPile, speed, CardState.FaceUp, 0));
                    chat.Write(lastPlay.Who.Name + " avoids " + players[whosTurn].Name + "'s bang card with a missed!");
                }
                else if (secondary[0] == null && !lastPlay.Who.HasUsedBarrel)
                {
                    WriteLifeLossToChat(lastPlay.Who, players[whosTurn]);
                }
                break;

            case CardType.Saloon:
                for (int i = 0; i < players.Length; i++)
                {
                    if (players[i].IsAlive && players[i].Life < players[i].MaxLife)
                    {
                        players[i].Life++;
                    }
                }
                break;

            case CardType.Beer:
                if (players[whosTurn].Life < players[whosTurn].MaxLife)
                {
                    players[whosTurn].Life++;
                }
                break;

            case CardType.Indians:
                for (int i = 0; i < players.Length; i++)
                {
                    if (i != whosTurn && players[i].IsAlive)
                    {
                        secondary[i] = players[i].Play(null, PlayType.IndiansResponse);
                        if (secondary[i] != null)
                        {
                            AddVisual(new TravelingCard(players[i].Hand, secondary[i].Index, discardPile, speed, CardState.FaceUp, 0));
                            chat.Write(players[i].Name + " avoids the Indians with a bang!");
                        }
                        else
                        {
                            WriteLifeLossToChat(players[i], players[whosTurn]);
                        }
                    }
                }
                break;

            case CardType.Gatling:
                for (int i = 0; i < players.Length; i++)
                {
                    if (i != whosTurn && players[i].IsAlive)
                    {
                        secondary[i] = players[i].Play(null, PlayType.BangResponse);
                        if (secondary[i] != null)
                        {
                            AddVisual(new TravelingCard(players[i].Hand, secondary[i].Index, discardPile, speed, CardState.FaceUp, 0));
                            chat.Write(players[i].Name + " avoids the gatling with a missed!");
                        }
                        else
                        {
                            WriteLifeLossToChat(players[i], players[whosTurn]);
                        }
                    }
                }
                break;

            case CardType.Duel:

                break;

            case CardType.CatBalou:
                bool discarded = false;
                for (int i = 0; i < lastPlay.Who.TableCards.Size; i++)
                {
                    if (lastPlay.OtherCard == lastPlay.Who.TableCards[i])
                    {
                        AddVisual(new TravelingCard(lastPlay.Who.TableCards, lastPlay.OtherIndex, discardPile, speed, CardState.FaceUp, 0));
                        discarded = true;
                    }
                }
                if (!discarded)
                {
                    AddVisual(new TravelingCard(lastPlay.Who.Hand, lastPlay.OtherIndex, discardPile, speed, CardState.FaceUp, 0));
                }
                chat.Write(players[whosTurn].Name + " discards " + lastPlay.Who.Name + "'s " + lastPlay.OtherCard.GetFullCardTypeString() +
                           "!");
                break;

            case CardType.Panic:
                discarded = false;
                for (int i = 0; i < lastPlay.Who.TableCards.Size; i++)
                {
                    if (lastPlay.OtherCard == lastPlay.Who.TableCards[i])
                    {
                        AddVisual(new TravelingCard(lastPlay.Who.TableCards, lastPlay.OtherIndex, players[whosTurn].Hand, speed, CardState.FaceUp, 0));
                        discarded = true;
                    }
                }
                if (!discarded)
                {
                    AddVisual(new TravelingCard(lastPlay.Who.Hand, lastPlay.OtherIndex, players[whosTurn].Hand, speed, CardState.FaceUp, 0));
                }
                chat.Write(players[whosTurn].Name + " steals " + lastPlay.Who.Name + "'s " + lastPlay.OtherCard.GetFullCardTypeString() +
                           "!");
                break;

            case CardType.Stagecoach: effectFinished = HandleStagecoach(); break;

            case CardType.WellsFargo: effectFinished = HandleWellsFargo(); break;

            default: break;
            }
            if (effectFinished) //Completes the operations of the current card.
            {
                players[whosTurn].HasPlayedCard = false;
                if (lastPlay.Who != null)
                {
                    lastPlay.Who.HasUsedBarrel = false;
                }
                lastPlay = null;
            }
        }