Пример #1
0
        public void ResetStacks()
        {
            _mainStack.Clear();
            _offStack.Clear();

            List <Card> listOfCards = new List <Card>(UnoDefaultNumberOfCards);

            CreateListOfCards(listOfCards);

            listOfCards = CardShuffler.Shuffle(listOfCards);

            _mainStack = ListToStack(listOfCards);
        }
Пример #2
0
        public Game(int numPlayers, string[] playerNames)
        {
            // First we need to initialize the mainStack:
            List <Card> listOfCards = new List <Card>(UnoDefaultNumberOfCards);

            CreateListOfCards(listOfCards);

            // We should also allocate space for the off stack:
            _offStack = new Stack <Card>(UnoDefaultNumberOfCards);

            // We should shuffle the list of cards:
            listOfCards = CardShuffler.Shuffle(listOfCards);

            // Now convert it to a stack.
            _mainStack = ListToStack(listOfCards);

            // Set the number of players:
            AmountOfPlayers = numPlayers;
            ActivePlayerID  = 0;

            // Setup the players:
            Players = new List <Player>(numPlayers);

            foreach (string name in playerNames)
            {
                Players.Add(new Player(name));
            }

            GameHasBeenWon = false;

            // Eventuelle fejl:
            if (playerNames.Length != numPlayers)
            {
                throw new ArgumentException("Der er ikke suppleret nok spiller-navne, kontra hvor mange" +
                                            " spillere der er blevet bedt om");
            }
            if (numPlayers > UnoMaxPlayers || numPlayers < UnoMinPlayers)
            {
                throw new ArgumentException("Der er ikke suppleret et korrekt antal spillere, vælg mellem 2-10 spillere.");
            }
        }
Пример #3
0
        public Card DrawCardFromMainStack()
        {
            if (_mainStack.Count == 0)
            {
                Console.WriteLine("There's no cards left in the main stack.\nSo we'll put the cards from the off stack into the mainstack now.");

                // Shuffle the off stack:
                List <Card> temporaryList = new List <Card>(_offStack.Count);

                foreach (Card c in _offStack)
                {
                    temporaryList.Add(c);
                }

                temporaryList = CardShuffler.Shuffle(temporaryList);

                foreach (Card ca in temporaryList)
                {
                    _mainStack.Push(ca);
                }
            }

            return(_mainStack.Pop());
        }