[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);
}
posted @   HaneDaniko  阅读(8)  评论(0编辑  收藏  举报
编辑推荐:
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
阅读排行:
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· 使用C#创建一个MCP客户端
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· Windows编程----内核对象竟然如此简单?
点击右上角即可分享
微信分享提示