Пример #1
2
 public Player(String name, Random random, Game game)
 {
     this.name = name;
     this.random = random;
     this.game = game;
     this.cards = new Deck(new Card[] { });
     game.AddProgress(name + " has just joined the game");
 }
Пример #2
0
        public void AskForACard(IEnumerable<Player> players, int myIndex, Deck stock, Values value)
        {
            List<Player> _players = (List<Player>)players;

            textBoxOnForm.Content +=  name + " asks if anyone has a " + value + "." + Environment.NewLine;

            int cardsAdded = 0;
            for (int playerIndex = 0; playerIndex < _players.Count; playerIndex++)
            {
                if (playerIndex != myIndex)
                {
                    Deck cardsGiven = _players[playerIndex].DoYouHaveAny(value);
                    if (cardsGiven.Count > 0)
                    {
                        while (cardsGiven.Count > 0)
                        {
                            cards.Add(cardsGiven.Deal());
                            cardsAdded++;
                        }
                    }
                }
            }
            textBoxOnForm.Content += Environment.NewLine;

            if (cardsAdded == 0 && stock.Count > 0)
            {
                textBoxOnForm.Content += name + " has to draw from the stock." + Environment.NewLine;
                cards.Add(stock.Deal());
            }
        }
Пример #3
0
 public Player(String name, Random random, TextBox textBoxOnForm)
 {
     this.name = name;
     this.random = random;
     this.textBoxOnForm = textBoxOnForm;
     this.cards = new Deck(new Card[] { });
     textBoxOnForm.Text += name + " has joined the game." + Environment.NewLine;
 }
Пример #4
0
 public Deck PullOutValues(Values value)
 {
     Deck deckToReturn = new Deck(new Card[] { });
     for (int i = cards.Count - 1; i >= 0; i--)
         if (cards[i].Value == value)
             deckToReturn.Add(Deal(i));
     return deckToReturn;
 }
Пример #5
0
 public void AskForACard(List<Player> players, int myIndex, Deck stock)
 {
     if (stock.Count > 0)
     {
         if (cards.Count == 0)
             cards.Add(stock.Deal());
         Values randomValue = GetRandomValue();
         AskForACard(players, myIndex, stock, randomValue);
     }
 }
        public void AskForACard(List<Player> players, int myIndex, Deck stock)
        {
            /*
                Eis uma versão sobrecarregada de AskForACard() - escolha
                um valor aleatório do baralho usando GetRandomValue()
                pergunte usando AskForACard().
            */

            /**/Values randomValue = /**/GetRandomValue();

            AskForACard(players, myIndex, stock, randomValue);
        }
Пример #7
0
 public Game(string playerName, IEnumerable<string> opponentNames, TextBox textBoxOnForm)
 {
     Random random = new Random();
     this.textBoxOnForm = textBoxOnForm;
     players = new List<Player>();
     players.Add(new Player(playerName, random, textBoxOnForm));
     foreach (string player in opponentNames)
         players.Add(new Player(player, random, textBoxOnForm));
     books = new Dictionary<Values, Player>();
     stock = new Deck();
     Deal();
     players[0].SortHand();
 }
Пример #8
0
 public void AskForACard(List<Player> players, int myIndex, Deck stock, Value value)
 {
     this.textBoxOnForm.Text += Name + " asks if anyone has a " + value + Environment.NewLine;
     int totalCardsGiven = 0;
     for (int i = 0; i < players.Count; i++)
     {
         if (i != myIndex)
         {
             Player player = players[i];
             Deck cardsGiven = player.DoYouHaveAny(value);
             totalCardsGiven += cardsGiven.Count;
             while (cardsGiven.Count > 0) this.cards.Add(cardsGiven.Deal());
         }
     }
     if (totalCardsGiven == 0) this.textBoxOnForm.Text += Name + " must draw from the stock." + Environment.NewLine;
     this.cards.Add(stock.Deal());
 }
        public void AskForACard(List<Player> players, int myIndex, Deck stock, Values value)
        {
            /*
                Pergunte para os outros jogadores se eles têm uma valor.
                Primeiro, adicione uma linha a TextBox: "João pergunta se alguém tem algum 8".
                Então, percorra a lista de jogadores passada como parâmetro e pergunte a cada um
                deles se ele tem o valor (usando seu método DoYouHaveAny()). Ele deve passar um baralho
                - adicione ao seu. Controle quantas cartas foram adicionadas. Se não houver nenhuma, você
                mesmo terá lidar com uma do stock (que também foi passado como parâmetro) e você terá que
                adicionar uma linha a TextBox: "João tem que pegar uma carta do stock"
            */

            txtBoxOnForm.Text += string.Format("{0} pergunta se alguém tem algum {1}." + Environment.NewLine, Name, value);

            //foreach (Player player in players)
            //{
            //    player.DoYouHaveAny(value);
            //}

            /**/
            int totalCardsGiven = 0;

            for (int i = 0; i < players.Count; i++)
            {
                if (i != myIndex)
                {
                    Player player = players[i];
                    Deck CardsGiven = player.DoYouHaveAny(value);
                    totalCardsGiven += CardsGiven.Count;
                    while (CardsGiven.Count > 0)
                    {
                        deckCards.Add(CardsGiven.Deal());
                    }
                }
            }
            /**/
            if (totalCardsGiven == 0)
            {
                txtBoxOnForm.Text += Name + " deve tirar do stock." + Environment.NewLine;
            }
            deckCards.Add(stock.Deal());
        }
        public Player(string name, Random random, TextBox txtBoxOnForm)
        {
            /*
                O CONSTRUTOR INICIALIZA QUATRO CAMPOS PRIVATOS, E ADICIONA UMA LINHA
                AO CONTROLE TEXTBOX NO FORMULÁRIO QUE DIZ "JOÃO ENTROU NO JOGO" - MAS
                USE O NOME NO CAMPO PRIVADO E NÃO SE ESQUEÇA DE ADICIONAR UMA QUEBRA
                DE LINHA NO FIM DE CADA LINHA ADICIONADA A TEXTBOX.
            */

            this.name = name;
            this.random = random;
            /*
                INIZIALIZAÇÃO REFEITA DE ACORDO COM O LIVRO
             */
            //deckCards = new Deck();
            deckCards = new Deck(new Card[] { });
            this.txtBoxOnForm = txtBoxOnForm;

            txtBoxOnForm.Text += string.Format("{0} entrou no jogo!\r\n", Name);
        }
Пример #11
0
 public void AskForACard(List<Player> players, int myIndex, Deck stock, Values value)
 {
     game.AddProgress(Name + " asks if anyone has a " + value);
     int totalCardsGiven = 0;
     for (int i = 0; i < players.Count; i++)
     {
         if (i != myIndex)
         {
             Player player = players[i];
             Deck CardsGiven = player.DoYouHaveAny(value);
             totalCardsGiven += CardsGiven.Count;
             while (CardsGiven.Count > 0)
                 cards.Add(CardsGiven.Deal());
         }
     }
     if (totalCardsGiven == 0)
     {
         game.AddProgress(Name + " must draw from the stock.");
         cards.Add(stock.Deal());
     }
 }
Пример #12
0
        public void AskForACard(IEnumerable<Player> players, int myIndex, Deck stock)
        {
            List<Player> _players = (List<Player>)players;

            // Round is only played if the stock still has cards.
            if (stock.Count > 0)
            {
                // Player asking must have at least one card.'Player asking must have at least one card.
                if (cards.Count == 0)
                {
                    cards.Add(stock.Deal());
                }
                AskForACard(players, myIndex, stock, GetRandomValue());

                // As long as the stock still has cards after the last move, if the human player must have at least one card.
                // This is needed for the next round to be started. Cases of the AIs running out of cards is handled when they are asking for cards, above.
                if (stock.Count > 0 && _players[0].CardCount == 0)
                {
                    _players[0].cards.Add(stock.Deal());
                }
            }
        }
Пример #13
0
 public void AskForACard(List<Player> players, int myIndex, Deck stock)
 {
     Value randomValue = this.GetRandomValue();
     this.AskForACard(players, myIndex, stock, randomValue);
 }
Пример #14
0
 public void ResetGame()
 {
     GameInProgress = false;
     OnPropertyChanged("GameInProgress");
     OnPropertyChanged("GameNotStarted");
     books = new Dictionary<Values, Player>();
     stock = new Deck();
     Hand.Clear();
 }
Пример #15
0
 public Deck PullOutValues(Value value)
 {
     Deck deckToReturn = new Deck(new Card[] { });
     for (int i = this.cards.Count - 1; i >= 0; i--)
     {
         if (this.cards[i].Value == value)
         {
             deckToReturn.Add(this.Deal(i));
         }
     }
     return deckToReturn;
 }