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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
|
#include<iostream>
#include<conio.h>
#include<iomanip>
using namespace std;
void Rules();
void SplashScreen();
void GenCompHand(int cHand[5]);
void GenPlayHand(int pHand[5], int pSuit[5]);
void ShowCard(int value, int suit);
void Guess(char &guess, int pHand[5]);
bool VldCard(char guess, int pHand[5]);
int CharInt(char guess);
int main(){
SplashScreen();
int cHand[5]; int pHand[5]; int pSuit[5];
char guess;
GenCompHand(cHand);
GenPlayHand(pHand, pSuit);
system("cls");
cout << "Player's Hand:"<<endl;
for (int i = 0; i < 5; i++){
ShowCard(pHand[i], pSuit[i]);
}
Guess(guess, pHand);
_getch();
return 0;
}
void Rules()
//Shows the rules of this version of Go Fish
{
system("cls");
cout << "*******************************************************************************" << endl;
cout << "______ _ " << endl;
cout << "| ___ \\ | | " << endl;
cout << "| |_/ / _| | ___ ___ " << endl;
cout << "| / | | | |/ _ \\/ __|" << endl;
cout << "| |\\ \\ |_| | | __/\\__ \\"<<endl;
cout << "\\_| \\_\\__,_|_|\___||___/" << endl;
cout << "*******************************************************************************"<<endl;
cout << "In Go Fish, You will be given 5 cards. The object is to get a pair of the same\ncards,";
cout << " for example, two 2s. You and the computer will take turns guessing cards\nto try to";
cout << "get a pair of cards. If you guess a card the computer does not have,\nyou will draw a card.";
cout << " You will be asked to discard a card in your hand if\nyou already have 5 cards in your hand."<<endl;
cout << "The first player to reach 10 pairs will be the winner." << endl;
cout << "*******************************************************************************" << endl<<endl;
cout << "Press any key to continue..."<<endl;
_getch();
}
void SplashScreen()
//Displays a neat-o start screen
{
cout << "********************************************"<<endl;
cout << " _____ ______ _ _ " << endl;
cout << "| __ \\ | ___(_) | | " << endl;
cout << "| | \\/ ___ | |_ _ ___| |__ " << endl;
cout << "| | __ / _ \\ | _| | / __| '_ \ " << endl;
cout << "| |_\\ \\ (_) | | | | \\__ \\ | | |" << endl;
cout << " \\____/\\___/ \\_| |_|___/_| |_|" << endl;
cout << "********************************************" << endl;
cout << "Press any key to head on over to the rules!"<<endl;
cout << "********************************************" << endl;
_getch();
Rules();
}
void ShowCard(int value, int suit)
/* Draws an ASCII art image to show the card
Pre: value must be 1(for Ace), 2-10, or 11(Jack), 12(Queen), 13(King)
suit must be 3(heart), 4(diamond), 5(clubs), 6(spades) to show legit. card suit
Post: Card has been displayed, cursor is on next line. Fill style set back to default, spaces.
*/
{
cout << setfill('-') << setw(9) << "" <<endl;
if (value == 10)
cout << "| " << value << setfill(' ') << setw(4) << "" << "|" << endl;
else if (value == 1)
cout << "| " << "A" << setfill(' ') << setw(5) << "" << "|" << endl;
else if (value == 11)
cout << "| " << "J" << setfill(' ') << setw(5) << "" << "|" << endl;
else if (value == 12)
cout << "| " << "Q" << setfill(' ') << setw(5) << "" << "|" << endl;
else if (value == 13)
cout << "| " << "K" << setfill(' ') << setw(5) << "" << "|" << endl;
else
cout << "| " << value << setfill(' ') << setw(5) << "" << "|" << endl;
cout << "| " << (char)suit << setfill(' ') << setw(5) << "" << "|" << endl;
cout << "| " << setw(6) << "" << "|" << endl;
cout << "|" << setw(5) << "" << (char)suit << " |" << endl;
if (value == 10)
cout << "|" << setw(4) << "" << value << " |" << endl;
else if (value == 1)
cout << "|" << setw(5) << "" << "A" << " |" << endl;
else if (value == 11)
cout << "|" << setw(5) << "" << "J" << " |" << endl;
else if (value == 12)
cout << "|" << setw(5) << "" << "Q" << " |" << endl;
else if (value == 13)
cout << "|" << setw(5) << "" << "K" << " |" << endl;
else
cout << "|" << setw(5) << "" << value << " |"<<endl;
cout << setfill('-') << setw(9) << ""<<endl;
cout << setfill(' ');
}
void GenCompHand(int cHand[5])
//Randomly generates the computer's hand
{
for (int i = 0; i < 5; i++)
cHand[i] = rand() % 13 + 1;
}
void GenPlayHand(int pHand[5], int pSuit[5])
//Randomly Generates the Player's Hand
{
for (int i = 0; i < 5; i++){
pHand[i] = rand() % 13 + 1;
pSuit[i] = rand() % 4 + 3;
}
}
void Guess(char &guess, int pHand[5])
//Grabs the guess from the user
{
bool valid = true;
do{
cout << "Which card would you like to choose?: ";
cin >> guess;
if (guess == 'a' || guess == 'A')
valid = VldCard(1, pHand);
else if (guess == 'j' || guess == 'J')
valid = VldCard(11, pHand);
else if (guess == 'q' || guess == 'Q')
valid = VldCard(12, pHand);
else if (guess == 'k' || guess == 'K')
valid = VldCard(13, pHand);
else{
int nGuess = CharInt(guess);
valid = VldCard(nGuess, pHand);
}
} while(valid);
}
int CharInt(char guess)
//converts the guess of type char to a numerical value for comparison
{
if (guess == '1')
return 10;
else if (guess == '2')
return 2;
else if (guess == '3')
return 3;
else if (guess == '4')
return 4;
else if (guess == '5')
return 5;
else if (guess == '6')
return 6;
else if (guess == '7')
return 7;
else if (guess == '8')
return 8;
else if (guess == '9')
return 9;
}
bool VldCard(int guess, int pHand[5])
/*Checks to see if the guess the player entered is in the player's hand
returns true if not in hand, false otherwise*/
{
if (guess == pHand[0] || guess == pHand[1] || guess == pHand[2] || guess == pHand[3] || guess == pHand[4])
return false;
return true;
}
|