Click here to Skip to main content
15,566,625 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
hi everybody,
I am planing to do a card game called "trex" its so popular in my place .. there are 4 players in this game.. so 52/4 = 13 cards for each player
-how to divide those card for each player randomly..
-and how to display the divided cards on form1.cs[design]
-how to assign every single card with its image for form1.cs[design]

I have the card.cs class

namespace cards_game
{
 
    /// Card suit values
  
    public enum Suit
    {
        Diamonds, Spades, Clubs, Hearts
    }
   
    /// Card face values
   
    public enum FaceValue
    {
        Two = 2, Three = 3, Four = 4, Five = 5, Six = 6, Seven = 7, Eight = 8,
        Nine = 9, Ten = 10, Jack = 11, Queen = 12, King = 13, Ace = 14
    }
    public class Card
    {
        // Objects for card information
        private readonly Suit suit;
        private readonly FaceValue faceVal;
        private bool isCardUp;
        public Suit Suit { get { return suit; } }
        public FaceValue FaceVal { get { return faceVal; } }
        public bool IsCardUp { get { return isCardUp; } set { isCardUp = value; } }
        
        /// Constructor for a new card.  Assign the card a suit, face value, and if the card is facing up or down
        
        public Card(Suit suit, FaceValue faceVal, bool isCardUp)
        {
            this.suit = suit;
            this.faceVal = faceVal;
            this.isCardUp = isCardUp;
        }
        
        public override string ToString()
        {
            return "The" + faceVal.ToString() + "of" + suit.ToString();
        }
    }
}


[Edited]Wrapped your code in "pre" tags[/Edited]
Posted
Updated 29-Apr-11 20:32pm
v2

1 solution

1) Use the class System.Random.
2) Use the class System.Windows.Forms.PictureBox.
3) Dynamically combine small images denoting Suite with the card's layout (say, arranging 6 spades has the same layout as 6 clubs, but not the same as 10 spades) and "picture" cards: Jack, Queen and King. You can "compile" those combination into each of the individual cards during initialization and reuse those images during the rest of the game.

You're using public all the time where you might work with internal; public is only needed to access declarations form another assembly. Will you use these declarations in different assemblies? Plan ahead and try not to use higher access then really needed.

—SA
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900