Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialChristian Higgins
15,758 PointsGeneral frustration about C# not clicking in my brain
Around the 2:40 mark, Jeremy says: "This is how I learn to code. I often know what I want to do but I don't always know how to do it. That gives me an opportunity to figure it out."
I know some JavaScript already, but I'm having this feeling so much with C#. It reminds me of the first time I was trying to understand how a for loop works. I knew what it was doing, I could describe it, and yet I still somehow couldn't wrap my head all the way around it. I know one day it'll all make sense and I'll wonder what was wrong with me for not understanding it yet.
I'm trying to build a Console app for Black Jack. Here is how I would describe parts of it in plain English:
- There is a Card . It has a rank and suit. It can be Deal 't from a Deck into a Hand.
- There is a Player which can Hit, Stand, Bet/Ante, and has Cards/Hands. There will be a HumanPlayer and a ComputerPlayer. The HumanPlayer will make an active choice on whether to Hit, Stand, or Bet. The ComputerPlayer will be automated based on the situation (Stand on 17 or higher; Hit on 16 or lower)
- There is a Deck made up of Cards. It can be Create 'd, Shuffle 'd, and Deal 't.
- There is a Hand, which is made up of Cards and can be Calculate 'd for the Total. The calculations will be by the value of number cards; Jacks, Queens, and Kings will count as 10; Aces will be counted as 11 or 1 based on whether the Total would put it above 21. If a Hand goes over 21, it's a Bust and that Player loses. Whichever player has the higher Total for its Hand would win the game.
- There is Money which belongs to each player. The players can Bet that Money, but not more than they currently have.
Christian Higgins
15,758 PointsSteven Parker , the hardest part about C# for me in the early stages is how to tie everything together. So more specifically, if there is a Deal method, then it also has to Deal from a Deck and to a certain Player.
1 Answer
Steven Parker
231,248 PointsBased on your description, I might imagine that a Hand might have an "Add" method that takes a Card argument, and a Deck might have a "Deal" method that returns the top card. So:
Player.Hand.Add(TheDeck.Deal()); // deal the top card into the player's hand
if (Player.Hand.Total > 21) { // oops! Bust
But you could also have "Deal" take an argument that is which hand to add to, and have it call "Add" directly instead of returning the dealt card:
TheDeck.Deal(Player.Hand);
So you have implementation options. Do what makes the most sense to you.
Christian Higgins
15,758 PointsYeah, I actually just woke up this morning with a "Eureka!" moment about List<Type> Thank you for this!
Steven Parker
231,248 PointsSteven Parker
231,248 PointsYour strategy for building your app sounds good. But are you just sharing, or did you have a question about it?