Click here to Skip to main content
15,890,717 members
Home / Discussions / C#
   

C#

 
GeneralRe: Retrieving the Value of a costumn control placed in a Placeholder placed in a repeater Pin
Not Active17-Mar-08 6:28
mentorNot Active17-Mar-08 6:28 
GeneralMore Collision (XNA) Pin
MasterSharp17-Mar-08 5:01
MasterSharp17-Mar-08 5:01 
GeneralRe: More Collision (XNA) Pin
Christian Graus17-Mar-08 9:15
protectorChristian Graus17-Mar-08 9:15 
GeneralRe: More Collision (XNA) [modified] Pin
MasterSharp17-Mar-08 10:09
MasterSharp17-Mar-08 10:09 
Generalto return or not to return something Pin
pauli17-Mar-08 4:58
pauli17-Mar-08 4:58 
GeneralRe: to return or not to return something Pin
Rob Philpott17-Mar-08 6:20
Rob Philpott17-Mar-08 6:20 
GeneralRe: to return or not to return something Pin
Simon P Stevens17-Mar-08 6:55
Simon P Stevens17-Mar-08 6:55 
GeneralRe: to return or not to return something [modified] Pin
pauli17-Mar-08 23:01
pauli17-Mar-08 23:01 
Rob, Simon,
Thank you for your replies.
To answer Rob's questions: I'm using VS Express 2005 with .NET 2.0.5.
Hands are not players, but are the cards dealt to players. Maybe I should make Player class and I don't even need a Hands class?
Anyway, there are 4 players and each one it's dealt a set of 13 cards.
I wanted the Hands class to have fields required for the AI (evaluating hands) - such as "ShortestSuit" , "LowestCardofShortestSuit"... Now I'm not even 100%sure I need this class. I could write the above methods as members of a Game class and store the hands in simple arrays (arrays of card objects). This way I could pass the array as argument for the hand evaluation functions.

Simon, thank you very much for your suggestions and examples. I do have a Card class in my project, which is a cards.dll wraper from Mike Kitchen's hilow source code posted here on codeproject:

/*<br />
 * cardsdll wrapper class<br />
 * Downloaded from www.publicjoe.co.uk<br />
 *<br />
 * This software is provided 'as-is', without any express or implied warranty.<br />
 * In no event will the author(s) be held liable for any damages arising from<br />
 * the use of this software.<br />
 * <br />
 * Permission is granted to anyone to use this software for any purpose,<br />
 * including commercial applications, and to alter it and redistribute it<br />
 * freely.<br />
 */<br />
<br />
using System;using System.Drawing;using System.Runtime.InteropServices;<br />
namespace miscelements.Windows.Cards<br />
{<br />
  public enum CardSuit : int<br />
  {<br />
    Clubs = 0,<br />
    Diamond = 1,<br />
    Hearts = 2,<br />
    Spades = 3<br />
  }<br />
  public enum CardRank : int<br />
  {<br />
    Ace = 0,<br />
    Two = 1,<br />
    Three = 2,<br />
    Four = 3,<br />
    Five = 4,<br />
    Six = 5,<br />
    Seven = 6,<br />
    Eight = 7,<br />
    Nine = 8,<br />
    Ten = 9,<br />
    Jack = 10,<br />
    Queen = 11,<br />
    King = 12<br />
  }<br />
  public enum CardBack : int<br />
  {<br />
    Crosshatch = 53,<br />
    Sky        = 54,<br />
    Mineral    = 55,<br />
    Fish       = 56,<br />
    Frog       = 57,<br />
    Moonflower = 58,<br />
    Island     = 59,<br />
    Squares    = 60,<br />
    Magenta    = 61,<br />
    Sanddunes  = 62,<br />
    Space      = 63,<br />
    Lines      = 64,<br />
    Toycars    = 65,<br />
    Unused     = 66,<br />
    The_X      = 67,<br />
    The_O      = 68<br />
  }<br />
  public enum CardMode : int<br />
  {<br />
    RankCollated   = 0, // card number starts from 0<br />
    SuitCollated   = 1, // card number offset by 1 for blank card.<br />
    Highlight      = 2, /* Same as RankCollated except drawn inverted */<br />
    Ghost          = 3, /* Draw a ghost card -- for ace piles */<br />
    Remove         = 4, /* draw background specified by color */<br />
    InvisibleGhost = 5, /* ? */<br />
    DeckX          = 6, /* Draw X */<br />
    DeckO          = 7  /* Draw O */<br />
  }<br />
  public class Card : IDisposable<br />
  {<br />
    // Internal constants e.g. Magic Numbers.<br />
    /// Default width used by card's DLL.<br />
    internal const int DefaultWidth = 71;<br />
    /// Default height used by card's DLL.<br />
    internal const int DefaultHeight = 97;<br />
    /// Default border mask value.<br />
    internal const int BorderMask = 0x00FFFFFF;<br />
    /// .NET Graphics surface used for drawing.<br />
    private Graphics graphicsSurface;<br />
    /// Win32 HDC surface use for Win32 drawing.<br />
    private IntPtr graphicsDC;<br />
    /// Last value from the card's DLL.<br />
    private bool lastReturnValue;<br />
    /// Is this instance current being disposed?<br />
    private bool disposed;<br />
    /// Current Mode to draw Card<br />
    private static int mode;<br />
    public int Mode<br />
    {<br />
      get { return mode;  }<br />
      set { mode = value; }<br />
    }<br />
    /// Constructor which initialise access to the card's DLL.<br />
    public Card()<br />
    {<br />
      int width = DefaultWidth;<br />
      int height = DefaultHeight;<br />
      mode = (int)CardMode.RankCollated;<br />
      NativeMethods.cdtInit(ref width, ref height);<br />
    }<br />
/* the remaing of the class code contains the  #region Implementation: IDisposable & Finaliser, the destructor, dispose, native methods, internal helpers etc ...... */


Mike's/Public Joe's code has some resemblances with your suggestions.
In your example, I see that each card will be an object, with value and suit as properties, accessed with property set / get. In Mike's code it seems to me that the value and suit are fields instead of properties.

I think using integers was needed for easier use of the dll. I do not mind.
The cards in the cards.dll are numbered from 1 to 52, with 1 to 13 being clubs, 14 to 26 being diamonds and so on... It's not hard to do the correct math to "extract" the real suit and value from these numbers.
Now I must confess I don't see yet how exaclty will I work with the cards in hands. Mike's hilow game does not deal the cards, but takes one card from the deck and shows it on the table. I am still learning from his source code. I just noticed this member of the card class and it's doing the math i was writing above (converts from suit and value to 1-52 numbers) :

/// Helper that converts a given Card's rank, suit, mode into the card index.<br />
/// </summary><br />
/// <param name="suit">Suit to draw.</param><br />
/// <param name="rank">Rank of card.</param><br />
/// <returns></returns><br />
    public static int ToCardIndex( CardSuit suit, CardRank rank )<br />
    {<br />
      int cardNo = -1;<br />
<br />
      switch( mode )<br />
      {<br />
        case 0: /*CardMode.RankCollated*/<br />
          cardNo = ((int)rank)*4+((int)suit);<br />
          break;<br />
<br />
        case 1: /* CardMode.SuitCollated */<br />
          cardNo = 1+((int)rank)+13*((int)suit);<br />
          break;<br />
<br />
        default:<br />
          cardNo = 0;<br />
          break;<br />
      }<br />
      return cardNo;<br />
    }



The cards are objects while my Hands class works with an array of integers. I realize this might not make sense (althogh I think it could really work this way - I would do anythind in order to avoid an object Smile | :) ). At first I was wondering if I should work with an array of cards objects, but now I see you suggest working with a collection. I am yet to learn about this concept.
I'm not familiarized with many of the concepts used in your samples: enums, set / get, and collections, but that's why I'm doing this project - to learn.

Simon, I am gonna try all your suggestions. They look really promising and thanks again for spending some of your time to help me.

Edit: I am stuck.
I made a total mess out of it. What type is theHands? I assume Collection<playerhand> is a type?

Collection<playerhand> theHands; // why not = new Collection<playerhand>(); ?
// System.Type type = theHands.GetType();
// MessageBox.Show(Convert.ToString(type));
theHands = TheDeck.DealHands(4);

How do I refer to each hand? How do I assign a value to theHands?
I am trying to rewrite the DealHands method of the Deck class, but I can't make it work in the new way:
///.......
public class Deck
{
private int[] CardArray = new int[52];
private Collection<playerhand> aHand = new Collection<playerhand>();
/// ......
public Collection<playerhand> DealHands (int handsnumber)
{
for (int j = 0; j < 13; j++)
{
for (int i = 0; i < handsnumber; i++)
{
//passedHands.PlayerHands [i,j]=CardArray[4 * j + i];
aHand [i].Cards(j).set =CardArray[4 * j + i];
}
}
return aHand;
}

the above does not work - the error is Cards is a property and i am trying to use it as a method. I someone could drag me out of this messs, I would higly appreciate.
<joke>
otherwise, I'm back to VB6, forever ! Big Grin | :-D


modified on Tuesday, March 18, 2008 10:26 AM

GeneralRe: to return or not to return something Pin
Simon P Stevens18-Mar-08 6:07
Simon P Stevens18-Mar-08 6:07 
Generalgeneric collection - .net 2.0 Pin
arkiboys17-Mar-08 4:22
arkiboys17-Mar-08 4:22 
GeneralRe: generic collection - .net 2.0 Pin
Luc Pattyn17-Mar-08 4:29
sitebuilderLuc Pattyn17-Mar-08 4:29 
QuestionActive Directory "login" from C# application Pin
User 137680017-Mar-08 3:52
User 137680017-Mar-08 3:52 
GeneralResource leak (handles count) in simple .NET application Pin
Kolobock17-Mar-08 3:45
Kolobock17-Mar-08 3:45 
GeneralRe: Resource leak (handles count) in simple .NET application Pin
Luc Pattyn17-Mar-08 3:55
sitebuilderLuc Pattyn17-Mar-08 3:55 
GeneralRe: Resource leak (handles count) in simple .NET application Pin
Kolobock17-Mar-08 4:07
Kolobock17-Mar-08 4:07 
GeneralRe: Resource leak (handles count) in simple .NET application Pin
Luc Pattyn17-Mar-08 4:25
sitebuilderLuc Pattyn17-Mar-08 4:25 
GeneralRe: Resource leak (handles count) in simple .NET application Pin
Kolobock17-Mar-08 8:32
Kolobock17-Mar-08 8:32 
GeneralRe: Resource leak (handles count) in simple .NET application Pin
Luc Pattyn17-Mar-08 8:44
sitebuilderLuc Pattyn17-Mar-08 8:44 
GeneralRe: Resource leak (handles count) in simple .NET application Pin
Kolobock17-Mar-08 10:18
Kolobock17-Mar-08 10:18 
GeneralRe: Resource leak (handles count) in simple .NET application Pin
Rob Philpott17-Mar-08 4:10
Rob Philpott17-Mar-08 4:10 
GeneralRe: Resource leak (handles count) in simple .NET application Pin
Kolobock17-Mar-08 8:34
Kolobock17-Mar-08 8:34 
GeneralRe: Resource leak (handles count) in simple .NET application Pin
Kolobock17-Mar-08 23:57
Kolobock17-Mar-08 23:57 
GeneralIP Camera with C# Pin
sher1217-Mar-08 3:44
sher1217-Mar-08 3:44 
GeneralRe: IP Camera with C# Pin
Luc Pattyn17-Mar-08 3:59
sitebuilderLuc Pattyn17-Mar-08 3:59 
GeneralScreen Shot Pin
sjs4u17-Mar-08 2:18
sjs4u17-Mar-08 2:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.