Click here to Skip to main content
15,886,094 members
Articles / Programming Languages / SQL

rdsCards - A Card Deck Library using RDS

Rate me:
Please Sign up or sign in to vote.
4.43/5 (4 votes)
17 Jul 2012CPOL3 min read 26.7K   328   10  
Create an easy-to-use Card Deck / Deal / Shuffle library with RDS
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using rds;

namespace rdsCards
{
	/// <summary>
	/// Holds a single playing card
	/// </summary>
	public class Card : RDSObject
	{
		#region CONSTRUCTOR
		/// <summary>
		/// Initializes a new instance of the <see cref="Card"/> class.
		/// </summary>
		/// <param name="cardvalue">The cardvalue is a 1-character-string describing the card.
		/// The chars for a card are (A)ce, (K)ing, (Q)ueen, (J)ack, (T)en or the number from 9 to 2 or * for a Joker</param>
		public Card(string cardvalue, Suit suit)
		{
			if (CardDeck.stringcards.Contains(cardvalue))
			{
				mvalue = cardvalue;
				if (cardvalue != "*")
					msuit = suit;
				else
					msuit = Suit.None;
			}
			else
				throw new InvalidOperationException("\"" + cardvalue + "\" is not a valid card value character.");
		}
		#endregion

		#region FIELDS
		/// <summary>
		/// Gets the short display string for the card. This looks like A♥ and is always 2 characters long.
		/// For Jokers, the second character is a blank (no suit).
		/// </summary>
		public string ShortDisplayString
		{
			get { return mvalue + CardDeck.stringsuits[(int)Suit]; }
		}

		/// <summary>
		/// Gets the value of the card. The range is from A to 2
		/// </summary>
		public string Value
		{
			get { return mvalue; }
		}
		private string mvalue = "";

		/// <summary>
		/// Gets the suit of the card or Suit.None when it is a Joker
		/// </summary>
		public Suit Suit
		{
			get { return msuit; }
		}
		private Suit msuit = Suit.None;
		#endregion

		#region INTERNAL MEMBERS AND OVERRIDES FOR THE CARD DECK
		/// <summary>
		/// Card already dealt?
		/// </summary>
		internal bool IsDealt = false;

		/// <summary>
		/// Raises the <see cref="E:PreResultEvaluation"/> event.
		/// </summary>
		/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
		public override void OnRDSPreResultEvaluation(EventArgs e)
		{
			base.OnRDSPreResultEvaluation(e);
			rdsEnabled = !IsDealt;
		}

		/// <summary>
		/// Raises the <see cref="E:Hit"/> event.
		/// </summary>
		/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
		public override void OnRDSHit(EventArgs e)
		{
			base.OnRDSHit(e);
			IsDealt = true;
			rdsEnabled = false;
		}
		#endregion

		public override string ToString()
		{
			return "\"" + ShortDisplayString + "\" " + base.ToString();
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Austria Austria
Software Developer since the late 80's, grew up in the good old DOS-Era, switched to windows with Win95 and now doing .net since early 2002 (beta).
Long year c# experience in entertainment software, game programming, directX and XNA as well as SQLServer (DBA, Modelling, Optimizing, Replication, etc) and Oracle Databases in Enterprise environments. Started with Android development in 2014.

Developer of the gml-raptor platform (See my github profile below).

My Game Developer Profile at itch.io
My Repositories at github

Comments and Discussions