前段时间,很多公司都在招聘使用Unity3D开发卡牌游戏的程序员,我身边的很多朋友也都在这类棋牌游戏公司工作,刚好最近有闲,写一下简单的发牌算法。
本片博客一共分为三部分:
1:简单的发牌算法(将52张牌发放到玩家手中)
2:通过牌的大小进行排序
3:通过牌的花色进行排序
1:发牌算法
思路整理:可以将所有的卡牌存放到一个列表中,通过循环/随机数的方式来发牌,每循环一次,就从别表中将发过的牌移除
“`
using System;
using System.Collections;
using System.Collections.Generic;
namespace DealArithmetic发牌算法
{
//枚举花色方便调用
public enum Color{
红桃 = -1,
黑桃 = -2,
梅花 = -3,
方块 = -4,
}
//枚举牌面方便调用
enum Point{
A ,
Two,
Three ,
Four,
Five,
Six,
Seven,
Eight,
Nine,
Ten,
J ,
Q ,
K ,
}
//声明一个扑克结构体
struct Poker{
//声明两个string类型的变量
private string pocker_color,poker_point;
//声明构造方法
public Poker(string _color,string _point){
this.pocker_color = _color;
this.poker_point = _point;
}
//打印牌的信息
public void Printpoker(){
Console.WriteLine ("花色:{0},大小:{1}",this.pocker_color,this.poker_point);
}
}
class MainClass
{
public static void Main (string[] args)
{
//实例化一个ArrayList存储所有的扑克
List<Poker> myPokerList = new List<Poker>();
//存放每个人的牌的集合
List<Poker> person1 = new List<Poker>(