[Games] Start! The UNO! -demo
version demo0.3
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<ctime>
#include<windows.h>
//2*4*10 p 2*12 +2 2*2 +4 2*4 w 2*8 c 2*8 s = 148
using namespace std;
vector<int> p[4];
int uno[46],form,totplayer,pl,order=1,rc[5];
string sform;
void startUNO(int pn,int size){
srand(time(NULL));
for(int i=1;i<=pn;++i){
rc[i]=size;
}
for(int i=1;i<=40;++i){
uno[i]=2;
}
uno[41]=24;
uno[42]=4;
uno[43]=8;
uno[44]=16;
uno[45]=16;
for(int k=1;k<=pn;++k){
for(int i=1;i<=size;++i){
int j=rand()%46;
while(uno[j]==0){
j=rand()%46;
}
p[k].push_back(j);
}
}
}
void printUNO(int totplayer){
system("cls");
if(form!=0){
cout<<"Last "<<sform<<endl;
}
cout<<"Player "<<totplayer<<endl;
for(int i=0;i<=p[totplayer].size()-1;++i){
cout<<i+1<<" ";
if((p[totplayer][i]-1)/10==0){
cout<<"Red "<<(p[totplayer][i]-1)%10<<endl;
}
else if((p[totplayer][i]-1)/10==1){
cout<<"Blue "<<(p[totplayer][i]-1)%10<<endl;
}
else if((p[totplayer][i]-1)/10==2){
cout<<"Green "<<(p[totplayer][i]-1)%10<<endl;
}
else if((p[totplayer][i]-1)/10==3){
cout<<"Yellow "<<(p[totplayer][i]-1)%10<<endl;
}
else if(p[totplayer][i]==41){
cout<<"+2"<<endl;
}
else if(p[pl][i]==42){
cout<<"+4"<<endl;
}
else if(p[pl][i]==43){
cout<<"ACL"<<endl;
}
else if(p[pl][i]==44){
cout<<"Change"<<endl;
}
else if(p[pl][i]==45){
cout<<"Stop"<<endl;
}
}
cout<<endl;
}
bool flag;
void outUNO(){
flag=false;
printUNO(pl);
while(flag!=true){
flag=false;
cout<<"Put a card off >>";
int pc;
cin>>pc;
pc--;
if(form==0||((p[pl][pc]-1)%10==(p[pl][form]-1)%10)||((p[pl][pc]-1)/10==(p[pl][form]-1)/10)){
if((p[pl][pc]-1)/10==0){
sform="Red ";
}
else if((p[pl][pc]-1)/10==1){
sform="Blue ";
}
else if((p[pl][pc]-1)/10==2){
sform="Green ";
}
else if((p[pl][pc]-1)/10==3){
sform="Yellow ";
}
sform.push_back((p[pl][pc]-1)%10+'0');
form=p[pl][pc];
p[pl].erase(p[pl].begin()+pc);
flag=true;
}
else if(p[pl][pc]==41||p[pl][pc]==42){
}
if(flag==true){
system("cls");
cout<<"Off "<<sform<<" Successfully."<<endl<<"Next : Player "<<pl<<endl<<"Please turn to next player now."<<endl<<endl;
system("pause");
if(pl+order>totplayer||pl+order<1){
if(order==1){
pl=1;
}
else{
pl=totplayer;
}
}
else{
pl+=order;
}
}
else{
cout<<"Wrong card."<<endl;
}
}
}
int main(){
cout<<"Putin the number of players >>";
cin>>totplayer;
cout<<"Putin the number of cards >>";
int c;
cin>>c;
pl=1;
cout<<"Next : Player "<<pl<<endl<<"Please turn to next player now."<<endl<<endl;
system("pause");
startUNO(totplayer,c);
while(1){
outUNO();
}
// printUNO(2);
}