跳到正文

剪贴板

剪贴板 hzwnu7k7

原文
剪贴板信息

剪贴板信息

收录
更新

console_color.h

C++
#include<bits/stdc++.h>
#include"console_color.h"
using namespace std;
//#define DEBUG


#define R 1
#define Y 2
#define B 3
#define G 4
#define W 5

#define MAX_PLAYER 10
namespace _wrk{;
struct card{
	int typ;
	int id;
	string da;
	int sco;
	void pr(){
		wcout<<ConsoleColor::Black;
		switch(typ){
			case R:
				wcout<<ConsoleBackgroundColor::Red;
				break;
			case B:
				wcout<<ConsoleBackgroundColor::Blue;

				break;
			case Y:
				wcout<<ConsoleBackgroundColor::Yellow;

				break;
			case G:
				wcout<<ConsoleBackgroundColor::Green;

				break;
			case W:
				wcout<<ConsoleBackgroundColor::White;

				break;
		}
		cout<<da;
		wcout<<ConsoleBackgroundColor::Black;
		wcout<<ConsoleColor::White;
	}
	bool operator<(const card &f)const{
		return typ==f.typ?id<f.id:typ<f.typ;
	}
};
vector<card>card_list;
deque<card>s;
	mt19937 w;
void init_card(){

	for(int i=0;i<14;i++){
		string s=to_string(i);
		if(i==10)s="skip";
		if(i==11)s="reverse";
		if(i==12)s="+2";
		if(i==13)s="all";
		int t=(i>=10?20:i);
		for(int j=0;j<=bool(i);j++){
			card_list.push_back({R,i,s,t});
			card_list.push_back({B,i,s,t});
			card_list.push_back({G,i,s,t});
			card_list.push_back({Y,i,s,t});
		}
	}
	for(int i=0;i<8;i++){
		card_list.push_back({W,50,"anycol",50});
		card_list.push_back({W,51,"+4",50});
	}
	shuffle(card_list.begin(),card_list.end(),w);
	for(auto x:card_list){
		#ifdef DEBUG
		x.pr();
		int u=1e6;
		while(u--)rand();
		cout<<endl;
		#endif
		s.push_back(x);
	}
}
int dx=1;
multiset<card>user_cards[MAX_PLAYER+10];
int y=0;
void send_card(int x){
	for(int id=0;id<6;id++){

		for(int i=1;i<=x;i++){
			user_cards[i].insert(s.front());s.pop_front();
		}
	}
}
bool is_fit(card a,card b,int cho_col){
	if(b.typ==W)return 1;
	if(a.typ==W&&cho_col==b.typ)return 1;
	if(a.typ!=W&&(a.typ==b.typ||a.id==b.id))return 1;
	return 0;
}
int main(){
	w.seed(time(0));
	int peo;
	cin>>peo;
	if(peo<=2){
		cout<<"There should be at least 3 people";
		return 0;
	}
	init_card();
	send_card(peo); /*
	for(auto x:user_cards[1]){
		x.pr();
		cout<<' ';
	}*/
	cout<<user_cards[1].size()<<endl;;
	int na=w()%peo+1;
	int d=1;
	bool isskiped=0;
	int plcard=0;
	while(s.back().typ==W){
		s.push_back(s.front());s.pop_front();
	}
	int cho_col=0;
	while(1){
		for(int i=1;i<=peo;i++){
			cout<<"Player "<<i<<" has ";
			for(int h=0;h<user_cards[i].size();h++)cout<<"D";
			cout<<" cards\n";
		}
		cout<<"Now is the Player "<<na<<"\n";;
		cout<<"The placed card is ";
		s.back().pr();
		if(s.back().typ==W){
			cout<<"Chosen colour is ";
			switch(cho_col){

				case R:
					wcout<<ConsoleBackgroundColor::Red;
					break;
				case B:
					wcout<<ConsoleBackgroundColor::Blue;

					break;
				case Y:
					wcout<<ConsoleBackgroundColor::Yellow;

					break;
				case G:
					wcout<<ConsoleBackgroundColor::Green;

					break;
			}
			cout<<' ';
			wcout<<ConsoleBackgroundColor::Black;
			wcout<<ConsoleColor::White;
		} cout<<'\n';
		if(isskiped){
			cout<<"Skiped"<<endl;
			isskiped=0;
		} else if(plcard){
			cout<<"Now Get "<<plcard<<" cards\n";
			cout<<"Now your card is:";
			for(auto x:user_cards[na]){
				x.pr();
				cout<<' ';
			}
			int k;
			bool h=0;
			do{

				auto p=user_cards[na].begin();
				do{
					cin>>k;
					if(k==0){
						goto l2;
					}
				}while(k<=0||k>user_cards[na].size());

				k--;
				while(k--){
					p++;
				}
				if(is_fit(s.back(),*p,cho_col)&&((*p).da=="+2"||(*p).da=="+4")){
					s.push_back(*p);
					if((*p).da=="+2"){
						plcard+=2;
					}
					if((*p).da=="+4"){
						plcard+=4;
						cout<<"Sel a colour:1 is Red,2 is Yellow,3 is Blue,4 is Green:";
						do {
							cin>>cho_col;
						}while(cho_col<=0||cho_col>=5);
					}
					user_cards[na].erase(p);
					goto l3;

				}
			}while(1);
			l2:;
			cout<<endl;
			cout<<"Get ";
			for(int i=0;i<plcard;i++){
				s.front().pr();
				cout<<' ';
				user_cards[na].insert(s.front());s.pop_front();
			}
			cout<<endl;
			plcard=0;
			l3:;
			//cout<<plcard<<endl;
		}else{
			//if(na==1){

				cout<<"Now your card is:";
				for(auto x:user_cards[na]){
					x.pr();
					cout<<' ';
				}
				cout<<endl;
				cout<<"Select a number to chose it:(0 to get a new card)";
				int k;
				bool h=0;
				do{

					auto p=user_cards[na].begin();
					do{
						cin>>k;
						if(k==0){
							if(h)goto l;
							h=1;
							cout<<"Get ";
							s.front().pr();
							cout<<endl;
							user_cards[na].insert(s.front());s.pop_front();
							cout<<"Now your card is:";
							for(auto x:user_cards[na]){
								x.pr();
								cout<<' ';
							}
						}
					}while(k<=0||k>user_cards[na].size());

					k--;
					while(k--){
						p++;
					}
					if(is_fit(s.back(),*p,cho_col)){
						s.push_back(*p);
						if((*p).da=="skip"){
							isskiped=1;
						}
						if((*p).da=="reverse"){
							d=-d;
						}
						if((*p).da=="+2"){
							plcard=2;
						}
						if((*p).da=="+4"){
							plcard=4;
						}
						if((*p).da=="all"){
							card f=*p;
							vector<card>nemo;
							for(auto x:user_cards[na]){
								if(x.typ=f.typ)nemo.push_back(x);
							}
							for(auto x:nemo){
								user_cards[na].erase(x);
							}
							break;
						}
						if((*p).typ==W){
							cout<<"Sel a colour:1 is Red,2 is Yellow,3 is Blue,4 is Green:";
							do {
								cin>>cho_col;
							}while(cho_col<=0||cho_col>=5);
						}
						user_cards[na].erase(p);
						break;
					}
				}while(1);
				l:;
		//	}
		}
		if(user_cards[na].size()==0){
			cout<<"Player "<<na<<" Wins";
			na=(na+d-1+peo)%peo+1;
			while(plcard--){
				user_cards[na].insert(s.front());s.pop_front();
			}
			for(int i=1;i<=peo;i++){
				cout<<"Player "<<i<<" is " ;
				int l=0;
				for(auto x:user_cards[i]){
					l+=x.sco;
				}
				cout<<l<<": ";
				for(auto x:user_cards[i]){
					x.pr();
					cout<<' ';
				}
				cout<<endl;

			}
			system("pause");
			return 0;
		}
		//if(na==1){
			cout<<"Now your card is:";
			for(auto x:user_cards[na]){
				x.pr();
				cout<<' ';
			}
			cout<<endl;
		//}
		na=(na+d-1+peo)%peo+1;
		system("pause");
		system("cls");
	}
	return 0;
}
}
signed main(){
	   return _wrk::main();
}