首页 > 学院 > 开发设计 > 正文

扑克牌程序

2019-11-06 06:24:55
字体:
来源:转载
供稿:网友

将一副52张的扑克牌洗牌后分给4个玩家

这里写代码片using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace PuKe{ class PRogra { static void Main(string[] args) { string heart = Encoding.ASCII.GetString(new byte[] { (byte)(3) });//红心 string diamond = Encoding.ASCII.GetString(new byte[] { (byte)(4) });//方块 string club = Encoding.ASCII.GetString(new byte[] { (byte)(5) });//黑桃 string spide = Encoding.ASCII.GetString(new byte[] { (byte)(6) });//梅花 string[] model = { heart, diamond, club, spide }; string[] num = { "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K" }; List<string> card1 = new List<string>();//存放初始卡牌 List<string> card2 = new List<string>();//存放洗牌后的卡牌 for (int i = 0; i < model.Length; i++) { for (int j = 0; j < num.Length; j++) { card1.Add(model[i] + num[j]); } } Random random = new Random(); /* Console.WriteLine(card1.Count); Console.WriteLine(model.Length ); Console.WriteLine(num.Length); */ for (int i = 0; i < model.Length * num.Length; i++) { int Random_x = random.Next(0, card1.Count); card2.Add(card1[Random_x]); card1.RemoveAt(Random_x);//取出已产生的随机数,避免重复 } Console.WriteLine("玩家1:"); int[] ss = new int[13]; for (int i = 0; i < 13; i++) { Console.Write(card2 [i] +" "); } Console.WriteLine(); Console.WriteLine("玩家2:"); for (int i = 13; i < 26; i++) { Console.Write(card2[i] + " "); } Console.WriteLine(); Console.WriteLine("玩家3:"); for (int i = 26; i < 39; i++) { Console.Write(card2[i] + " "); } Console.WriteLine(); Console.WriteLine("玩家4:"); for (int i = 39; i < 52; i++) { Console.Write(card2[i] + " "); } Console.ReadLine(); } }}

这里写图片描述


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表