예제 #1
0
파일: Cards.cs 프로젝트: CrazyStilet/CSharp
        public List<Cards> CreateKoloda()
        {
            string[] masTypes = Enum.GetNames(typeof(Types));
            string[] masMasts = Enum.GetNames(typeof(Masts));

            for (int i = 0; i < masTypes.Length; i++)
            {
                for (int j = 0; j < masMasts.Length; j++)
            {
                    Cards card = new Cards();
                    object temp = Enum.Parse(typeof(Types), masTypes[i]);
                    card.typesCard = (Types)temp;
                    object tempM = Enum.Parse(typeof(Masts), masMasts[j]);
                    card.typesMast = (Masts)tempM;
                    cards.Add(card);
            }
            }

            return cards;
        }
예제 #2
0
파일: Cards.cs 프로젝트: CrazyStilet/CSharp
 public List<Cards> Sort()
 {
     for(int i = 0; i < cards.Count; i++)
     {
         Random rand = new Random();
         int rnd = rand.Next(0, cards.Count);
         Cards temp = new Cards();
         temp = cards[i];
         cards[i] = cards[rnd];
         cards[rnd] = temp;
     }
     return cards;
 }
예제 #3
0
파일: Game.cs 프로젝트: CrazyStilet/CSharp
        public static void Start()
        {
            List<Player> listPlayers = new List<Player>();
            int countPlayers = 6;

            #region Создание и сортировка колоды
            Cards koloda = new Cards();
            koloda.CreateKoloda();
            //koloda.ShowCards();
            //Console.WriteLine();
            koloda.Sort();
            //koloda.ShowCards();
            #endregion
            #region Cоздание игроков и раздача им карт
            do
            {
                Console.WriteLine("Введите количество игроков от 2 до 6");
                try
                {
                    countPlayers = Convert.ToInt32(Console.ReadLine());
                }
                catch(Exception e)
                {
                    Console.WriteLine(e.Message);
                }
                if(countPlayers == 5)
                {
                    Console.WriteLine("36 карт на 5 поровну не делятся");
                }
            } while((countPlayers > 6 || countPlayers < 2) || countPlayers == 5);
            for(int i = 0; i < countPlayers; i++)
            {
                listPlayers.Add(new Player());
                listPlayers[i].ListCards.AddRange(koloda.Razdacha(countPlayers));
            }
            #endregion
            #region Игра
            int winner = 0;
            while(listPlayers[winner].CountPlayerCards!=36)
            {
                Console.Clear();
                List<Cards> Table = new List<Cards>(countPlayers);
                for(int i = 0; i < countPlayers; i++)
                {
                    if(listPlayers[i].CountPlayerCards!=0)
                    {
                        Table.Add(listPlayers[i].ListCards[0]);
                        listPlayers[i].ListCards.RemoveAt(0);
                    }
                    else
                    {
                        Cards card=new Cards();
                        Table.Add(card);
                    }
                }
                for(int i = 0; i < countPlayers; i++)
                {
                    if(listPlayers[i].CountPlayerCards != 0)
                    {
                        Console.WriteLine("{0} игрок {1} карт:", i + 1, listPlayers[i].CountPlayerCards);
                        listPlayers[i].ShowPlayerCards();
                        Console.WriteLine();
                    }
                }
                Console.WriteLine("\nКарты на столе:");
                for(int i = 0; i < Table.Count; i++)
                {
                    if(Table[i].typesCard!=0)
                    {
                        Console.Write("{0} {1}\t", Table[i].typesCard, Table[i].typesMast);
                    }
                }
                for(int i = countPlayers - 1; i >= 0; i--)
                {
                    if(Table[i].typesCard != 0)
                    {
                        if(Table[i].typesCard>=Table[winner].typesCard)
                        {
                            winner = i;
                        }
                    }
                }
                Console.WriteLine("Победил игрок № {0}\n", winner + 1);
                for(int i = 0; i < Table.Count; i++)
                {
                    if(Table[i].typesCard!=0)
                    {
                        listPlayers[winner].ListCards.Add(Table[i]);
                    }
                }
                //for(int i = 0; i < countPlayers; i++)
                //{
                //    if(listPlayers[i].CountPlayerCards!=0)
                //    {
                //        Console.WriteLine("{0} игрок {1} карт:", i + 1, listPlayers[i].CountPlayerCards);
                //        listPlayers[i].ShowPlayerCards();
                //        Console.WriteLine();
                //    }
                //}
                //Console.ReadLine();
            #endregion
            }
            #region Победа
            Console.WriteLine("Игрок № {0} - ПОБЕДИТЕЛЬ!!!", winner + 1);
            Console.ReadLine();
            #endregion
        }