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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
#include <ctime>
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
//5. Write a program to play poker! You can provide 5 cards to the player, let that player choose new
//cards, and then determine how good the hand is. Think about whether this is easy to do? What
//problems might you have in terms of keeping track of cards that have been drawn already? Was this
//easier or harder than the slot machine?
string cards[13] = {"2", "3", "4", "5", "6","7", "8", "9","10", "j", "q", "k","Ace"};
string suits[4] = {" of Hearts", " of Spades", " of Diamond", " of Clubs" };
int randcard() {
return rand() % 13;
}
int randsuits(){
return rand() % 4;
}
string* drawHand()
{
string* hand = new string[5];
for(int i=0; i<5; i++){
hand[i] = cards[randcard()] + suits[randsuits()];
}
return hand;
}
string* replaceHand(int i)
{
string* hand = drawHand();
string* newhand; /// if i remove the pointer, I cant send new hand to hand.
newhand[i] = cards[randcard()] + suits[randsuits()];
newhand[i] = hand[i];
return newhand;
}
void displayHand(){
string* hand = drawHand();
cout << "1." << hand[1] << endl;
cout << "2." << hand[2] << endl;
cout << "3." << hand[3] << endl;
cout << "4." << hand[4] << endl;
cout << "5." << hand[5] << endl;
}
string winningHands(){
string* hand = drawHand();
if(hand[1] += 1) == hand[2] && (hand[2] += 1) == hand[3] && (hand[3] += 1) == hand[4] && (hand[4] +=1) == hand[5])
{
return "You have a straight flush!!";
}
/* TODO: Change this if statement to check the hand that was drawn.
You'll probably need a for loop.
if(hand() == "j of Clubs" && hand() == "10 of Clubs" && hand() == "9 of Clubs" && hand() == "8 of Clubs" && hand() == "7 of Clubs"){
return "You have a straight flush!!";
}
if(hand() == " of Clubs" && hand() == " of Hearts" && hand() == " of Spades" && hand() == " of Diamond" ){
return "You have four of a kind!!";/// comparing a partial string, not sure if this is correct
}
*/
return 0;
delete[] hand;
}
int main() {
srand( time( NULL ) );
int newCard(-1);
string* hand = drawHand();
char confirmHand;
do{
cout << "Input the card number that you wish to replace" << endl;
displayHand();
cin << /* << Error?? */ newCard; // inputs 2
replaceHand(newCard);
displayHand();
cout << "Are you pleased with your hand? y/n" << endl;
cin << /* << Error?? */ confirmHand;
if(confirmHand == y){
cout << winningHands() << endl; //// incomplete
}else{
cout << " input the card that you wish to replace" << endl;
cin << /* << Error?? */newCard;
replaceHand(newCard);
}
}while(!winningHands);
system ("PAUSE");
}
|