コード例 #1
0
ファイル: CardDeck.cs プロジェクト: jsdokos/CIS501_Project1
        //Using example code from http://rosettacode.org/wiki/Knuth_shuffle
        public void Shuffle()
        {
            Random random = new Random();

            for (int i = 0; i < Deck.Length; i++)
            {
                int         j    = random.Next(i, Deck.Length);
                PlayingCard temp = Deck[i];
                Deck[i] = Deck[j];
                Deck[j] = temp;
            }
        }
コード例 #2
0
ファイル: Player.cs プロジェクト: jsdokos/CIS501_Project1
        //Using example code from http://rosettacode.org/wiki/Knuth_shuffle
        public void Shuffle()
        {
            Random random = new Random();

            for (int i = 0; i < topIndex; i++)
            {
                int         j    = random.Next(i, topIndex + 1);
                PlayingCard temp = Hand[i];
                Hand[i] = Hand[j];
                Hand[j] = temp;
            }
        }
コード例 #3
0
ファイル: CardDeck.cs プロジェクト: jsdokos/CIS501_Project1
        public CardDeck() //finish making old maid
        {
            int count = 0;

            topIndex = Deck.Length - 1;
            for (int i = 1; i < 5; i++)
            {
                for (int j = 1; j < 14; j++)
                {
                    Deck[count] = new PlayingCard(j, i, false);
                    count++;
                }
            }
            Deck[count] = new PlayingCard(0, 5, false);
            //Deck[52] = new PlayingCard(5, );
        }
コード例 #4
0
ファイル: Player.cs プロジェクト: jsdokos/CIS501_Project1
        public void DiscardAllPairs()
        {
            temp = new PlayingCard[15];

            for (int i = 0; i < temp.Length; i++)
            {
                temp[i] = null;
            }

            for (int i = 0; i < Hand.Length; i++)
            {
                PlayingCard card = Hand[i];
                Hand[i] = null;

                if (card != null)
                {
                    if (temp[(int)card.Rank] == null)
                    {
                        temp[(int)card.Rank] = card;
                    }
                    else
                    {
                        Deck.ReturnCard(temp[(int)card.Rank]);
                        Deck.ReturnCard(card);
                        temp[(int)card.Rank] = null;
                        card = null;
                    }
                }
            }
            int count = 0;

            for (int i = 0; i < temp.Length; i++)
            {
                if (temp[i] != null)
                {
                    Hand[count] = temp[i];
                    temp[i]     = null;
                    count++;
                }
            }
            topIndex = count;
        }
コード例 #5
0
ファイル: CardDeck.cs プロジェクト: jsdokos/CIS501_Project1
 public void ReturnCard(PlayingCard card)
 {
     topIndex++;
     Deck[topIndex] = card;
 }
コード例 #6
0
ファイル: Player.cs プロジェクト: jsdokos/CIS501_Project1
 public virtual void Deal(PlayingCard card)
 {
 }
コード例 #7
0
ファイル: Player.cs プロジェクト: jsdokos/CIS501_Project1
 public void AddCard(PlayingCard card)
 {
     topIndex++;
     Hand[topIndex] = card;
     DiscardAllPairs();
 }
コード例 #8
0
 public override void Deal(PlayingCard card)
 {
     card.FaceUp = true;
     topIndex++;
     Hand[topIndex] = card;
 }
コード例 #9
0
ファイル: OldMaid.cs プロジェクト: jsdokos/CIS501_Project1
        private bool keyAlgorithim()
        {
            int  drawer   = 0;
            int  drawee   = -1000;
            bool playNext = true;

            do
            {
                drawee = (drawer + 1) % currentPlayers.Count;

                if (currentPlayers[drawee].NumCardsInHand == 0)
                {
                }

                //might work
                //if (String.Compare(currentPlayers[drawee].GetType().ToString(), "HumanPlayer") == 0)
                if (currentPlayers[drawer].isHuman && currentPlayers[drawer].NumCardsInHand != 0)
                {
                    console.DisplayLine("");
                    console.DisplayLine("%%%%%%%%%%It is now the User's turn%%%%%%%%%%");
                    console.DisplayLine(currentPlayers[drawer].ToString());
                    console.DisplayLine(currentPlayers[drawee].ToString());

                    ComputerPlayer temp = (ComputerPlayer)currentPlayers[drawee];
                    console.DisplayLine(temp.MakeCardIndices()); //there has to be a better way

                    int takenCard = console.GetInt("Pick One Card from Player " + drawee + " ", 0,
                                                   currentPlayers[drawee].NumCardsInHand - 1);

                    PlayingCard card = currentPlayers[drawee].PickCardAt(takenCard);

                    currentPlayers[drawer].AddCard(card);

                    console.DisplayLine("Player " + currentPlayers[drawer].Name + " picks up Player " + currentPlayers[drawee].Name + "'s Card at [" + takenCard + "], Card: " + card.ToString());
                    console.userWait();
                }
                else if (currentPlayers[drawer].NumCardsInHand != 0)
                {
                    Random r          = new Random();
                    int    cardToTake = r.Next(currentPlayers[drawee].NumCardsInHand);

                    PlayingCard card = currentPlayers[drawee].PickCardAt(cardToTake);

                    currentPlayers[drawer].AddCard(card);
                    console.DisplayLine("");
                    console.DisplayLine("Player " + currentPlayers[drawer].Name + " picks up Player " + currentPlayers[drawee].Name + "'s Card at [" + cardToTake + "], Card: " + card.ToString());
                }

                if (currentPlayers[drawer].NumCardsInHand > 0)
                {
                    while (currentPlayers[drawee].NumCardsInHand <= 0)
                    {
                        drawee++;
                    }

                    if (drawer == drawee)
                    {
                        playNext = false;
                        break;
                    }
                }

                shuffleAllPlayerHands();
                showAllPlayerHands();

                if (currentPlayers.Count <= 1)
                {
                    playNext = false;
                    console.DisplayLine("@@@@@Player " + currentPlayers[0].Name + " is the LOSER.@@@@@");
                    currentPlayers[0].ReturnHandToDeck();
                    break;
                }

                drawer += 1;
                if (drawer > currentPlayers.Count - 1)
                {
                    drawer = 0; //might work?
                }

                //remove all player who are done
                for (int i = currentPlayers.Count - 1; i >= 0; i--)
                {
                    if (currentPlayers[i].NumCardsInHand == 0)
                    {
                        currentPlayers.Remove(currentPlayers[i]);
                        console.DisplayLine("+++++Player " + currentPlayers[i].Name + " has finished playing.+++++");
                    }
                }
            }while (playNext);

            char ans = console.getChar("Do you want to play again? (Y/N)", "YN");

            if (ans.Equals('Y'))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }