New answers tagged

4

First off, this is quite good for beginner code. You'll do well if you keep the good habits you've started following. A few critiques: class Card : IComparable<Card> Do you intend this class to be subclassed? If not, seal it. Are cards comparable by reference? That is, suppose we have two different instances of the queen of spades. Is it possible ...


5

Just a few things not already mentioned by other answers: Are you sure that you will need DrawRandomCard() ? How many card games have you played where you just draw from a random position in the deck? The only times I can think of this is useful is when you do a magic trick, which doesn't really work the same in code as in real life :) Normally in card ...


5

Encapsulation and Mutability Your Card class is a perfect candidate for being immutable: make Kind and Suit readonly fields or getter-only properties (prefer the later in most cases): public Kind Kind { get; } public Suit Suit { get; } You should also hide away the Deck list in CardDeck: making it readonly and private (or protected, if you are happy to ...


7

enum Kind { ... Queen, King, Joker // ??? } Jokers is the joker. You're not considering jokers class Card : IComparable<Card> { ... I'm not convinced that there is a default comparison for cards? It could be misunderstood by consumers. On the other hand a deck of cards is always sorted by Suit and then Kind, but the ...


5

List<T> You have just learned about List<T> and are eager to use it. Perfectly understandable, but think about what it is designed for and what alternatives are available for this use case. Here is an overview of common Collections in C# To be fair, there is no common collection available designed for a deck of cards. What you need, is ...


0

I found the solution already to the timer issue. const deal = () => { init(); // Can be improved by continue to use the remaining card in the deck newDeck(); // Option: to burn first card before deal a card // to the first player burnOneCard; setTimeout(function () { dealOneCardToPlayer("", false); }, 500); ...


Top 50 recent answers are included