示例#1
0
        /// <summary>
        /// Starts a new game with the specified amount of players.
        /// </summary>
        /// <param name="numberOfPlayers">
        /// The number of starting players. Must be larger than 1.
        /// </param>
        /// <exception cref="ArgumentOutOfRangeException">If the number of players is less than 1 or higher
        /// than <see cref="MaximalPlayersLimit"/></exception>
        public void BeginGame(int numberOfPlayers)
        {
            if (numberOfPlayers < 1)
            {
                throw new ArgumentOutOfRangeException("numberOfPlayers", "Must have at least one player");
            }
            if (numberOfPlayers > MaximalPlayersLimit)
            {
                throw new ArgumentOutOfRangeException("numberOfPlayers", "Can't add players over the maximal player limit");
            }
            // shuffle the deck of cards.
            deck.Shuffle(numberOfPlayers * 2);
            // prepare the player card holders
            playerCards = new List <Card> [numberOfPlayers];
            // prepare the player fold state
            foldedPlayers = new bool[numberOfPlayers];

            for (int i = 0; i < playerCards.Length; ++i)
            {
                playerCards[i]   = new List <Card>();
                foldedPlayers[i] = false;
            }
            families.Clear();
            // Get the defined order of hand families for this game and store it according to their family value
            foreach (HandFamily family in GetFamilies())
            {
                if (families.ContainsKey(family.FamilyValue))
                {
                    throw new InvalidOperationException("Derived class must assign unique values to the families returned by GetFamilies()");
                }
                families.Add(family.FamilyValue, family);
            }
            // start the game
            OnBeginGame();
        }
示例#2
0
        public static void NewGame()
        {
            if (DeckCollection.Instance.MyDeck.Count == 0)
            {
                Console.WriteLine("\nPlease create a deck before starting a game.");
                GameEngine.Run();
            }
            //Pregame selection:

            // - Player Choose Decks and the decks are being shuffled
            Console.WriteLine("Player 1 please choose your deck:");

            foreach (string key in deckCollection.MyDeck.Keys)
            {
                Console.WriteLine(key);
            }

            Deck.Deck player1Deck = deckCollection.MyDeck[Console.ReadLine()]; //Трябва да погледнем как се прави deep copy тук,
            player1Deck.Shuffle();                                             //защото shallow copy ще прецеката колекциите в тестетата
            Console.WriteLine("Player 2 please choose your deck:");
            Deck.Deck player2Deck = deckCollection.MyDeck[Console.ReadLine()];
            player2Deck.Shuffle();

            player1.PlayerDeck = player1Deck;
            player2.PlayerDeck = player2Deck;
            // - Player Draw Cards
            for (int i = 0; i < 3; i++)
            {
                player1.DrawACards();
                player2.DrawACards();
            }


            string playerTurn = "P1";

            while (true)
            {
                if (playerTurn == "P1")
                {
                    Console.WriteLine("Player 1 Turn");
                    StartOfTurn(player1);
                    Console.WriteLine("===========================");
                    PlayTurn(player1, player2);
                    playerTurn = "P2";
                    if (player2.Lifepoints <= 0)
                    {
                        Console.WriteLine("Player 1 Won the game");
                        break;
                    }
                }
                else
                {
                    Console.WriteLine("Player 2 Turn");
                    StartOfTurn(player2);
                    Console.WriteLine("===========================");
                    PlayTurn(player2, player1);
                    playerTurn = "P1";
                    if (player1.Lifepoints <= 0)
                    {
                        Console.WriteLine("Player 2 won the game!");
                        break;
                    }
                }
            }
            GameEngine.Run();
        }