c#实验报告模拟发牌程序

using System;
using System.Collections.Generic;
using System.Text;
namespace card
{                             
    class Card
    {
        public enum _suit
        {红桃,黑桃,草花,方块}
        private _suit suit = new _suit();
        public _suit Suit
        {
            get { return suit; }
            set { suit = value; }
        }
       
        private int rank = new int();
        public int Rank
        {
            get { return rank; }
            set
            {
                if (value <= 13 && value >= 0)
                    rank = value;
                else
                    rank = 1;
            }
        }
    }
}
---------------------------------------------空虚的分割线-----------------
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections ;
namespace card
{
    class Deck
    {
        private ArrayList m_cards = new ArrayList();
        public Deck()
        {
            for (int i = 0; i <= 3; i++)
            {
                for (int j = 1; j <= 13; j++)
                {
                    Card temp=new Card ();
                    temp.Suit=(Card._suit)i;
                    temp.Rank=j;
                    m_cards.Add(temp);
                }
            }
        }
        public int Count
        {
            get { return m_cards.Count; }
        }
        public void Shuffle()          //洗牌
        {
            Random r = new Random();
            ArrayList temp_m_cards = new ArrayList();
            for (int j = 1; j <= 52; j++)
            {
                int i = r.Next(0, m_cards.Count);
                temp_m_cards.Add(m_cards[i]);
                m_cards.RemoveAt(i);
            }
            for (int j = 0; j < 52; j++)
            {
                Card temp = (Card)temp_m_cards[j];
                m_cards.Add(temp);
            }
        }
        public void Deal(Hand[] hands)
        {
            int k=0 ;
            for (int i = 0; k<52 ; i++)
            {
                hands[i].Add((Card)m_cards[k]);
                k++;
                if (i == (hands.Length-1))
                {
                    i = -1;
                }
            }
        }
        public void Show()
        {
            for (int i = 0; i < m_cards.Count; i++)
            {
                Console.Write(((Card)m_cards[i]).Suit);
                Console.WriteLine(((Card)m_cards[i]).Rank);
            }
        }
    }
}
---------------------------话说陈绮贞演唱会真激情----------------
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace card
{
    class Hand
    {
        private string name;
        private ArrayList m_cards = new ArrayList();
        public Hand(string name)
        {
            this.name = name;
        }
        public Hand(string name, Card[] cards)
        {
            this.name = name;
            m_cards.AddRange(cards);
        }
        public int Count
        {
            get { return m_cards.Count; }
        }
        public void Add(Card acard)
        {
            m_cards.Add(acard);
        }
        public void Show()
        {
            Console.WriteLine(name);
            for (int i = 0; i < m_cards.Count; i++)
            {
                Console.Write(((Card)m_cards[i]).Suit);
                Console.WriteLine(((Card)m_cards[i]).Rank);
            }
        }
    }
}
------------------------------哈哈~~~陈绮贞 我爱你~~~------------
using System;
using System.Collections.Generic;
using System.Text;
namespace card
{
    class Program
    {
        static void Main(string[] args)
        {
            Deck aDeck = new Deck();
            Console.WriteLine("before shuffle");
            aDeck.Show();
            aDeck.Shuffle();
            Console.WriteLine("after shuffle");
            aDeck.Show();
            Hand hand1 = new Hand("Zhao");
            Hand hand2 = new Hand("Qian");
            Hand hand3 = new Hand("Sun");
            Hand hand4 = new Hand("Li");
            aDeck.Deal(new Hand[] { hand1, hand2, hand3, hand4 });
            hand1.Show();
            hand2.Show();
            hand3.Show();
            hand4.Show();
        }
    }
}



评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值