棋牌游戏大厅开户

您现在的位置: 网上现金棋牌游戏平台 >> 棋牌技巧 >> 游戏设计 >> 正文

C#中梭哈游戏的实现

分享到:
时间:2013-2-7  看看谷歌  瞅瞅搜狗  眯眯搜搜
内容简介:梭哈,又称沙蟹,五张,是扑克游戏的一种。以五张牌的排列、组合决定胜负。今天我们来讲一下C#中如何实现梭哈游戏. 本文由网上现金棋牌游戏平台www.crjq8.com编辑整理,介绍各种网上真钱棋牌游戏技巧,澳门赌场赌博技巧,提供各种网上博彩游戏,网上真钱游戏,免费试玩。希望C#中梭哈游戏的实现这篇文章能给你提供帮助。

棋牌游戏精简版下载 棋牌游戏完整版大厅下载

梭哈,又称沙蟹,五张,是扑克游戏的一种。以五张牌的排列、组合决定胜负。今天我们来讲一下C#中如何实现梭哈游戏.

using System;
using System.Collections.Generic;

using System.Text;

namespace ConsoleApplication1
{
    public class Rule
    {
        #region ------------------------私有字段(牌的最大值,牌型,颜色,是否是同色)----------
        private PaiType paiType = PaiType.Not;  //牌型
        private int maxPai = 0;                //玩家手中的最大牌
        private PaiColor paicolor;           //玩家最大牌的颜色
        private bool isColor;                //玩家手中的牌的花色是否相同
        #endregion
        #region ----------------------------------玩家手中牌的最大值,颜色,牌型的属性-----------------------
        public PaiType Paitype
        {
            get { return paiType; }
        }
        public int MaxPai
        {
            get { return maxPai; }
        }
        public PaiColor Paicolor
        {
            get { return paicolor; }
        }
        #endregion
        #region -------------------同花顺(拥有五张连续数字同花色的顺子,以黑桃A为首的同花顺最大)---------------------------------
        public int StraightFlush(int[] cards, bool isColor)//同花顺
        {
            if (cards.Length == 5)
            {
                if (isColor)
                {
                    Array.Sort(cards);
                    for (int i = 0; i < cards.Length; i++)
                    {
                        if (cards[i] != cards[0] + i)
                        {
                            return 0;
                        }
                    }
                    paiType = PaiType.isTHS;
                    maxPai = cards[4];
                    return 1;
                }
                return 0;
            }
            return 0;
        }
        #endregion
        #region ------------------------------铁支(四张相同数字的牌,外加一单张,比数字大小,A铁支最大)----------------
        public int IronBranch(int[] cards, bool isColor)
        {
            if (cards.Length == 5 && isColor == false)
            {
                Array.Sort(cards);
                if ((cards[0] != cards[1] && cards[1] == cards[2] && cards[3] == cards[1] && cards[4] == cards[1]) || (cards[0] == cards[1] && cards[1] == cards[2] && cards[3] == cards[1] && cards[4] != cards[1]))
                {
                    paiType = PaiType.isTZ;
                    maxPai = cards[2];
                    return 1;
                }
                return 0;
            }
            return 0;
        }
        #endregion
        #region -----------------------------葫芦(由「三条」加一个「对子」所组成的牌。若别家也有此牌型,则比三条数字大小)----------------
        public int Cucurbit(int[] cards, bool isColor)
        {
            if (cards.Length == 5 && isColor == false)
            {
                Array.Sort(cards);
                if ((cards[0] == cards[1] && cards[1] != cards[2] && cards[3] == cards[2] && cards[4] == cards[2]) || (cards[0] == cards[1] && cards[1] == cards[2] && cards[3] != cards[2] && cards[4] == cards[3]))
                {
                    paiType = PaiType.isHL;
                    maxPai = cards[2];
                    return 1;
                }
                return 0;
            }
            return 0;
        }
        #endregion
        #region --------同花(不构成顺子的五张同花色的牌。比花色后比大小)
        public int SameColor(int[] cards, bool isColor)
        {
            if (cards.Length == 5)
            {
                if (isColor)
                {
                    Array.Sort(cards);
                    for (int i = 0; i < cards.Length; i++)
                    {
                        if (cards[i] != cards[0] + i)
                        {
                            paiType = PaiType.isTH;
                            maxPai = cards[4];
                            return 1;
                        }
                    }
                    return 0;
                }
                return 0;
            }
            return 0;
        }
        #endregion
        #region ------------------顺子(五张连续数字不同花色的牌组成。以A为首的顺子最大,如果大家都是顺子,比最大的一张牌,如果大小还一样就比这张牌的花色,黑桃A顺)
        public int Straight(int[] cards, bool isColor)
        {
            if (cards.Length == 5)
            {
                if (isColor == false)
                {
                    Array.Sort(cards);
                    for (int i = 0; i < cards.Length; i++)
                    {
                        if (cards[i] != cards[0] + i)
                        {
                            return 0;
                        }
                    }
                    paiType = PaiType.isSZ;
                    maxPai = cards[4];
                    return 1;
                }
                return 0;
            }
            return 0;
        }
        #endregion
        #region --------------三条(牌型由三张相同的牌组成,以A为首的三条最大)
        public int Three(int[] cards, bool isColor)
        {
            if (cards.Length == 5 && isColor == false)
            {
                int Count = 0;
                int _count = 0;
                int j = 0;
                Array.Sort(cards);
                for (int i = 0; i < cards.Length; i++)
                {
                    if (cards[2] == cards[i])
                    {
                        Count++;
                    }
                    else
                    {
                        j = i;
                        for (int n = 0; n < cards.Length; n++)
                        {
                            if (cards[j] == cards[n] && n != j)
                            {
                                _count++;
                            }
                        }
                    }
                }
                if (Count == 3 && _count == 0)
                {
                    paiType = PaiType.isSanTiao;
                    maxPai = cards[2];
                    return 1;
                }
                else
                {
                    return 0;
                }
            }
            return 0;
        }
        #endregion
        #region ----------------二对(牌型中五张牌由两组两张同数字的牌所组成。若遇相同则先比这副牌中最大的一对,如又相同再比第二对,如果还是一样,比大对子中的最大花色)
        public int TwoTwo(int[] cards, bool isColor)
        {
            int count = 0;
            int count2 = 0;
            if (cards.Length == 5 && isColor == false)
            {
                Array.Sort(cards);
                for (int i = 0; i < cards.Length; i++)
                {
                    if (cards[1] == cards[i])
                    {
                        count++;
                    }
                    if (cards[3] == cards[i])
                    {
                        count2++;
                    }
                }
                if (count == 2 && count2 == 2 && cards[1] != cards[3])
                {
                    paiType = PaiType.isTwoDui;
                    maxPai = cards[3];
                    return 1;
                }
                return 0;
            }
            return 0;
        }
        #endregion
        #region ---------------------对子(牌型由两张相同的牌加上三张单张所组成。如果大家都是对子,比对子的大小,如果对子也一样,比这个对子中的最大花色)
        public int Two(int[] cards, bool isColor)
        {
            int count = 0;
            int num = 0;
            if (cards.Length == 5 && isColor == false)
            {
                Array.Sort(cards);
                for (int i = 1; i < cards.Length; i++)
                {
                    if (cards[i] == cards[i - 1])
                    {
                        count++;
                        num = cards[i];
                    }
                }
                if (count == 1)
                {
                    paiType = PaiType.isDui;
                    maxPai = num;
                    return 1;
                }
                return 0;
            }
            return 0;
        }
        #endregion
        #region --------散牌(由单一型态,不构成上面的牌型的五张散牌组成,先比最大一张牌的大小,如果大小一样,比这张牌的花色)
        public int SP(int[] cards, bool isColor)
        {
            if (cards.Length == 5)
            {
                if (isColor == false)
                {
                    Array.Sort(cards);
                    if (Straight(cards, isColor) > 0)
                    {
                        return 0;
                    }
                    else
                    {
                        for (int i = 1; i < cards.Length; i++)
                        {
                            if (cards[i - 1] == cards[i])
                            {
                                return 0;
                            }
                        }
                        paiType = PaiType.isSP;
                        maxPai = cards[4];
                        return 1;
                    }
                }
                return 0;
            }
            return 0;
        }
        #endregion
        #region --------------------------------判断玩家手中的牌的牌型,最大值,和花色-----------------------
        public int PDTypeAndMaxAndColor(CardNum[] cards)
        {
            int[] num = PMZ(cards);
            //PDColor(cards, out isColor, out paicolor);//isColor :手中的牌是否同色。paicolor:手中最大的一张牌的颜色
            isColor = PDColor(cards);
            int max = 0;
            if (StraightFlush(num, isColor) > 0)
            {
                max = MaxPai;
                paicolor = ColorIndex(cards, max);
                return 1;
            }
            else if (IronBranch(num, isColor) > 0)
            {
                max = MaxPai;
                paicolor = ColorIndex(cards, max);
                return 2;
            }
            else if (Cucurbit(num, isColor) > 0)
            {
                max = MaxPai;
                paicolor = ColorIndex(cards, max);
                return 3;
            }
            else if (SameColor(num, isColor) > 0)
            {
                max = MaxPai;
                paicolor = ColorIndex(cards, max);
                return 4;
            }
            else if (Straight(num, isColor) > 0)
            {
                max = MaxPai;
                paicolor = ColorIndex(cards, max);
                return 5;
            }
            else if (Three(num, isColor) > 0)
            {
                max = MaxPai;
                paicolor = ColorIndex(cards, max);
                return 6;
            }
            else if (TwoTwo(num, isColor) > 0)
            {
                max = MaxPai;
                paicolor = ColorIndex(cards, max);
                return 7;
            }
            else if (Two(num, isColor) > 0)
            {
                max = MaxPai;
                paicolor = ColorIndex(cards, max);
                return 8;
            }
            else if (SP(num, isColor) > 0)
            {
                max = MaxPai;
                paicolor = ColorIndex(cards, max);
                return 9;
            }
            else
            {
                return 0;
            }

        }
        #endregion
        #region -----------------------找到对应的牌型中,牌的最大的花色---------------
        public PaiColor ColorIndex(CardNum[] cards, int max)//cards 牌的枚举数组,max 最大的牌
        {
            if (cards.Length == 5)
            {
                int[] num = new int[5] {0,0,0,0,0};
                for (int i = 0; i < cards.Length; i++)
                {
                    if (max==(int)cards[i]%100)
                    {
                        num[i] = (int)cards[i]/100;
                    }
                }
                Array.Sort(num);
                switch (num[4])
                {
                case 1:
                    return PaiColor.FP;
                case 2:
                    return PaiColor.CH;
                case 3:
                    return PaiColor.RedTao;
                case 4:
                    return PaiColor.BlackTao;
                default :
                    return PaiColor.Not;
                }

            }
            return PaiColor.Not;
        }
        #endregion
        #region --------------------------将枚举类型的牌转化成牌面值-----------------
        public int[] PMZ(CardNum[] cards)
        {
            int[] num = new int[cards.Length];
            for (int i = 0; i < cards.Length; i++)
            {
                num[i] = ((int)cards[i]) % 100;
            }
            return num;
        }
        #endregion
        #region -----------------------判断玩家手中的牌的花色是否相同和返回最大的一张牌的花色--------------
        //public void PDColor(CardNum[] cards, out bool isColors, out PaiColor paiColors)
        //{
        //    paiColors = PaiColor.Not;
        //    int[] num = new int[cards.Length];
        //    int[] num2 = new int[cards.Length];
        //    for (int i = 0; i < cards.Length; i++)
        //    {
        //        num[i] = (int)cards[i] % 100;
        //        num2[i] = ((int)cards[i]) / 100;
        //    }
        //    if (num2[0] == num2[1] && num2[2] == num2[3] && num2[1] == num2[4] && num2[2] == num2[4])
        //    {
        //        isColors = true;
        //    }
        //    else
        //    {
        //        isColors = false;
        //    }
        //    int maxColor = num.Max();
        //    int index = Array.IndexOf(num, maxColor);
        //    maxColor = (int)cards[index] / 100;
        //    switch (maxColor)
        //    {
        //        case 1:
        //            paiColors = PaiColor.BlackTao;
        //            break;
        //        case 2:
        //            paiColors = PaiColor.RedTao;
        //            break;
        //        case 3:
        //            paiColors = PaiColor.CH;
        //            break;
        //        case 4:
        //            paiColors = PaiColor.FP;
        //            break;
        //    }
        //}
        public bool PDColor(CardNum[] cards)
        {
            int[] num2 = new int[cards.Length];
            for (int i = 0; i < cards.Length; i++)
            {
                num2[i] = ((int)cards[i]) / 100;
            }
            if (num2[0] == num2[1] && num2[2] == num2[3] && num2[1] == num2[4] && num2[2] == num2[4])
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        #endregion
    }
}

 

 

 public enum CardNum
    {
        A0 = 108, A1=109, A2=110, A3=111, A4=112, A5=113, A6=114,//黑桃
        B0 = 208, B1=209, B2=210, B3=211, B4=212, B5=213, B6=214,//红桃
        C0 =308, C1 =309, C2 =310,C3 =311, C4 =312,C5 = 313,C6 = 314,//草花
        D0 = 408, D1 = 409, D2 = 410, D3= 411, D4 = 412, D5 = 413, D6 = 414,//方片
        invalid =500
    }
    public enum PaiType
    {
        Not = 0,        //没有牌型
        isTHS,          //同花顺
        isTZ,           //铁支
        isHL,           //葫芦
        isTH,           //同花
        isSZ,           //顺子
        isSanTiao,      //三条
        isTwoDui,        //两对
        isDui,          //一对
        isSP,           //散牌

    }
    public enum PaiColor
    {
        Not = 0,       //没有颜色
        BlackTao,      //黑桃
        RedTao,        //红桃
        CH,            //草花
        FP,            //方片
    }

 


来源:本站原创
你可能感兴趣的:
梭哈游戏服务端的实现
梭哈游戏开发文档
让自己成为梭哈的主宰
玩梭哈游戏必胜的条件
梭哈游戏该如何下注
梭哈游戏斗智斗勇
梭哈游戏简史
梭哈游戏
我们向您推荐的:
新一代棋牌游戏设计原则UI设计原则
棋牌类网络游戏UI界面博雅德州扑克UI设计
棋牌游戏设计常用窗口风格游戏角色概念设定
游戏设计中如何构图什么是游戏场景
设计游戏场景的原则
麻将出牌要考虑哪些方面麻将五行分析
趣话随州麻将拳打脚踢定将麻将打法
麻将九段必考题麻将声东击西技巧
麻将番种:孔雀东南麻将技巧-瞒天过海
麻将怎么养牌麻将基本打法

麻雀和扑克

斗地主斗什么?

斗地主传奇

麻将的研究

民间游戏麻将

抓牌靠运气,打牌靠本领

麻将游戏的益智性

把扑克引入数学课堂中
欢乐麻将游戏介绍谁说败局已定
澳门赌场赌大小必胜法澳门赌场赌大小策略
澳门赌场赌大小技巧牌桌上要细致观察
什么是懦夫博弈如何成为酒吧“色魔”
赌博的两大因素博弈专家输了自己的游戏

打双扣的心理因素双扣战局把握能力
双扣的配合双扣战略意识
双扣的记忆品质双扣博弈心理分析
双扣怎么玩?双扣哲学
关于双扣双扣用炸技巧
棋牌游戏下载 36棋牌深海捕鱼

深海捕鱼

游戏视频

经验分享

棋牌游戏攻略

斗地主

2007-2011 © 网上现金棋牌游戏平台 版权所有
经营许可证编号:浙B2-20100034 文网文编号:[浙网文[2011]0009-002号] 网站备案号:浙ICP备06050027号 浙江广凌天网络科技有限公司