예제 #1
0
        public UnoSingleGame(Int32 PlayersAmount, List <Panel> playersPanel, List <Label> playersLabels, String mainUserName)
        {
            if (PlayersAmount < 2)
            {
                this.playersAmount = 2;
            }
            else
            {
                if (PlayersAmount > 6)
                {
                    this.playersAmount = 6;
                }
                else
                {
                    this.playersAmount = PlayersAmount;
                }
            }

            this.players = new List <UnoUserPlayer>();

            for (int i = 0; i < this.playersAmount; i++)
            {
                if (i == 0)
                {
                    this.players.Add(new UnoUserPlayer(mainUserName, playersPanel[i], playersLabels[i]));
                }
                else
                {
                    this.players.Add(new UnoComputerPlayer(NamesUsers[R.Next(0, NamesUsers.Length)], playersPanel[i], playersLabels[i]));
                }

                playersPanel[i].Visible  = true;
                playersLabels[i].Visible = true;
            }

            this.side = Side.Front;

            this.mainPanel      = playersPanel[playersPanel.Count - 1];
            this.lbCurrentColor = playersLabels[playersLabels.Count - 2];
            this.lbTopCard      = playersLabels[playersLabels.Count - 1];

            this.mainDeck = new UnoCardDeck();
            this.outage   = new List <UnoCard>();

            this.FillPanels();

            UnoCard tmp = this.mainDeck.Deck.First();

            this.mainDeck.Deck.RemoveAt(0);

            this.lbTopCard.Image = tmp.CurrentImage;

            foreach (var item in this.players)
            {
                item.topCard = tmp;
            }

            this.setColor(tmp.Color);
            this.activePlayer = 0;
        }
예제 #2
0
        private void tmpLb_DoubleClick(object sender, EventArgs e)
        {
            Int32   ind = this.playerPanel.Controls.IndexOf(sender as Label);
            UnoCard uno = this.CardsList[ind];

            if (TopCardType == CardType.ChooseColor || TopCardType == CardType.PlusFour)
            {
                if (uno.Color == CurrentColor || uno.Color == CardColors.Black)
                {
                    CardReturn = ind;
                }
                else
                {
                    return;
                }
            }
            else
            {
                if (uno.Color == CurrentColor || uno.Type == TopCardType || uno.Color == CardColors.Black)
                {
                    CardReturn = ind;
                }
                else
                {
                    return;
                }
            }

            this.Close();
        }
예제 #3
0
        public override UnoCard Move(Label currentColor)
        {
            UnoCard    crd      = this.topCard;
            CardColors colorTmp = crd.Color;

            if (crd.Color == CardColors.Black)
            {
                colorTmp = Helper.ToCardColor(currentColor.BackColor);
            }

            var colorsCards = this.Cards.Where(c => c.Color == colorTmp);

            if (colorsCards.Count() > 0)
            {
                return(colorsCards.First());
            }

            var typeCards = this.Cards.Where(t => t.Type == crd.Type);

            if (typeCards.Count() > 0)
            {
                return(typeCards.First());
            }

            var blackCards = this.Cards.Where(t => t.Color == CardColors.Black);

            if (blackCards.Count() > 0)
            {
                return(blackCards.First());
            }

            return(null);
        }
예제 #4
0
        // методы класса

        public virtual void TakeCard(UnoCard card)      // виртуальный метод для добавления карты в список карт игрока
        {
            Label currentLb;

            this.playerCards.Add(card);
            currentLb         = this.playerPanel.Controls[this.playerCards.Count - 1] as Label;
            currentLb.Image   = card.CurrentImage;
            currentLb.Visible = true;
        }
예제 #5
0
        public async void playersMove()
        {
            Boolean countCards = false;
            Int32   currLastPlayer;

            while (!countCards)
            {
                currLastPlayer = this.activePlayer;
                this.players[currLastPlayer].PlayerLabel.Font = new System.Drawing.Font("Modern No. 20", 16);

                if (this.activePlayer != 0)
                {
                    await Task.Delay(R.Next(1000, 3000));
                }

                UnoCard tmp = this.players[this.activePlayer].Move(this.lbCurrentColor);
                Console.WriteLine(players[activePlayer].Name + " " + (tmp == null ? "null" : tmp.ToString()));
                if (tmp != null)
                {
                    tmp.IsHidden = false;
                    players[activePlayer].DeleteCard(tmp);
                    this.PlayerMove(tmp);
                    this.lbTopCard.Image = tmp.CurrentImage;
                }
                else
                {
                    this.players[activePlayer].TakeCard(this.mainDeck.Deck.First());
                    mainDeck.Deck.RemoveAt(0);
                    this.changePlayer();
                }

                countCards = players.Where(c => c.Cards.Count == 0).Count() > 0;
                this.players[currLastPlayer].PlayerLabel.Font = new System.Drawing.Font("Modern No. 20", 11);
            }

            StringBuilder strB = new StringBuilder();

            foreach (var item in players.Where(c => c.Cards.Count != 0).ToArray())
            {
                strB.Append(item.Name + " " + item.Points.ToString() + ";\n");

                if (item.GetType() == typeof(UnoComputerPlayer))
                {
                    for (int i = 0; i < item.Cards.Count; i++)
                    {
                        item.Cards[i].IsHidden = false;
                        ((Label)item.PlayerPanel.Controls[i]).Image = item.Cards[i].CurrentImage;
                    }
                }
            }

            MessageBox.Show(strB.ToString());
            Application.Exit();
        }
예제 #6
0
        public void DeleteCard(UnoCard tmp)         // виртуальный метод для удаления карты из списка карт игрока
        {
            Label tmpLbLeft, tmpLbRight;
            Int32 index = this.Cards.FindIndex(c => c == tmp);

            for (int i = index; i < this.Cards.Count; i++)
            {
                tmpLbLeft  = this.playerPanel.Controls[i] as Label;
                tmpLbRight = this.playerPanel.Controls[i + 1] as Label;

                tmpLbLeft.Visible = tmpLbRight.Visible;
                tmpLbLeft.Image   = tmpLbRight.Image;
            }

            this.playerCards.RemoveAt(index);
        }
예제 #7
0
        public void SortDeck()         // сортировка колоды
        {
            UnoCard Tmp = null;
            Random  R = new Random();
            int     randNum1 = 0, randNum2 = 0;

            for (int i = 0; i < 200; i++)       // цикл на 200 итераций для перетасовки
            {
                randNum1 = R.Next(0, this.Cards.Count);
                randNum2 = R.Next(0, this.Cards.Count);

                Tmp = this.Cards[randNum1];
                this.Cards[randNum1] = this.Cards[randNum2];
                this.Cards[randNum2] = Tmp;
            }
        }
예제 #8
0
        private async void FillPanels()
        {
            for (int j = 0; j < 8; j++)
            {
                for (int i = 0; i < this.playersAmount; i++)
                {
                    UnoCard tmp = this.mainDeck.Deck.ElementAt(0);

                    if (i != 0)
                    {
                        tmp.IsHidden = true;
                    }

                    this.players[i].TakeCard(tmp);
                    this.mainDeck.Deck.RemoveAt(0);
                    await Task.Delay(100);
                }
            }
        }
예제 #9
0
        private void PlayerMove(UnoCard playerCard)
        {
            this.outage.Add(playerCard);

            if (mainDeck.Deck.Count == 0)
            {
                mainDeck.Deck = outage;
                mainDeck.SortDeck();
                outage.Clear();
            }

            foreach (var item in this.players)
            {
                item.topCard = playerCard;
            }

            if (playerCard.Type != CardType.PlusTwo && playerCard.Type != CardType.Reverse && playerCard.Type != CardType.Stop && playerCard.Color != CardColors.Black)
            {
                this.setColor(playerCard.Color);
                changePlayer();
            }
            else
            {
                if (playerCard.Color == CardColors.Black)
                {
                    if (playerCard.Type == CardType.PlusFour)
                    {
                        this.setColor(this.players[this.activePlayer].ChooseColor());
                        this.changePlayer();
                        for (int i = 0; i < 4; i++)
                        {
                            this.players[activePlayer].TakeCard(this.mainDeck.Deck.First());
                            mainDeck.Deck.RemoveAt(0);
                        }
                        this.changePlayer();
                    }
                    else
                    {
                        this.setColor(this.players[this.activePlayer].ChooseColor());
                        changePlayer();
                    }
                }
                else
                {
                    this.setColor(playerCard.Color);
                }


                if (playerCard.Type == CardType.PlusTwo)
                {
                    changePlayer();
                    for (int w = 0; w < 2; w++)
                    {
                        this.players[activePlayer].TakeCard(this.mainDeck.Deck.First());
                        mainDeck.Deck.RemoveAt(0);
                    }
                    changePlayer();
                }

                if (playerCard.Type == CardType.Reverse)
                {
                    if (this.side == Side.Front)
                    {
                        this.side = Side.Back;
                    }
                    else
                    {
                        this.side = Side.Front;
                    }
                    changePlayer();
                }

                if (playerCard.Type == CardType.Stop)
                {
                    for (int w = 0; w < 2; w++)
                    {
                        this.changePlayer();
                    }
                }
            }
        }
예제 #10
0
 public override void TakeCard(UnoCard card)
 {
     card.IsHidden = true;
     base.TakeCard(card);
 }