need help creating a "stack" of cards

Reply

Join Date: Mar 2005
Posts: 91
Reputation: tyczj is an unknown quantity at this point 
Solved Threads: 1
tyczj tyczj is offline Offline
Junior Poster in Training

need help creating a "stack" of cards

 
0
  #1
Apr 29th, 2006
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

  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. }
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,321
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 384
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: need help creating a "stack" of cards

 
0
  #2
Apr 29th, 2006
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?
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 519
Reputation: Bench is a jewel in the rough Bench is a jewel in the rough Bench is a jewel in the rough 
Solved Threads: 53
Bench's Avatar
Bench Bench is offline Offline
Posting Pro

Re: need help creating a "stack" of cards

 
0
  #3
Apr 29th, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 91
Reputation: tyczj is an unknown quantity at this point 
Solved Threads: 1
tyczj tyczj is offline Offline
Junior Poster in Training

Re: need help creating a "stack" of cards

 
0
  #4
Apr 29th, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 519
Reputation: Bench is a jewel in the rough Bench is a jewel in the rough Bench is a jewel in the rough 
Solved Threads: 53
Bench's Avatar
Bench Bench is offline Offline
Posting Pro

Re: need help creating a "stack" of cards

 
0
  #5
Apr 30th, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 91
Reputation: tyczj is an unknown quantity at this point 
Solved Threads: 1
tyczj tyczj is offline Offline
Junior Poster in Training

Re: need help creating a "stack" of cards

 
0
  #6
Apr 30th, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,321
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 384
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: need help creating a "stack" of cards

 
0
  #7
Apr 30th, 2006
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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 1378 | Replies: 6
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC