943,923 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1519
  • C++ RSS
Apr 29th, 2006
0

need help creating a "stack" of cards

Expand Post »
i need some help on this, im making a blackjack game and i need to make a stack of cards and i dont know what to do so just get me started is all im really askin for.

here is what i have so far

C++ Syntax (Toggle Plain Text)
  1. #include <stack>
  2. #include <list>
  3. #include <iostream>
  4. #include <conio.h>
  5. #include <string>
  6.  
  7. using namespace std;
  8.  
  9. const DECKS = 8;
  10.  
  11. enum suit { Clubs, Diamonds, Hearts, Spades};
  12. enum value { Ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King};
  13.  
  14. /****************************************************/
  15. class Node
  16. {
  17. private:
  18. int data;
  19. Node* next;
  20.  
  21. public:
  22. Node();
  23. Node(int data);
  24. ~Node(){};
  25. Node(Node& node);
  26. Node& operator = (Node& node);
  27.  
  28. int getData() {return data;};
  29. Node* getNext() {return next;};
  30.  
  31. void setData(int data) { this->data = data;};
  32. void setNext(Node* next) { this->next = next;};
  33. };
  34.  
  35. Node::Node()
  36. {
  37. data = 0;
  38. next = NULL;
  39. }
  40.  
  41. Node::Node(int data)
  42. {
  43. this->data = data;
  44. next = NULL;
  45. }
  46.  
  47. Node::Node(Node& node)
  48. {
  49. this->data = node.data;
  50. next = NULL;
  51. }
  52.  
  53. Node& Node::operator= (Node& node)
  54. {
  55. this->data = node.data;
  56. next = NULL;
  57. return *this;
  58. }
  59. /**************************************************************/
  60.  
  61. /**************************************************************/
  62. struct Card
  63. {
  64. stack<Card> deck;
  65. static int counters[52 * DECKS];
  66.  
  67. int jack,
  68. queen,
  69. king;
  70.  
  71. int ace();
  72. Card();
  73. ~Card();
  74. Card (Card& card);
  75. Card operator = (Card& card);
  76. };
  77.  
  78. Card::Card()
  79. {
  80. jack = 10;
  81. queen = 10;
  82. king = 10;
  83. }
  84.  
  85. int ace()
  86. {
  87. int choice;
  88.  
  89. cout << "do you want your Ace/s to be a 1 or an 11?" << endl;
  90. cin >> choice;
  91.  
  92. return choice;
  93. }
  94. /**************************************************************/
  95. class Player
  96. {
  97. private:
  98.  
  99.  
  100. static int players;
  101. int val; // sum of all the cards
  102.  
  103. public:
  104.  
  105. Player();
  106. ~Player();
  107. Player (const Player& player);
  108. int getSize() {return size};
  109.  
  110.  
  111. };
  112.  
  113. Player::Player()
  114. {
  115. val = 0;
  116.  
  117. }
  118.  
  119. class Playerlist
  120. {
  121. private:
  122.  
  123. int size; //number of players
  124. Player* player; // array
  125.  
  126. public:
  127. Playerlist();
  128. ~Playerlist();
  129. Playerlist (const Playerlist& playerlist);
  130. int getSize() {return size;}
  131.  
  132. Player* getPlayer(int index) {return &player[index];}
  133. };
  134.  
  135. Playerlist::Playerlist()
  136. {
  137. player = NULL;
  138. cout << "How many players will be playing? " << endl;
  139.  
  140. cout << "* Number of players should not exceed the cubic dimensions * " << endl;
  141. cin >> size;
  142. player = new Player [size];
  143.  
  144. }
  145.  
  146. Playerlist::~Playerlist()
  147. {
  148. delete [] player;
  149. }
  150.  
  151. Playerlist::Playerlist (const Playerlist& playerlist)
  152. {
  153. size = playerlist.size;
  154. player = new Player [size];
  155. for(int s = 0; s < size; s++)
  156. player[s] = playerlist.player[s];
  157. }
  158. /***************************************************************/
  159. int Player::players = 1; //static players
  160.  
  161. void main()
  162. {
  163. Playerlist p;
  164. Card c;
  165.  
  166. }
Similar Threads
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
tyczj is offline Offline
91 posts
since Mar 2005
Apr 29th, 2006
0

Re: need help creating a "stack" of cards

I've not tried your code but it looks to be well organised. Was there a specific question you wanted to ask regarding the game?
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Apr 29th, 2006
0

Re: need help creating a "stack" of cards

What exactly are you going to do with your deck of cards? I presume you'll have some common routines such as "shuffle", "cut deck", etc. but different card games use different rules. A totally generic deck might not be possible, or even desirable. I suggest you decide first which games you want to simulate, then you'll get a much clearer idea of what to do. Not all card games treat the deck as a stack either. some card games treat it more like a queue, others involve a random draw from the middle - keep that in mind when you decide what sort of container to keep the cards in.
Reputation Points: 307
Solved Threads: 62
Posting Pro
Bench is offline Offline
565 posts
since Feb 2006
Apr 29th, 2006
0

Re: need help creating a "stack" of cards

its goin to be casino like but im not goin to follow all the ruled there will be 8 decks in the stack of cards and u just take a card from the top of the deck after its shuffled. im not goin to bother with cutting the eck though

i dont think my code actually works i got a few error i think still with the enumerator types but i dont know how to start the stack of cards. i have to do that to basically do the rest of the program so i know what everything is
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
tyczj is offline Offline
91 posts
since Mar 2005
Apr 30th, 2006
0

Re: need help creating a "stack" of cards

It sounds like you're trying to do a bit too much at once - start out with getting the program to compile with just one card.. then get it to compile with a deck of cards... then take small steps adding more functionality as yóú go.
Personally i'd change the Card structure. To my mind, the only 2 bits of information a playing card holds are its suit and its rank - a card doesn't hold information about the rest of the deck.

The enums are definitely erroneous, you can't begin an identifier with a number, so you'll need to use
ace, two, three, four, five etc, instead.
Reputation Points: 307
Solved Threads: 62
Posting Pro
Bench is offline Offline
565 posts
since Feb 2006
Apr 30th, 2006
0

Re: need help creating a "stack" of cards

see thats the thing i dont even know how about make one card let alone a stack of them and i fixed the enum thing and it compiles now
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
tyczj is offline Offline
91 posts
since Mar 2005
Apr 30th, 2006
0

Re: need help creating a "stack" of cards

Should b simple, u can do this without a class heirarchy anyhoo.

An idea is the same, regardless of how you choose to represent it. Get it down on paper then continue from there.

ThanQ
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Array of pointers
Next Thread in C++ Forum Timeline: been at this for 5 hrs now and can't figure it out please help...





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC