c#实验报告模拟发牌程序
2011-10-25 20:34
274 查看
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(); } } }
相关文章推荐
- 页面置换算法模拟程序实现实验报告
- 实验二作业调度模拟程序实验报告
- 实验二 作业调度模拟程序 报告
- 实验二 作业调度模拟程序
- “软件工程(C编码实践篇)”实验报告【实验三:内部模块化的命令行菜单小程序V2.0】
- 第六周实验报告 程序填空
- C#的TabControl模拟IE7程序事例,带关闭功能
- 实验三、进程调度模拟程序实验
- 操作系统 实验三 进程调度模拟程序
- 实验三 进程调度模拟程序
- 实验三、进程调度模拟程序实验
- 实验三、进程调度模拟程序实验
- 软件工程(C编码实践篇)”实验报告 实验四:用可重用的链表模块来实现命令行菜单小程序V2.5
- C程序语言设计第一次上机实验报告
- “软件工程(C编码实践篇)”实验报告【实验二:命令行菜单小程序V1.0】
- 网络程序开发实验报告
- “软件工程(C编码实践篇)”实验报告【实验一:写一个hello world小程序】
- 控制台程序模拟登录--C#(三次输入错误程序关闭)
- 实验三进程调度模拟程序
- 【操作系统】实验三 进程调度模拟程序