Create a type corresponding to a playing card

Asked

Viewed 533 times

2

I need to create a guy that matches a playing card. I tried it like this: Create a class for each suit and within the class create the properties of those classes that would be the cards themselves, like, Ace, Jack, King, Queen, Two and so on. But that’s where I’m picking up, because I’ll need to use this deck, like shuffle, draw a card, play and etc. Then comes the question: How do I create a card? The question is not wide (more than one answer) I just tried to explain what should happen, but the answer I wish would be: How I create a letter. Preferably not code, just an orientation on how to do.

2 answers

3

Man, in my conception the ideal would be to create a class Carta, class Baralho containing a vector of 52 cards and two enums, one for Suits and one for Valor.

Within the Deck class, you would have the methods relating to the deck, such as shuffling, drawing a card, delivering a card from the deck, and in the builder you would instantiate the 52 cards using a for and the enums.

If you find it too abstract, I can do an Edit later, showing the approximate implementation in c#...

  • I’ll try to do it now and see if I really understand or not and of course, posting everything I do.

  • I just didn’t understand Enum for value.

  • Enum value would be the value of the card: A, 2, 3, ... , Q, K.

  • I just wouldn’t use a vector with 52 positions.

  • @joaoeduardorf, what would I use instead of the array then? Dude, I can’t create a line of reasoning. I need to create a method Shuffle, for example, and of course, it should be random and I have no idea how to assemble my "deck" and shuffle. Okay.

  • @Felipeavelar, really very abstract. It is worth what I commented to the joaoeduardorf.

Show 1 more comment

0

  • good evening. I will take a look and in the morning if you have no progress, and if you have also put.

  • Includes a console last night just to show you the exits.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.