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
|
#include<iostream>
#include<string>
#include<vector>
#include<time.h>
#include<stdlib.h>
#include<conio.h>
#include<algorithm>
using namespace std;
int cards(vector <int> deck, vector<int> p1,vector <int> p2);
int discard(vector<int> deck, vector<int> p1);
int win_lose(vector<int> p1, vector<int> p2);
int main()
{ system("color A1");
vector<int> deck;
srand(time(0));
deck.reserve(51);
vector <int> p1,p2;
cards(deck,p1,p2);
cout<<"Your cards are:";
for(int i=0; i<5;++i)
{cout<<p1[i]<<" ";}
win_lose(p1,p2);
_getch();
return 0;
}
int cards(vector <int> deck, vector<int> p1,vector <int> p2)
{ for(int i=1; i<=14; ++i)
for(int y=0; y<5; ++y)
{ deck.push_back(i);}
random_shuffle(deck.begin(),deck.end());
for(int i=0; i<5; ++i) { p1.push_back(deck[i]);}
for(int i=0; i<5; ++i) { p2.push_back(deck[i+5]);}
return 0;}
int discard(vector<int> deck, vector<int> p1)
{ cout<<"\n How many cards would you like to discard?\n";
cout<<"(type 1, 2, or 3, 0 if you wisk to discard no card)\n";
int wish_discard; int c_discard=0;
cin>>wish_discard;
while(c_discard<wish_discard)
{ cout<<"\n Which card would you like to discard?\n(1 for first, 2 for second and so on)\n";
int wish; cin>>wish;
while(wish>5) { cout<<"\nYou have only 5 cards in your hand! Please chose a valid one!\n"; cin>>wish;}
p1[wish]=rand()%13+1;
cout<<"Your cards are:";
for(int i=0; i<5;++i)
{ cout<<p1[i]<<"\t";} }
return 0;}
int win_lose(vector<int> p1, vector<int> p2)
{ cout<<"\nYour opponent cards are:\n";
for(int i=0; i<5;++i)
{ cout<<p2[i+5]<<"\t";}
int p1bonus=p1[0]+p1[1]+p1[2]+p1[3]+p1[4];
int p2bonus=p1[0+5]+p1[1+5]+p1[2+5]+p1[3+5]+p1[4+5];
cout<<"\nYour score is:"<<p1bonus<<endl;
cout<<"\nYour opponent's score is:"<<p2bonus<<endl;
if(p1>p2) {cout<<"Congrats, you won!";}
else if(p2<p1) {cout<<"Bad luck, you lose!";}
else {cout<<"It's a tie!";}
return 0;}
|