Member Avatar for stow19

Hey all,

I have created a group of player using a list within a list method. But now I'm stuck on dealing out the cards. Here is the code for setting up the players:

static Random r = new Random();
        static int numPlayers;
        static List<List<string>> playersHands = new List<List<string>>();

        static void setNumPlayers()
        {
            Console.Write("Please Enter the Number of Players Between 2 and 52: ");
            numPlayers = Convert.ToInt16(Console.ReadLine());
            if (numPlayers < 2 || numPlayers > 52)//only loops through once
            {
                Console.WriteLine("Please enter a value between 2 and 52: ");
                numPlayers = Convert.ToInt16(Console.ReadLine());
            }
            else
            {
                Console.WriteLine("NUM PLAYERS: " + numPlayers);
                List<string> p = new List<string>();
                for (int i = 1; i <= numPlayers; i++)
                {
                    var name = "p" + i;
                    p.Add(name);
                }
                
                playersHands.Add(p);
                p.ForEach(Console.WriteLine);//for 2 players outputs p1 p2
            }
        }

Thanks

Have you a Player class?
In it you could keep properties like the players hand, the players score etc.

Member Avatar for stow19

I haven't. This is the part I got confused at. How would I go about doing this? I wasn't sure which fields to add to it. And how to get the list to be set there instead of just one class.

Something like this?

class Card
    {
        public Card()
        {

        }

        public string CardValue { get; set; }
        // possibly more here a picture? etc.
    }

    class Player
    {
        public Player()
        {
            Name = string.Empty;
            Score = 0;
            Hand = new List<Card>();
        }

        public string Name { get; set; }
        public int Score { get; set; }
        public List<Card> Hand { get; set; }
        // possibly more here
    }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.