简单的发牌程序 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();
}
}
}