using System; using System.Collections.Generic; using System.Text; namespace CardGame_995240 { //using the enum keyword to create an enumeration list suits enum Suits { Diamond, Heart, Club, Spade } // the PlayingCards class is used to define the value and suit of a card class PlayingCards { protected Suits suit; protected string value; // default constuctor public PlayingCards() { } public PlayingCards(Suits suit2, string value2) { suit = suit2; value = value2; } public override string ToString() { return string.Format("{0} of {1}", value, suit); } } //the DeckofCards class defines a shuffling algorithm to randomly shuffle the cards class DeckofCards { // defining an array of 52 cards for the PlayingCards object PlayingCards[] cards = new PlayingCards[52]; string[] types = new string[] { "2", "3", "4", "5", "6", "7", "8", "9", "Jack", "Queen", "King" }; // assigning a the values of cards to a suit // constructor public DeckofCards() { int i = 0; //using foreach staements to iterate through the suits foreach(string s in types) { cards[i] = new PlayingCards(Suits.Diamond, s); i++; } foreach (string s in types) { cards[i] = new PlayingCards(Suits.Heart, s); i++; } foreach (string s in types) { cards[i] = new PlayingCards(Suits.Club, s); i++; } foreach (string s in types) { cards[i] = new PlayingCards(Suits.Spade, s); i++; } } //shuffling algorithm static Random r = new Random(); //Based on Java code from wikipedia: http://en.wikipedia.org/wiki/Fisher-Yates_shuffle static public void Shuffle(int[] deck) { for (int n = deck.Length - 1; n > 0; --n) { int k = r.Next(n + 1); int temp = deck[n]; deck[n] = deck[k]; deck[k] = temp; } } public PlayingCards [] Cards { get { return cards; } } } class Player { private string name; // Constructor assigning the name of the player public Player(string name) { this.name = name; } // Printing the name of the player on the screen public void PrintPlayer() { Console.WriteLine("{0}", name); } } class CardGame { } class TestClass { static void Main() { //creating objects to define two players Player player1 = new Player("Fred"); Player player2 = new Player("Sarah"); //displaying results onto the console Console.Write("Player *1: "); player1.PrintPlayer(); Console.Write("Player *2: "); player2.PrintPlayer(); //displays the deck of cards DeckofCards deck = new DeckofCards(); foreach (PlayingCards c in deck.Cards) { Console.WriteLine(c); } } } }