Beispiel #1
0
 public Player()
 {
     playerHand = new Deck();
 }
Beispiel #2
0
        static void Main(string[] args)
        {
            //create the deck (function write tests)
            var thisDeck = new Deck();
            thisDeck.LoadDeck();

            //create the player
            var player1 = new Player();
            player1.playerName = "first player";
            var player2 = new Player();
            player2.playerName = "second player";

            //initalise the players deck count, can this be done smarter?
            //does this need to be removed now?
            //int player1deckcount = 0;
            //int player2deckcount = 0;

            //this deal can be a function or procedure

            //set a boolean for player
            Boolean playerSwitch = true;
            Boolean cardsDealt = true;
            int x = 0;
            int[] dealtCards;
            dealtCards = new int[6];
            Boolean deckDealt = false;

            while (x<=5) {//this loop will not go on the number of the cards because of randomness of the assigning

                //check deck is not all dealt if it is exit the loop
                for (int z=0; z<= 5; z++)
                {
                    if (thisDeck.myDeck[z].dealt)
                    {
                        deckDealt = true;
                    }
                    else deckDealt = false;
                }

                if (!deckDealt)
                {

                    if (playerSwitch)
                    {
                        player1.playerHand.myDeck.Add(thisDeck.myDeck[x]); //with this the player
                        dealtCards[x] = thisDeck.myDeck[x].cardId;
                        playerSwitch = false;
                    }
                    else
                    {
                        player2.playerHand.myDeck.Add(thisDeck.myDeck[x]); //with this the player
                        dealtCards[x] = thisDeck.myDeck[x].cardId;
                        playerSwitch = true;
                    }
                    thisDeck.myDeck[x].dealt = true;
                    Console.WriteLine("the card id is - " + dealtCards[x].ToString());
                }
                x++;
            };

            //loop through the whole deck but with randomly assigning card it could take ages (i need to improve)
            //for (int x = 0; x <= 3; x++) {
            //    if (playerSwitch)
            //    {
            //        player1.playerHand.myDeck.Add(thisDeck.myDeck[x]); //with this the player
            //        dealtCards[x] = thisDeck.myDeck[x].cardId;
            //        playerSwitch = false;
            //    }
            //    else
            //    {
            //        player2.playerHand.myDeck.Add(thisDeck.myDeck[x]); //with this the player
            //        playerSwitch = true;
            //    }
            //    Console.WriteLine("the card id is - " + dealtCards[x].ToString());
            //}

            //put the showing the deck on the player?
            player1.showDeck();
            player2.showDeck();

            Console.ReadKey();

            #region the rest of the code
                        //int y = 0;
                        //int a = 0;

                        ////deal the cards
                        //do
                        //{
                        //    if (y<=1) {
                        //        Console.WriteLine("this player is ->" + player1.playerName + " ! " + player1.playerHand.myDeck[y].cardName + " ! " + player1.playerHand.myDeck[y].cardStrengthValue);
                        //    }
                        //    if (y >= 2 && y <= 3)
                        //    {
                        //        Console.WriteLine("this player is ->" + player2.playerName + " ! " + player2.playerHand.myDeck[a].cardName + " ! " + player2.playerHand.myDeck[a].cardStrengthValue);
                        //        a++;
                        //    }
                        //    y++;
                        //} while (y <= 3);
                        //Console.WriteLine("the games afoot !!!");
                        //Console.ReadKey();

                        ////game loop
                        ////string exitgame = "";
                        ////while (exitgame != "exit")
                        //player1deckcount = player1.showDeckCount();
                        //player2deckcount = player2.showDeckCount();

                        //while (player1deckcount != 0 && player2deckcount != 0)
                        //{
                        //    //
                        //    Random rnd = new Random();
                        //    int cardindex = rnd.Next(0, 1);
                        //    Console.WriteLine("player 1 card is " + player1.playerHand.myDeck[cardindex].cardName + " ! " + player1.playerHand.myDeck[cardindex].cardStrengthValue);
                        //    cardindex = rnd.Next(0, 1);
                        //    Console.WriteLine("player 2 card is " + player2.playerHand.myDeck[cardindex].cardName + " ! " + player2.playerHand.myDeck[cardindex].cardStrengthValue);

                        //    if (player1.playerHand.myDeck[cardindex].cardStrengthValue > player2.playerHand.myDeck[cardindex].cardStrengthValue) {
                        //        Console.WriteLine("player 1 wins!");
                        //        //add card to the other player
                        //        player1.playerHand.AddCard(player2.playerHand.myDeck[cardindex].cardName, player2.playerHand.myDeck[cardindex].cardStrengthValue);
                        //        player2.playerHand.myDeck.Remove(player2.playerHand.myDeck[cardindex]);
                        //        player1.showDeck();//TODO: DRY break!
                        //    }
                        //    else
                        //    {
                        //        Console.WriteLine("player 2 wins!");
                        //        player2.playerHand.AddCard(player1.playerHand.myDeck[cardindex].cardName, player1.playerHand.myDeck[cardindex].cardStrengthValue);
                        //        player1.playerHand.myDeck.Remove(player1.playerHand.myDeck[cardindex]);
                        //        player2.showDeck();//TODO: DRY break!
                        //    }
                        //    player1deckcount = player1.showDeckCount();
                        //    player2deckcount = player2.showDeckCount();
                        //    //Console.Write("enter ->: ");
                        //    //exitgame = Console.ReadLine();
                        //    Console.ReadLine();
                        //}
                        //Console.Write("finished !");
                        //Console.ReadLine();
            #endregion
        }