Yeah, @fun2code, I solved that problem and a few others but ended up stuck because the inheritance wouldn't work with what I had. @pearlyman, I have some code, but it is so jumbled that I just need to restart. @AbstractionAnon, thanks for the help on the outline above. I have searched quite a bit but haven't found a way to setup the deck, then deal one card at a time to separate players. I know that people don't want to simply give the answers, which is understandable, but I do like to see some code examples.
So here are the requirements:
You will create a program to play a game of Poker. This will be an easy game of Poker.
You will need to create the StudPoker class. We will use the following rules:
Players: 2 – 6
Supplies: 1 Deck of cards (52 total)
Objective: Get as many points as possible by playing n games/hands of the following
Stud Poker rules. If there is more than one player with the same high hand then they
split the pot for that game. After a card has been dealt to each player, they have a
chance to bet. They specify a number of points, which are added to the pot while
decreasing the amount of Points they have. Unlike real poker they cannot pass. At the
end of the game, after 5 rounds the player with the highest hand gets the current pot.
That amount is added to his set of Points and the pot is emptied. After n games, the
player with the most Points wins. This game is not table stakes, so the players can have
a negative balance.
Playing: Start by dealing 1 card to each player. The player who received the first card is
the first to bet. They can choose to drop out by betting 0. They will forfeit all money they
have put in the pot and will not be dealt any more cards. After all players have bet,
another card is dealt. This continues until the last player has 5 cards or if all but one player has dropped. All cards are then revealed and the winner is determined according
to this list, hands ranked lowest to highest value: (then the assignment shows the standard hands and rankings, such as pairs, three of a kind, etc.
Here is some stuff I have started, but I really think I need to start from scratch because this isn't going to work out.
functions.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
#include "card_games.h"
#include <iostream>
#include <ctime>
#include <cstdlib> //for rand and srand
#include <cstdio>
#include <string>
using std::cin;
using std::cout;
using std::endl;
string StudPoker::deckFunction () {
srand(time(0));
struct card deck[52]; // An array of cards named deck, size 52
const string ranks[ ] = { "Ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight",
"Nine", "Ten", "Jack", "Queen", "King" };
const string suits[ ] = { "Diamonds", "Hearts", "Spades", "Clubs" };
int k = 0;
for ( int i = 0; i < 13; i++)
{
for ( int j = 0; j < 4; j++)
{
deck[ k ].rank = ranks[ i ];
deck[ k ].suit = suits[ j ];
k++;
}
}
int RandIndex = rand() % 13;
int RandIndex2 = rand() % 4;
return ranks[RandIndex] + " of " + suits[RandIndex2];
}
void StudPoker::player1hand() {
}
|
main.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
#include <iostream>
#include "card_games.h"
using std::cin;
using std::cout;
using std::endl;
int main(int argc, char **argv)
{
StudPoker deckF;
cout << deckF.deckFunction() << endl;
return 0;
}
|
card_games.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
#ifndef HEADER_H
#define HEADER_H
#include <string>
using namespace std;
class StudPoker{
public:
string deckFunction();
void player1hand();
//void playerHand(ranks, suits);
struct card{
string rank;
string suit;
int value;
};
private:
string ranks;
string suits;
};
#endif // HEADER_H
|
Thanks guys!