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
|
#include <cstdlib>
#include <iostream>
#include <time.h>
using namespace std;
void menu(){
cout << "1. Play" << endl;
cout << "2. Quit" << endl;
}
int iRandomCards(int x, int y, int a, int b){
x = rand() % 10 + 1;
y = rand() % 10 + 1;
a = rand() % 10 + 1;
b = rand() % 10 + 1;
}
int
main()
{
srand (time(NULL));
int iInput, iElevenOne, iFirst, iSecond, iThird, iForth, iDrawCard, iTotal;
char cInput;
menu();
cin >> iInput;
if (iInput == 1){
cout << "You have ";
iRandomCards(iFirst, iSecond, iThird, iForth);
cout << "a " << iFirst << " and a " << iSecond << endl;
cout << "Your opponent has a " << iThird << " and a " << iForth << endl;
if (iFirst == 1){
cout << "1 or 11: ";
cin >> iElevenOne;
if (iElevenOne == 1){
iFirst = 1;
}
else if(iElevenOne == 11){
iFirst = 11;
}else{}
if (iSecond == 1){
cout << "1 or 11: ";
cin >> iInput;
if (iElevenOne == 1){
iSecond = 1;
}else if (iElevenOne == 11){
iSecond = 11;
}else{}
}
}
iTotal = iFirst + iSecond;
cin.get();
do{
cout << "Draw a card Y/N: ";
cin >> cInput;
if(cInput == 'Y' || cInput == 'y'){
iDrawCard = rand() % 10 + 1;
iTotal + iDrawCard;
cout << "You have: " << iTotal << endl;
}else
{
break;
}
}while(cInput == 'Y' || cInput == 'y');
if (iTotal > 21){
cout << "You lost" << endl;
cin.get();
}else if(iTotal == 21){
cout << "You won!" << endl;
cin.get();
}else if(iTotal > (iThird + iForth)){
cout << "You won!" << endl;
cin.get();
}else{
cout << "You lost" << endl;
cin.get();
}
}
} |
Partager