6 Replies - 2560 Views - Last Post: 13 December 2010 - 10:20 AM Rate Topic: -----

#1 beker22  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 13-December 10

Inheritance in a poker game

Posted 13 December 2010 - 07:48 AM

Hi everyone,

I need to write a poker game.
My problem is that I have to use inheritance, but I can't find
where should I use it.
I have the classes: Deck , Card , Hand , Player , Round
How can I connect any of these classes with inheritance (maybe i'm missing some classes...)
I will be glad if someone will give me some examples.

Thank You.
Is This A Good Question/Topic? 0
  • +

Replies To: Inheritance in a poker game

#2 jimblumberg  Icon User is offline

  • member icon

Reputation: 5466
  • View blog
  • Posts: 17,018
  • Joined: 25-December 09

Re: Inheritance in a poker game

Posted 13 December 2010 - 09:12 AM

Well isn't a Deck 52 Cards? A Hand several cards?

Jim
Was This Post Helpful? 0
  • +
  • -

#3 Guest_Guest*


Reputation:

Re: Inheritance in a poker game

Posted 13 December 2010 - 09:31 AM

yeah, but class deck will contain a list of cards ,
and class hand will contain a vector of cards.
It's not inheritance...
Was This Post Helpful? 0

#4 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon


Reputation: 7161
  • View blog
  • Posts: 14,927
  • Joined: 16-October 07

Re: Inheritance in a poker game

Posted 13 December 2010 - 09:40 AM

No, a Deck an a Hand should be fundamentally the same thing. They are both a collection of cards. Both can inherit from something like CardCollection.

A Player would have a Hand. However, if you're looking for silly inheritance, a Player can extend Hand.
Was This Post Helpful? 0
  • +
  • -

#5 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6246
  • View blog
  • Posts: 24,014
  • Joined: 23-August 08

Re: Inheritance in a poker game

Posted 13 December 2010 - 09:41 AM

Yeah, this is a weird assignment. As you rightly point out, poker lends itself to containment (the exact term is escaping me at the moment) rather than inheritance. There is no inherent is-a relationship there, unless you somehow wanted to make face cards a special implementation of a base Card class, or the players were potentially AI players of different strengths which all inherit from a base Player class.

I would think you might want to speak to your instructor about this.

This post has been edited by JackOfAllTrades: 13 December 2010 - 09:42 AM

Was This Post Helpful? 0
  • +
  • -

#6 Guest_beker22*


Reputation:

Re: Inheritance in a poker game

Posted 13 December 2010 - 09:49 AM

Thanks...
Was This Post Helpful? 0

#7 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1853
  • View blog
  • Posts: 6,671
  • Joined: 19-February 09

Re: Inheritance in a poker game

Posted 13 December 2010 - 10:20 AM

I was thinking of having a suit class and a rank class.

Edit: Baavgai's idea sounds better though.

This post has been edited by #define: 13 December 2010 - 01:45 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1