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 169 170 171 172 173 174 175 176 177
|
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int sumofarray(int d[]);
void restartgame();
void turnplayer1(int player1[],string deck[],int player2[]);
void turnplayer2(int player2[],string deck[],int player1[]);
void endgame();
int main()
{
string deck[53]= {"---------------","Ace of Clubs ","2 of Clubs ","3 of Clubs ","4 of Clubs ","5 of Clubs ","6 of Clubs "
,"7 of Clubs ","8 of Clubs ","9 of Clubs ","10 of Clubs ","Jack of Clubs ","Queen of Clubs ","King of Clubs ","Ace of Diamonds"
,"2 of Diamonds ","3 of Diamonds ","4 of Diamonds ","5 of Diamonds","6 of Diamonds","7 of Diamonds","8 of Diamonds","9 of Diamonds"
,"10 of Diamonds","Jack of Diamonds","Queen of Diamonds","King of Diamonds","Ace of Hearts ","2 of Hearts ","3 of Hearts ","4 of Hearts "
,"5 of Hearts ","6 of Hearts ","7 of Hearts ","8 of Hearts ","9 of Hearts ","10 of Hearts ","Jack of Hearts ","Queen of Hearts"
,"King of Hearts ","Ace of Spades ","2 of Spades ","3 of Spades ","4 of Spades ","5 of Spades ","6 of Spades ","7 of Spades "
,"8 of Spades " ,"9 of Spades ","10 of Spades ","Jack of Spades ","Queen of Spades","King of Spades "};
int array[52]={0};
int x=1,y=0;
srand(time(0));
array[0]=rand()%52+1;
do
{
array[x]=rand()%52+1;
y=0;
while (y<x)
{
if (array[y]==array[x])
{
--x;
break;
}
++y;
}
++x;
} while (x<52);
int *shuffle=array;
int player1[26];
int player2[26];
for(int a=0;a<26;a++){
player1[a]=shuffle[a];
}
for (int i=0;i<26; i++){
player2[i]=shuffle[i+26];
}
for (int c=0;c<26;c++){
cout <<player1[c]<<"*\t";
}
cout<<"\n\n";
for (int e=0;e<26;e++){
cout <<player2[e]<<"^\t";
}
cout<<"\n\n";
cout <<"Player 1 :\t\t\t\tPlayer 2 : \n";
for (int d=0;d<26;d++){
int v=player1[d];
int c =player2[d];
cout <<d<<" = " <<deck[v]<<"\t\t\t"<<d<<" = " <<deck[c]<<"\n";
}
do
{
turnplayer1(player1,deck,player2);
}
while (-1);
}
int sumofarray(int d[]){
int k=0;
for(int i=0;i<26;i++){
k=k+d[i];
}
return k;
}
void restartgame(){
cout << "Restart? <Y/N> ";
char lol;
cin>>lol;
if (lol=='Y'){
main();
}
else if (lol=='N'){
endgame();
}
else {
restartgame();
}
}
void turnplayer1(int player1[],string deck[],int player2[]){
int e=sumofarray(player1);
cout <<e<<"!!!";
if(e==0){
cout <<"Player 1 wins!\n";\
restartgame();
}
else{
cout << "Enter the desired card to withdraw Player 1: ";
int yolo;
cin >> yolo;
cout << "Player 1 : "<< deck[player1[yolo]]<<endl;
int z = player1[yolo];
if (z==0){
turnplayer1(player1,deck,player2);
}
else{
cout <<z<<" and "<<z%13<<endl;
player1[yolo]=0;
if (z%13==2){
turnplayer2(player2,deck,player1);
turnplayer2(player2,deck,player1);
}
else if(z%13==3){
turnplayer2(player2,deck,player1);
turnplayer2(player2,deck,player1);
turnplayer2(player2,deck,player1);
}
else{
turnplayer2(player2,deck,player1);
}
}
}
}
void turnplayer2(int player2[],string deck[],int player1[]){
int e=sumofarray(player2);
cout <<e<<"!!!";
if(e==0){
cout <<"Player 2 wins!\n";\
restartgame();
}
else{
cout << "Enter the desired card to withdraw Player 2: ";
int yo;
cin >> yo;
cout << "Player 2 : "<< deck[player2[yo]]<<endl;
int z = player2
[yo];
if (z==0){
turnplayer2(player2,deck,player1);
}
else{
player2[yo]=0;
if (z%13==2){
turnplayer1(player1,deck,player2);
turnplayer1(player1,deck,player2);
}
else if(z%13==3){
turnplayer1(player1,deck,player2);
turnplayer1(player1,deck,player2);
turnplayer1(player1,deck,player2);
}
else{
turnplayer1(player1,deck,player2);
}
}
}
}
void endgame(){
cout <<"Thank you";
}
|