简单的发牌程序 54张牌发给3个人

来源:互联网 发布:小满软件 编辑:程序博客网 时间:2024/05/17 02:56

简单的发牌程序 54张牌发给3个人 -------注重思路 着重是对动态数组的使用


namespace 制作一个发牌程序
{
    class Program
    {
        static void Main(string[] args)
        {
            List<int> pukeList = new List<int>();
            for (int i = 0; i < 54; i++)
            {
                pukeList.Add(i);
            }


            List<int> playerA = new List<int>();
            List<int> playerB = new List<int>();
            List<int> playerC = new List<int>();


            List<int> currentPlayer = playerA;
            Random r = new Random();
            while (pukeList.Count > 0)
            {
                int random = r.Next(0, pukeList.Count);
                currentPlayer.Add(pukeList[random]);
                pukeList.RemoveAt(random);


                currentPlayer = currentPlayer == playerA ? playerB : (currentPlayer == playerB ? playerC : playerA);
            }
            Console.Write("A的牌有:");
            foreach (int i in playerA)
            {
                Console.Write(" " + i);
            }
            Console.WriteLine("");
            Console.Write("B的牌有:");
            foreach (int i in playerB)
            {
                Console.Write(" " + i);
            }
            Console.WriteLine("");
            Console.Write("C的牌有:");
            foreach (int i in playerC)
            {
                Console.Write(" " + i);
            }
            Console.WriteLine("");
            Console.ReadLine();
        }
    }
}

原创粉丝点击