-
Program Design
I am a C programmer with lots of experience. Currently I'm trying to learn
C++ and Object Oriented programming. I would like suggestions from experienced
C++ programmers on what classes to use to implement a game of Showdown.
Showdown is played as follows: Shuffle a standard deck of 52 cards. Deal
5 cards to each of P players. Determine the player who has the highest hand.
He is the winner.
Some of the tasks needed to implement this are: Initialize and shuffle the
deck. Input and verify the number of players, P. Determine the rank and
suit of any card. Determine the value of any 5 card hand. Determine which
player has the highest hand.
One design I tried was to first create a Card class, then create Deck and
Hand classes which contain Card objects. My implementation of this design
seemed hard to understand.
Again, I would appreciate any suggestions on which classes to use.
-
Re: Program Design
"mstolnic" <mstolnic@mediaone.net> wrote in message
news:3bd86470$1@news.devx.com...
> One design I tried was to first create a Card class, then create Deck and
> Hand classes which contain Card objects. My implementation of this design
> seemed hard to understand.
That sounds about right. You'll probably also need a "Game" class which
hold a Deck and two Hand objects.
The next trick is to decide who gets what member function. Shuffling &
more importantly, setting up suits & ranks is the job of Deck. Each Hand
determines it's own score, but Game decides which is bigger.
--
Truth,
James Curran
www.NJTheater.com (Professional)
www.NovelTheory.com (Personal)
www.BrandsForLess.Com (Day Job)
-
Re: Program Design
Wow! An opportunity to sermonize on Object Oriented Programming in 25 words
or less. Who could pass that up? <g>
Hopefully you have a couple of good books.
"mstolnic" <mstolnic@mediaone.net> wrote:
>
>I am a C programmer with lots of experience. Currently I'm trying to learn
>C++ and Object Oriented programming. I would like suggestions from experienced
>C++ programmers on what classes to use to implement a game of Showdown.
>
>Showdown is played as follows: Shuffle a standard deck of 52 cards. Deal
>5 cards to each of P players. Determine the player who has the highest
hand.
> He is the winner.
>
>Some of the tasks needed to implement this are: Initialize and shuffle
the
>deck. Input and verify the number of players, P. Determine the rank and
>suit of any card. Determine the value of any 5 card hand. Determine which
>player has the highest hand.
>
First, get a good feeling for the difference between 'objects' and 'classes'.
Classes are programming constructs that you will use to create objects. So
first, pick the 'objects' not classes.
Second, having a list of "tasks" will lead you down the road of linear programming.
Instead of "Initialize and shuffle the deck", you will probably have a 'Deck'
(A Card collection manager) with a constructor and an exposed method to 'shuffle'
itself.
Instead of "Input and Verify the number of players", you will have a 'Game'
with the number of players likely to be passed to the constructor. 'Players'
will have 'Hands' (card collection) that contain a 'compare' method, ....
Or maybe you will have a table, that has a number of players in an order,
one of whom can message the Deck to 'deal', 'call', etc....
>
>One design I tried was to first create a Card class, then create Deck and
>Hand classes which contain Card objects. My implementation of this design
>seemed hard to understand.
>
Keep trying. The most interesting feature of OO (to me anyway when I started
in), was that, while at first it was foreign and strange, there is always
is a certain elegance and a sense of 'correctness' about any solution. Which
makes sense, because OO is closer to the way people think, not the way computers
think. But with that said, also remember there is NO one right design - just
degrees of a good fit for the problem at hand.
>
>Again, I would appreciate any suggestions on which classes to use.
>
First blush objects:
Player
Hand
Card
Deck
Table
Game
-
Re: Program Design
i have already written a deck class ... complete with shuffling and it uses
a card struct for the deck array ... if you want some more info on this and
the source code ... e-mail me ...
"James Curran" <JamesCurran@mvps.org> wrote:
>"mstolnic" <mstolnic@mediaone.net> wrote in message
>news:3bd86470$1@news.devx.com...
>
>> One design I tried was to first create a Card class, then create Deck
and
>> Hand classes which contain Card objects. My implementation of this design
>> seemed hard to understand.
>
> That sounds about right. You'll probably also need a "Game" class which
>hold a Deck and two Hand objects.
>
> The next trick is to decide who gets what member function. Shuffling
&
>more importantly, setting up suits & ranks is the job of Deck. Each Hand
>determines it's own score, but Game decides which is bigger.
>
>--
>Truth,
>James Curran
>www.NJTheater.com (Professional)
>www.NovelTheory.com (Personal)
>www.BrandsForLess.Com (Day Job)
>
>
>
>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|