不似斗地主,但神似斗地主,我的3月“胶带”在这啦
上源码
#include<iostream>
#include<ctime>
#include<cstdlib>
#include<windows.h>
using namespace std;
int c[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,1,2,3,4,5,6,7,8,9,10,11,12,13,1,2,3,4,5,6,7,8,9,10,11,12,13,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}; //一副完整的牌
int player1[18];
int player2[18];
int player3[18]; //将牌分为三份
//游戏规则
void Instructions(){
char s;
cout<<"欢迎来到卡牌接龙游戏!"<<endl;
cout<<"是否查看游戏规则?是(y)否(任意字符):";
cin>>s;
if(s == 'y'){
cout<<endl;
cout<<"一副牌总共有54张,洗牌后分为3叠,玩家随机得到一叠以开始。"<<endl;
cout<<"每次只能出一张牌,牌的点数必须比上家的牌的点数大,无牌出则输入 0 以PASS!率先清空牌库的玩家获胜!"<<endl;
cout<<endl;
}
else
cout<<endl;
}
//洗牌函数,打乱牌的顺序
void Shuffle(int *c){
cout<<"洗牌中。。。"<<endl;
srand(unsigned(time(NULL)));
Sleep(1000);
int a = rand();
while(a>0){
for(int i = 53; i > 0; i--){
srand(unsigned(time(NULL)));
int currentRandom = rand() % i;
swap(c[i],c[currentRandom]);
}
a--;
}
//发牌, 分为三份
for(int i = 0;i < 18;i++){
player1[i] = c[i];
}
for(int i = 18;i < 36;i++){
player2[i-18] = c[i];
}
for(int i = 36;i < 54;i++){
player3[i-36] = c[i];
}
}
//二分搜索算法,为了找到要出的牌在牌库中的位置
int Binary_Search(int *a, int start, int end, int key){
int mid;
while(start <= end){
mid = (start + end) / 2;
if(a[mid] < key){
start = mid + 1;
}
else if (a[mid] > key){
end = mid - 1;