c++游戏

大家好,我是@黑客小羊,今天给大家分享几个游戏

1.猜数游戏

#include<bits/stdc++.h>
using namespace std;
int main(){
    system("color b4");
    cout<<" 猜数\n";
    cout<<"请猜:";
    int z;
    float a;
    float b;
    srand(time(0));
    a=rand()%100+1;
    cin>>b;
    for(z=0;b!=a;z++)
       if(b==a)
         cout<<"猜对了";
       else if(b<a)
       {
            cout<<" 猜小了\n"<<"再猜:";
            cin>>b;
       }
       else if(b>a)
       {
            cout<<"猜大了\n"<<"再猜:";
            cin>>b;
       }
    cout<<"猜对了\n";
    cout<<"共猜了"<<z+1<<"次";
    return 0;
}
#include <iostream>
#include <windows.h>
#include <stdlib.h>
#include <time.h>
using namespace std;

int c1, c2 = 0;
string l[10] = {"", "简单", "普通", "中等", "困难", "地狱", "魔鬼"};

void choose1() {
	cout << "请选择难度:\n";
	cout << "1.简单\n";
	cout << "2.普通\n";
	cout << "3.中等\n";
	cout << "4.困难\n";
	cout << "5.地狱\n";
	cout << "6.魔鬼\n";
	cout << "请输入你需要的难度:(以回车结束)\n";
}

int number_max(int n) {
	switch(n) {
		case 1:return 30;
		case 2:return 50;
		case 3:return 100;
		case 4:return 500;
		case 5:return 1000;
		case 6:return 5000;
	}
}

void choose2() {
	cout << "您选择的是" << l[c1] << "难度\n";
	cout << "电脑会从1-" << number_max(c1) << "中随机生成一个数字\n";
	cout << "你需要猜出那个数\n";
	cout << "5秒钟后开始游戏";
	Sleep(5000);
	system("cls");
}

int generate(int n) {
	srand(time(0));
	return rand()%n+1;
}

int main() {
	cout<<"正在进入游戏……";
	Sleep(5000);
	system("cls");
	cout << "-------------------------------------------------------------------------你好,欢迎来到猜数游戏-------------------------------------------------------------------------\n\n\n";
	choose1();
	cin >> c1;
	if (c1 < 1 || c1 > 6) {
		while(c1 < 1 || c1 > 6) {
			cout << "输入错误,请重新输入1-6之间的数\n";
			cin >> c1;
		}
	}
	system("cls");
	choose2();
	int begin = 1, end = number_max(c1);
	int answer = generate(end);
	int count = 0;
	while (c2 != answer) {
		cout << "请输入一个整数(1-" << end << "):\n";
		cin >> c2;
		while (c2 < 0 || c2 > end) {
			cout << "你确定你输入的是一个1-" << end << "之间的整数?\n";
			cout << "请输入一个整数(1-" << end << "):\n";
			cin >> c2;
		}
		count ++;
		if (c2 == answer) {
			break;
		}
		if (c2 < answer) {
			cout << "猜小了\n";
		}
		if (c2 > answer) {
			cout << "猜大了\n";
		}
		Sleep(2000);
		system("cls");
	}
	cout << "恭喜您猜中了!\n";
	cout << "您一共用了" << count << "次";
	return 0;
}

2.狼人杀

#include<bits/stdc++.h>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<windows.h>
using namespace std;
struct IDname
{//undefined
    int geshu;
    string NAME;
};
IDname jue_se[101];
struct ID
{//undefined
    int num;
    bool life;
    string name;
    int know;
    int how;
};
ID player[101];
int n, MY, kill1, kill2;
char a;
bool jieyao = 1, duyao = 1;
bool yesuming = 1;
int lieren, shouwei = 0;
void init1()
{//undefined
    jue_se[1].NAME = "村民   ";
    jue_se[2].NAME = "狼人   ";
    jue_se[3].NAME = "女巫   ";
    jue_se[4].NAME = "预言家 ";
    jue_se[5].NAME = "猎人   ";
    jue_se[6].NAME = "守卫   ";
    jue_se[7].NAME = "白熊   ";
    jue_se[8].NAME = "白痴   ";
    jue_se[9].NAME = "耶稣   ";
    jue_se[10].NAME = "预言家 ";
    jue_se[11].NAME = "猎人 ";
    jue_se[12].NAME = "守卫 ";
}
void init2(int nn)
{//undefined
    switch (nn)
    {//undefined
    case 3:
        jue_se[1].geshu = 1;
        jue_se[2].geshu = 1;
        jue_se[3].geshu = 1;
        jue_se[4].geshu = 0;
        jue_se[5].geshu = 0;
        jue_se[6].geshu = 0;
        jue_se[7].geshu = 0;
        jue_se[8].geshu = 0;
        jue_se[9].geshu = 0;
        jue_se[10].geshu = 0;
        jue_se[11].geshu = 0;
        jue_se[12].geshu = 0;
        break;
    case 4:
        jue_se[1].geshu = 2;
        jue_se[2].geshu = 1;
        jue_se[3].geshu = 1;
        jue_se[4].geshu = 0;
        jue_se[5].geshu = 0;
        jue_se[6].geshu = 0;
        jue_se[7].geshu = 0;
        jue_se[8].geshu = 0;
        jue_se[9].geshu = 0;
        jue_se[10].geshu = 0;
        jue_se[11].geshu = 0;
        jue_se[12].geshu = 0;
        break;
    case 5:
        jue_se[1].geshu = 3;
        jue_se[2].geshu = 1;
        jue_se[3].geshu = 1;
        jue_se[4].geshu = 0;
        jue_se[5].geshu = 0;
        jue_se[6].geshu = 0;
        jue_se[7].geshu = 0;
        jue_se[8].geshu = 0;
        jue_se[9].geshu = 0;
        jue_se[10].geshu = 0;
        jue_se[11].geshu = 0;
        jue_se[12].geshu = 0;
        break;
    case 6:
        jue_se[1].geshu = 3;
        jue_se[2].geshu = 2;
        jue_se[3].geshu = 1;
        jue_se[4].geshu = 0;
        jue_se[5].geshu = 0;
        jue_se[6].geshu = 0;
        jue_se[7].geshu = 0;
        jue_se[8].geshu = 0;
        jue_se[9].geshu = 0;
        jue_se[10].geshu = 0;
        jue_se[11].geshu = 0;
        jue_se[12].geshu = 0;
        break;
    case 7:
        jue_se[1].geshu = 3;
        jue_se[2].geshu = 2;
        jue_se[3].geshu = 1;
        jue_se[4].geshu = 1;
        jue_se[5].geshu = 0;
        jue_se[6].geshu = 0;
        jue_se[7].geshu = 0;
        jue_se[8].geshu = 0;
        jue_se[9].geshu = 0;
        jue_se[10].geshu = 0;
        jue_se[11].geshu = 0;
        jue_se[12].geshu = 0;
        break;
    case 8:
        jue_se[1].geshu = 3;
        jue_se[2].geshu = 3;
        jue_se[3].geshu = 1;
        jue_se[4].geshu = 1;
        jue_se[5].geshu = 0;
        jue_se[6].geshu = 0;
        jue_se[7].geshu = 0;
        jue_se[8].geshu = 0;
        jue_se[9].geshu = 0;
        jue_se[10].geshu = 0;
        jue_se[11].geshu = 0;
        jue_se[12].geshu = 0;
        break;
    case 9:
        jue_se[1].geshu = 3;
        jue_se[2].geshu = 3;
        jue_se[3].geshu = 1;
        jue_se[4].geshu = 1;
        jue_se[5].geshu = 1;
        jue_se[6].geshu = 0;
        jue_se[7].geshu = 0;
        jue_se[8].geshu = 0;
        jue_se[9].geshu = 0;
        jue_se[10].geshu = 0;
        jue_se[11].geshu = 0;
        jue_se[12].geshu = 0;
        break;
    case 10:
        jue_se[1].geshu = 4;
        jue_se[2].geshu = 3;
        jue_se[3].geshu = 1;
        jue_se[4].geshu = 1;
        jue_se[5].geshu = 1;
        jue_se[6].geshu = 0;
        jue_se[7].geshu = 0;
        jue_se[8].geshu = 0;
        jue_se[9].geshu = 0;
        jue_se[10].geshu = 0;
        jue_se[11].geshu = 0;
        jue_se[12].geshu = 0;
        break;
    case 11:
        jue_se[1].geshu = 4;
        jue_se[2].geshu = 4;
        jue_se[3].geshu = 1;
        jue_se[4].geshu = 1;
        jue_se[5].geshu = 1;
        jue_se[6].geshu = 0;
        jue_se[7].geshu = 0;
        jue_se[8].geshu = 0;
        jue_se[9].geshu = 0;
        jue_se[10].geshu = 0;
        jue_se[11].geshu = 0;
        jue_se[12].geshu = 0;
        break;
    case 12:
        jue_se[1].geshu = 4;
        jue_se[2].geshu = 4;
        jue_se[3].geshu = 1;
        jue_se[4].geshu = 1;
        jue_se[5].geshu = 1;
        jue_se[6].geshu = 1;
        jue_se[7].geshu = 0;
        jue_se[8].geshu = 0;
        jue_se[9].geshu = 0;
        jue_se[10].geshu = 0;
        jue_se[11].geshu = 0;
        jue_se[12].geshu = 0;
        break;
    case 13:
        jue_se[1].geshu = 4;
        jue_se[2].geshu = 4;
        jue_se[3].geshu = 1;
        jue_se[4].geshu = 1;
        jue_se[5].geshu = 1;
        jue_se[6].geshu = 1;
        jue_se[7].geshu = 1;
        jue_se[8].geshu = 0;
        jue_se[9].geshu = 0;
        jue_se[10].geshu = 0;
        jue_se[11].geshu = 0;
        jue_se[12].geshu = 0;
        break;
    case 14:
        jue_se[1].geshu = 4;
        jue_se[2].geshu = 4;
        jue_se[3].geshu = 1;
        jue_se[4].geshu = 1;
        jue_se[5].geshu = 2;
        jue_se[6].geshu = 1;
        jue_se[7].geshu = 1;
        jue_se[8].geshu = 0;
        jue_se[9].geshu = 0;
        jue_se[10].geshu = 0;
        jue_se[11].geshu = 0;
        jue_se[12].geshu = 0;
        break;
    case 15:
        jue_se[1].geshu = 4;
        jue_se[2].geshu = 4;
        jue_se[3].geshu = 1;
        jue_se[4].geshu = 2;
        jue_se[5].geshu = 2;
        jue_se[6].geshu = 1;
        jue_se[7].geshu = 1;
        jue_se[8].geshu = 0;
        jue_se[9].geshu = 0;
        jue_se[10].geshu = 0;
        jue_se[11].geshu = 0;
        jue_se[12].geshu = 0;
        break;
    case 16:
        jue_se[1].geshu = 4;
        jue_se[2].geshu = 4;
        jue_se[3].geshu = 1;
        jue_se[4].geshu = 2;
        jue_se[5].geshu = 2;
        jue_se[6].geshu = 2;
        jue_se[7].geshu = 1;
        jue_se[8].geshu = 0;
        jue_se[9].geshu = 0;
        jue_se[10].geshu = 0;
        jue_se[11].geshu = 0;
        jue_se[12].geshu = 0;
        break;
    case 17:
        jue_se[1].geshu = 4;
        jue_se[2].geshu = 4;
        jue_se[3].geshu = 1;
        jue_se[4].geshu = 3;
        jue_se[5].geshu = 2;
        jue_se[6].geshu = 2;
        jue_se[7].geshu = 1;
        jue_se[8].geshu = 0;
        jue_se[9].geshu = 0;
        jue_se[10].geshu = 0;
        jue_se[11].geshu = 0;
        jue_se[12].geshu = 0;
        break;
    case 18:
        jue_se[1].geshu = 5;
        jue_se[2].geshu = 4;
        jue_se[3].geshu = 1;
        jue_se[4].geshu = 3;
        jue_se[5].geshu = 2;
        jue_se[6].geshu = 2;
        jue_se[7].geshu = 1;
        jue_se[8].geshu = 0;
        jue_se[9].geshu = 0;
        jue_se[10].geshu = 0;
        jue_se[11].geshu = 0;
        jue_se[12].geshu = 0;
        break;
    case 19:
        jue_se[1].geshu = 5;
        jue_se[2].geshu = 4;
        jue_se[3].geshu = 1;
        jue_se[4].geshu = 4;
        jue_se[5].geshu = 2;
        jue_se[6].geshu = 2;
        jue_se[7].geshu = 1;
        jue_se[8].geshu = 0;
        jue_se[9].geshu = 0;
        jue_se[10].geshu = 0;
        jue_se[11].geshu = 0;
        jue_se[12].geshu = 0;
        break;
    case 20:
        jue_se[1].geshu = 5;
        jue_se[2].geshu = 4;
        jue_se[3].geshu = 1;
        jue_se[4].geshu = 4;
        jue_se[5].geshu = 3;
        jue_se[6].geshu = 2;
        jue_se[7].geshu = 1;
        jue_se[8].geshu = 0;
        jue_se[9].geshu = 0;
        jue_se[10].geshu = 0;
        jue_se[11].geshu = 0;
        jue_se[12].geshu = 0;
        break;
    case 21:
        jue_se[1].geshu = 5;
        jue_se[2].geshu = 5;
        jue_se[3].geshu = 1;
        jue_se[4].geshu = 4;
        jue_se[5].geshu = 3;
        jue_se[6].geshu = 2;
        jue_se[7].geshu = 1;
        jue_se[8].geshu = 0;
        jue_se[9].geshu = 0;
        jue_se[10].geshu = 0;
        jue_se[11].geshu = 0;
        jue_se[12].geshu = 0;
        break;
    case 22:
        jue_se[1].geshu = 5;
        jue_se[2].geshu = 5;
        jue_se[3].geshu = 1;
        jue_se[4].geshu = 4;
        jue_se[5].geshu = 3;
        jue_se[6].geshu = 2;
        jue_se[7].geshu = 1;
        jue_se[8].geshu = 1;
        jue_se[9].geshu = 0;
        jue_se[10].geshu = 0;
        jue_se[11].geshu = 0;
        jue_se[12].geshu = 0;
        break;
    case 23:
        jue_se[1].geshu = 5;
        jue_se[2].geshu = 5;
        jue_se[3].geshu = 1;
        jue_se[4].geshu = 4;
        jue_se[5].geshu = 3;
        jue_se[6].geshu = 3;
        jue_se[7].geshu = 1;
        jue_se[8].geshu = 1;
        jue_se[9].geshu = 0;
        jue_se[10].geshu = 0;
        jue_se[11].geshu = 0;
        jue_se[12].geshu = 0;
        break;
    case 24:
        jue_se[1].geshu = 5;
        jue_se[2].geshu = 5;
        jue_se[3].geshu = 2;
        jue_se[4].geshu = 4;
        jue_se[5].geshu = 3;
        jue_se[6].geshu = 3;
        jue_se[7].geshu = 1;
        jue_se[8].geshu = 1;
        jue_se[9].geshu = 0;
        jue_se[10].geshu = 0;
        jue_se[11].geshu = 0;
        jue_se[12].geshu = 0;
        break;
    case 25:
        jue_se[1].geshu = 5;
        jue_se[2].geshu = 5;
        jue_se[3].geshu = 2;
        jue_se[4].geshu = 4;
        jue_se[5].geshu = 4;
        jue_se[6].geshu = 3;
        jue_se[7].geshu = 1;
        jue_se[8].geshu = 1;
        jue_se[9].geshu = 0;
        jue_se[10].geshu = 0;
        jue_se[11].geshu = 0;
        jue_se[12].geshu = 0;
        break;
    case 26:
        jue_se[1].geshu = 5;
        jue_se[2].geshu = 6;
        jue_se[3].geshu = 2;
        jue_se[4].geshu = 4;
        jue_se[5].geshu = 4;
        jue_se[6].geshu = 3;
        jue_se[7].geshu = 1;
        jue_se[8].geshu = 1;
        jue_se[9].geshu = 0;
        jue_se[10].geshu = 0;
        jue_se[11].geshu = 0;
        jue_se[12].geshu = 0;
        break;
    case 27:
        jue_se[1].geshu = 5;
        jue_se[2].geshu = 6;
        jue_se[3].geshu = 2;
        jue_se[4].geshu = 4;
        jue_se[5].geshu = 4;
        jue_se[6].geshu = 4;
        jue_se[7].geshu = 1;
        jue_se[8].geshu = 1;
        jue_se[9].geshu = 0;
        jue_se[10].geshu = 0;
        jue_se[11].geshu = 0;
        jue_se[12].geshu = 0;
        break;
    case 28:
        jue_se[1].geshu = 5;
        jue_se[2].geshu = 6;
        jue_se[3].geshu = 2;
        jue_se[4].geshu = 4;
        jue_se[5].geshu = 4;
        jue_se[6].geshu = 4;
        jue_se[7].geshu = 2;
        jue_se[8].geshu = 1;
        jue_se[9].geshu = 0;
        jue_se[10].geshu = 0;
        jue_se[11].geshu = 0;
        jue_se[12].geshu = 0;
        break;
    case 29:
        jue_se[1].geshu = 5;
        jue_se[2].geshu = 6;
        jue_se[3].geshu = 2;
        jue_se[4].geshu = 4;
        jue_se[5].geshu = 4;
        jue_se[6].geshu = 4;
        jue_se[7].geshu = 2;
        jue_se[8].geshu = 1;
        jue_se[9].geshu = 1;
        jue_se[10].geshu = 0;
        jue_se[11].geshu = 0;
        jue_se[12].geshu = 0;
        break;
    case 30:
        jue_se[1].geshu = 6;
        jue_se[2].geshu = 6;
        jue_se[3].geshu = 2;
        jue_se[4].geshu = 4;
        jue_se[5].geshu = 4;
        jue_se[6].geshu = 4;
        jue_se[7].geshu = 2;
        jue_se[8].geshu = 1;
        jue_se[9].geshu = 1;
        jue_se[10].geshu = 0;
        jue_se[11].geshu = 0;
        jue_se[12].geshu = 0;
        break;
    case 31:
        jue_se[1].geshu = 6;
        jue_se[2].geshu = 6;
        jue_se[3].geshu = 3;
        jue_se[4].geshu = 4;
        jue_se[5].geshu = 4;
        jue_se[6].geshu = 4;
        jue_se[7].geshu = 2;
        jue_se[8].geshu = 1;
        jue_se[9].geshu = 1;
        jue_se[10].geshu = 0;
        jue_se[11].geshu = 0;
        jue_se[12].geshu = 0;
        break;
    case 32:
        jue_se[1].geshu = 6;
        jue_se[2].geshu = 6;
        jue_se[3].geshu = 4;
        jue_se[4].geshu = 4;
        jue_se[5].geshu = 4;
        jue_se[6].geshu = 4;
        jue_se[7].geshu = 2;
        jue_se[8].geshu = 1;
        jue_se[9].geshu = 1;
        jue_se[10].geshu = 0;
        jue_se[11].geshu = 0;
        jue_se[12].geshu = 0;
        break;
    default:
        cout << "输入错误,再见" << endl;
        exit(0);
        break;
    }
}
int van[10] = { 7,4,6,43,35,1,2,8,20,19 };
void init3(int nn)
{//undefined
    srand(time(0));
    Sleep(rand() % 44);
    int x = 10000;
    int t = rand();
    srand(time(NULL));
    int y = van[(rand() % 100 * van[rand() % 10] + t) % 10];
    if (nn <= 6)
        x = abs(x * 6 / y) % 3 + 1;
    else if (nn <= 8)
        x = abs(x * 7 / y) % 4 + 1;
    else if (nn <= 11)
        x = abs(x * 8 / y) % 5 + 1;
    else if (nn <= 14)
        x = abs(x * 9 / y) % 6 + 1;
    else if (nn <= 17)
        x = abs(x * 10 / y) % 7 + 1;
    else if (nn <= 20)
        x = abs(x * 11 / y) % 8 + 1;
    else if (nn <= 23)
        x = abs(x * 12 / y) % 9 + 1;
    else if (nn <= 26)
        x = abs(x * 13 / y) % 10 + 1;
    else if (nn <= 29)
        x = abs(x * 14 / y) % 11 + 1;
    else if (nn <= 32)
        x = abs(x * 15 / y) % 12 + 1;
    do
    {//undefined
        if (nn <= 6)
            x = x % 3 + 1;
        else if (nn <= 8)
            x = x % 4 + 1;
        else if (nn <= 11)
            x = x % 5 + 1;
        else if (nn <= 14)
            x = x % 6 + 1;
        else if (nn <= 17)
            x = x % 7 + 1;
        else if (nn <= 20)
            x = x % 8 + 1;
        else if (nn <= 23)
            x = x % 9 + 1;
        else if (nn <= 26)
            x = x % 10 + 1;
        else if (nn <= 29)
            x = x % 11 + 1;
        else if (nn <= 32)
            x = x % 12 + 1;
        if (jue_se[x].geshu > 0)
        {//undefined
            player[nn].name = jue_se[x].NAME;
            if (player[nn].name == "猎人   ")
                lieren = nn;
            if (player[nn].name == "守卫   ")
                shouwei = nn;
            player[nn].life = 1;
            player[nn].num = nn;
            player[nn].know = 0;
            jue_se[x].geshu--;
            player[nn].how = 0;
            break;
        }
    } while (jue_se[x].geshu == 0);
}
void printhhh()
{//undefined
    int cm = 0;
    int sz = 0;
    for (int i = 1; i <= n; i++)
    {//undefined
        if (player[i].life == 0)
            continue;
        else if (player[i].name == "村民   " || player[i].name == "白痴   ")
            cm++;
        else if (player[i].name == "女巫   " || player[i].name == "预言家 " || player[i].name == "猎人   " || player[i].name == "守卫   " || player[i].name == "白熊   " || player[i].name == "耶稣   ")
            sz++;
    }
    if (sz == 0 || cm == 0)
        cout << "狼人阵营胜利" << endl;
    else
        cout << "好人阵营胜利" << endl;
    for (int i = 1; i <= n; i++)
    {//undefined
        cout << left << setw(3) << player[i].num << ": " << player[i].name << " ";
        if (player[i].life == 0)
            cout << "死亡" << "\t";
        else
            cout << "存活" << "\t";
        if (player[i].how == 0)
            cout << "最终存活 " << endl;
        else if (player[i].how == 1)
            cout << "最终被狼人杀死" << endl;
        else if (player[i].how == 2)
            cout << "最终被投票投死" << endl;
        else if (player[i].how == 3)
            cout << "最终被女巫毒死" << endl;
        else if (player[i].how == 4)
            cout << "最终被猎人射杀" << endl;
    }
    system("pause");
    system("pause");
    system("pause");
}
void print(int day, int ti)
{//undefined
    HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
    if (ti == 0)
        SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_INTENSITY);
    else
        SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
    cout << "\t\t\t\t第" << day << "天 ";
    if (ti == 0)
        cout << "白天" << endl;
    else
        cout << "夜晚" << endl;
	cout << "我的位置:" << MY << "号" << endl;
	if (n <= 8){
	    for (int i = 1; i <= n; i++)
	    {//undefined
	        cout << player[i].num << "号位   ";
	    }
	    cout << endl;
	    for (int i = 1; i <= n; i++)
	    {//undefined
	        if (player[i].life == 1)
	        {//undefined
	            if (ti == 0)
	                SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_INTENSITY | FOREGROUND_GREEN);
	            else
	                SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_GREEN);
	            cout << "存活    ";
	        }
	        else
	        {//undefined
	            if (ti == 0)
	                SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_INTENSITY | FOREGROUND_RED);
	            else
	                SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED);
	            cout << "已死亡  ";
	        }
	    }
	    if (ti == 0)
	        SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_INTENSITY);
	    else
	        SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
	    cout << endl;
	    for (int i = 1; i <= n; i++)
	    {//undefined
	        cout << player[i].name << " ";
	    }
	    cout << endl << endl;
	}
    else if (n >= 9){
	    for (int i = 1; i <= 8; i++)
	    {//undefined
	        cout << player[i].num << "号位   ";
	    }
	    cout << endl;
	    for (int i = 1; i <= 8; i++)
	    {//undefined
	        if (player[i].life == 1)
	        {//undefined
	            if (ti == 0)
	                SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_INTENSITY | FOREGROUND_GREEN);
	            else
	                SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_GREEN);
	            cout << "存活    ";
	        }
	        else
	        {//undefined
	            if (ti == 0)
	                SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_INTENSITY | FOREGROUND_RED);
	            else
	                SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED);
	            cout << "已死亡  ";
	        }
	    }
	    if (ti == 0)
	        SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_INTENSITY);
	    else
	        SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
	    cout << endl;
	    for (int i = 1; i <= 8; i++)
	    {//undefined
	        cout << player[i].name << " ";
	    }
	    cout << endl << endl;
    	if (n <= 16){
    		   for (int i = 9; i <= n; i++)
		    {//undefined
		        if (i < 10)
		            cout << player[i].num << "号位   ";
		        else
		            cout << player[i].num << "号位  ";
		    }
		    cout << endl;
		    for (int i = 9; i <= n; i++)
		    {//undefined
		        if (player[i].life == 1)
		        {//undefined
		            if (ti == 0)
		                SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_INTENSITY | FOREGROUND_GREEN);
		            else
		                SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_GREEN);
		            cout << "存活    ";
		        }
		        else
		        {//undefined
		            if (ti == 0)
		                SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_INTENSITY | FOREGROUND_RED);
		            else
		                SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED);
		            cout << "已死亡   ";
		        }
		    }
		    if (ti == 0)
		        SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_INTENSITY);
		    else
		        SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
		    cout << endl;
		    for (int i = 9; i <= n; i++)
	    	{//undefined
	    	    cout << player[i].name << " ";
	    	}
		    cout << endl << endl;
		}
		else if (n >= 17){
    		   for (int i = 9; i <= 16; i++)
		    {//undefined
		        if (i < 10)
		            cout << player[i].num << "号位   ";
		        else
		            cout << player[i].num << "号位  ";
		    }
		    cout << endl;
		    for (int i = 9; i <= 16; i++)
		    {//undefined
		        if (player[i].life == 1)
		        {//undefined
		            if (ti == 0)
		                SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_INTENSITY | FOREGROUND_GREEN);
		            else
		                SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_GREEN);
		            cout << "存活    ";
		        }
		        else
		        {//undefined
		            if (ti == 0)
		                SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_INTENSITY | FOREGROUND_RED);
		            else
		                SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED);
		            cout << "已死亡  ";
		        }
		    }
		    if (ti == 0)
		        SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_INTENSITY);
		    else
		        SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
		    cout << endl;
		    for (int i = 9; i <= 16; i++)
	    	{//undefined
	    	    cout << player[i].name << " ";
	    	}
		    cout << endl << endl;
		    if (n <= 24){
				   for (int i = 17; i <= n; i++)
			    {//undefined
			        if (i < 10)
			            cout << player[i].num << "号位  ";
			        else
			            cout << player[i].num << "号位  ";
			    }
			    cout << endl;
			    for (int i = 17; i <= n; i++)
			    {//undefined
			        if (player[i].life == 1)
			        {//undefined
			            if (ti == 0)
			                SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_INTENSITY | FOREGROUND_GREEN);
			            else
			                SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_GREEN);
			            cout << "存活    ";
			        }
			        else
			        {//undefined
			            if (ti == 0)
			                SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_INTENSITY | FOREGROUND_RED);
			            else
			                SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED);
			            cout << "已死亡  ";
			        }
			    }
			    if (ti == 0)
			        SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_INTENSITY);
			    else
			        SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
			    cout << endl;
			    for (int i = 17; i <= n; i++)
	    		{//undefined
					cout << player[i].name << " ";
	    		}
				cout << endl << endl;
			}
			else if (n >= 25){
				   for (int i = 17; i <= 24; i++)
			    {//undefined
			        if (i < 10)
			            cout << player[i].num << "号位  ";
			        else
			            cout << player[i].num << "号位  ";
			    }
			    cout << endl;
			    for (int i = 17; i <= 24; i++)
			    {//undefined
			        if (player[i].life == 1)
			        {//undefined
			            if (ti == 0)
			                SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_INTENSITY | FOREGROUND_GREEN);
			            else
			                SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_GREEN);
			            cout << "存活    ";
			        }
			        else
			        {//undefined
			            if (ti == 0)
			                SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_INTENSITY | FOREGROUND_RED);
			            else
			                SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED);
			            cout << "已死亡  ";
			        }
			    }
			    if (ti == 0)
			        SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_INTENSITY);
			    else
			        SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
			    cout << endl;
			    for (int i = 17; i <= 24; i++)
	    		{//undefined
					cout << player[i].name << " ";
	    		}
				cout << endl << endl;
				   for (int i = 25; i <= n; i++)
			    {//undefined
			        if (i < 10)
			            cout << player[i].num << "号位  ";
			        else
			            cout << player[i].num << "号位  ";
			    }
			    cout << endl;
			    for (int i = 25; i <= n; i++)
			    {//undefined
			        if (player[i].life == 1)
			        {//undefined
			            if (ti == 0)
			                SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_INTENSITY | FOREGROUND_GREEN);
			            else
			                SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_GREEN);
			            cout << "存活    ";
			        }
			        else
			        {//undefined
			            if (ti == 0)
			                SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_INTENSITY | FOREGROUND_RED);
			            else
			                SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED);
			            cout << "已死亡  ";
			        }
			    }
			    if (ti == 0)
			        SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_INTENSITY);
			    else
			        SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
			    cout << endl;
			    for (int i = 25; i <= n; i++)
	    		{//undefined
					cout << player[i].name << " ";
	    		}
				cout << endl << endl;
			}
		}
	}
}
int shou = 0;
void shoushui(int hhh, int hhhh)
{//undefined
    int x;
    Sleep(0);//3000
    system("cls");
    print(hhh, hhhh);
    cout << "守~卫~请~睁~眼~~~" << endl;
    Sleep(0);//3000
    system("cls");
    print(hhh, hhhh);
    if (MY == shouwei && player[MY].life == 1)
    {//undefined
        cout << "请问你要守护谁?" << endl << "输入:";
        cin >> x;
        while (x == shou || x<1 || x>n || player[x].life == 0)
        {//undefined
            cout << "输入错误,请重新输入" << endl << "输入:";
            cin >> x;
        }
        shou = x;
    }
    else if (player[shouwei].life == 1)
    {//undefined
        cout << "请问你要守护谁?" << endl;
        Sleep(rand() % 98);
        srand(time(0));
        x = rand() % n + 1;
        while (x == shou || player[x].life == 0)
        {//undefined
            Sleep(rand() % 98);
            srand(time(0));
            x = rand() % n + 1;
        }
        shou = x;
    }
    else
    {//undefined
        cout << "请问你要守护谁?" << endl;
        Sleep(0);//3000
        shou = -1;
    }
    Sleep(0);//3000
    system("cls");
    print(hhh, hhhh);
    cout << "守~卫~请~闭~眼~~~" << endl;
}
struct tou
{//undefined
    int xxx;
    int num;
    int toupiaoquan;
};
tou TOU[13];
bool cmp(tou x, tou y)
{//undefined
    if (x.xxx == y.xxx)
        return x.num < y.num;
    return x.xxx > y.xxx;
}
bool cmp1(tou x, tou y)
{//undefined
    return x.num < y.num;
}
void toupiao(int ddd, int nnn)
{//undefined
    //--------1--------
    int x;
    Sleep(2000);
    system("cls");
    print(ddd, nnn);
    cout << "现在大家请投票";
    for (int i = 1; i <= 3; i++)
    {//undefined
        cout << ".";
        Sleep(500);
    }
    cout << endl;
    for (int i = 1; i <= n; i++)
    {//undefined
        TOU[i].num = i;
        TOU[i].toupiaoquan = 1;
        TOU[i].xxx = 0;
    }
    for (int i = 1; i <= n; i++)
    {//undefined
        if (player[i].life == 1 || player[i].name == "白痴   ")
        {//undefined
            Sleep(0);//3000
            if (i == MY)
            {//undefined
                cout << "请投票...(0弃权)" << endl;
                cin >> x;
                while (player[x].life == 0 && x != 0)
                {//undefined
                    cin >> x;
                }
                if (x == 0)
                    cout << MY << "号玩家弃权" << endl;
                else
                    cout << MY << "号玩家投给了" << x << "号玩家" << endl;
            }
            else
            {//undefined
                srand(time(0));
                if (player[i].name == "狼人   ")
                {//undefined
                    x = rand() % (n + 1);
                    while (x != 0 && (player[x].life == 0 || player[x].name == "狼人 " || x == i))
                    {//undefined
                        Sleep(rand() % 98);
                        srand(time(0));
                        x = rand() % (n + 1);
                    }
                    if (x == 0)
                        cout << i << "号玩家弃权" << endl;
                    else
                        cout << i << "号玩家投给了" << x << "号玩家" << endl;
                }
                else if (player[i].name == "预言家 ")
                {//undefined
                    x = rand() % (n + 1);
                    while (x != 0 && (player[x].life == 0 || player[x].name != "狼人   " || x == i))
                    {//undefined
                        Sleep(rand() % 98);
                        srand(time(0));
                        x = rand() % (n + 1);
                    }
                    if (x == 0)
                        cout << i << "号玩家弃权" << endl;
                    else
                        cout << i << "号玩家投给了" << x << "号玩家" << endl;
                }
                else
                {//undefined
                    x = rand() % (n + 1);
                    while (x != 0 && (player[x].life == 0 || x == i))
                    {//undefined
                        Sleep(rand() % 98);
                        srand(time(0));
                        x = rand() % (n + 1);
                    }
                    if (x == 0)
                        cout << i << "号玩家弃权" << endl;
                    else
                        cout << i << "号玩家投给了" << x << "号玩家" << endl;
                }
            }
            if (x != 0)
                TOU[x].xxx++;
        }
    }
    Sleep(0);//3000
    sort(TOU + 1, TOU + n + 1, cmp);
    if (TOU[2].xxx != TOU[1].xxx)
    {//undefined
        cout << "投票结束," << TOU[1].num << "号投票出局" << endl;
        if (player[TOU[1].num].name == "耶稣   " && yesuming >= 1)
		{//undefined
			yesuming = yesuming - 1;
			player[TOU[1].num].know = 2;
		}
		else
		{//undefined
	        player[TOU[1].num].life = 0;
	        player[TOU[1].num].how = 2;
		}
    	Sleep(3000);
        return;
    }
    else
    {//undefined
        TOU[1].toupiaoquan = 0;
        TOU[2].toupiaoquan = 0;
        system("cls");
        print(ddd, nnn);
        cout << TOU[1].num << "号," << TOU[2].num << "号";
        int i;
        for (i = 3; i <= n; i++)
        {//undefined
            if (TOU[i].xxx == TOU[1].xxx)
            {//undefined
                TOU[i].toupiaoquan = 0;
                cout << "," << TOU[i].num << "号";
            }
            else
                break;
        }
        if (i == n + 1)
        {//undefined
            for (int i = 1; i <= n; i++)
                TOU[i].toupiaoquan = 1;
        }
        cout << "平票" << endl;
    }
    //--------2--------
    sort(TOU + 1, TOU + n + 1, cmp1);
    cout << "请再次投票";
    for (int i = 1; i <= 3; i++)
    {//undefined
        cout << ".";
    Sleep(0);//500
    }
    cout << endl;
    for (int i = 1; i <= n; i++)
    {//undefined
        if ((player[i].life == 1 || player[i].name == "白痴   ") && TOU[i].toupiaoquan == 1)
        {//undefined
    Sleep(0);//3000
            if (i == MY)
            {//undefined
                cout << "请投票...(0弃权)" << endl;
                cin >> x;
                while ((player[x].life == 0 || TOU[x].toupiaoquan == 1) && x != 0)
                {//undefined
                    cin >> x;
                }
                if (x == 0)
                    cout << MY << "号玩家弃权" << endl;
                else
                    cout << MY << "号玩家投给了" << x << "号玩家" << endl;
            }
            else
            {//undefined
                srand(time(0));
                if (player[i].name == "狼人   ")
                {//undefined
                    x = rand() % (n + 1);
                    while (x != 0 && (player[x].life == 0 || player[x].name == "狼人   " || x == i || TOU[x].toupiaoquan == 1))
                    {//undefined
                        srand(time(0));
                        x = rand() % (n + 1);
                    }
                    if (x == 0)
                        cout << i << "号玩家弃权" << endl;
                    else
                        cout << i << "号玩家投给了" << x << "号玩家" << endl;
                }
                else if (player[i].name == "预言家 ")
                {//undefined
                    x = rand() % (n + 1);
                    while (x != 0 && (player[x].life == 0 || player[x].name != "狼人   " || x == i || TOU[x].toupiaoquan == 1))
                    {//undefined
                        srand(time(0));
                        x = rand() % (n + 1);
                    }
                    if (x == 0)
                        cout << i << "号玩家弃权" << endl;
                    else
                        cout << i << "号玩家投给了" << x << "号玩家" << endl;
                }
                else
                {//undefined
                    x = rand() % (n + 1);
                    while (x != 0 && (player[x].life == 0 || x == i || TOU[x].toupiaoquan == 1))
                    {//undefined
                        srand(time(0));
                        x = rand() % (n + 1);
                    }
                    if (x == 0)
                        cout << i << "号玩家弃权" << endl;
                    else
                        cout << i << "号玩家投给了" << x << "号玩家" << endl;
                }
            }
            if (x != 0 && TOU[i].toupiaoquan == 1)
                TOU[x].xxx++;
        }
    }
    Sleep(0);//3000
    sort(TOU + 1, TOU + n + 1, cmp);
    if (TOU[2].xxx != TOU[1].xxx)
    {//undefined
        cout << "投票结束," << TOU[1].num << "号投票出局" << endl;
        if (player[TOU[1].num].name == "耶稣   " && yesuming >= 1)
		{//undefined
			yesuming = yesuming - 1;
			player[TOU[1].num].know = 2;
		}
		else
		{//undefined
	        player[TOU[1].num].life = 0;
	        player[TOU[1].num].how = 2;
		}
    	Sleep(3000);
        return;
    }
    else
    {//undefined
        TOU[1].toupiaoquan = 0;
        TOU[2].toupiaoquan = 0;
        system("cls");
        print(ddd, nnn);
        cout << TOU[1].num << "号," << TOU[2].num << "号";
        int i;
        for (i = 3; i <= n; i++)
        {//undefined
            if (TOU[i].xxx == TOU[1].xxx)
            {//undefined
                TOU[i].toupiaoquan = 0;
                cout << "," << TOU[i].num << "号";
            }
            else
                break;
        }
        if (i == n + 1)
        {//undefined
            for (int i = 1; i <= n; i++)
                TOU[i].toupiaoquan = 1;
        }
        cout << "平票" << endl;
    }
    //--------3--------
    sort(TOU + 1, TOU + n + 1, cmp1);
    cout << "请再次投票";
    for (int i = 1; i <= 3; i++)
    {//undefined
        cout << ".";
    Sleep(0);//500
    }
    cout << endl;
    for (int i = 1; i <= n; i++)
    {//undefined
        if ((player[i].life == 1 || player[i].name == "白痴   ") && TOU[i].toupiaoquan == 1)
        {//undefined
    		Sleep(0);//3000
            if (i == MY)
            {//undefined
                cout << "请投票...(0弃权)" << endl;
                cin >> x;
                while ((player[x].life == 0 || TOU[x].toupiaoquan == 1) && x != 0)
                {//undefined
                    cin >> x;
                }
                if (x == 0)
                    cout << MY << "号玩家弃权" << endl;
                else
                    cout << MY << "号玩家投给了" << x << "号玩家" << endl;
            }
            else
            {//undefined
                srand(time(0));
                if (player[i].name == "狼人 ")
                {//undefined
                    x = rand() % (n + 1);
                    while (x != 0 && (player[x].life == 0 || player[x].name == "狼人   " || x == i || TOU[x].toupiaoquan == 1))
                    {//undefined
                        srand(time(0));
                        x = rand() % (n + 1);
                    }
                    if (x == 0)
                        cout << i << "号玩家弃权" << endl;
                    else
                        cout << i << "号玩家投给了" << x << "号玩家" << endl;
                }
                else if (player[i].name == "预言家 " || player[i].name == "猎人   ")
                {//undefined
                    x = rand() % (n + 1);
                    while (x != 0 && (player[x].life == 0 || player[x].name != "狼人   " || x == i || TOU[x].toupiaoquan == 1))
                    {//undefined
                        srand(time(0));
                        x = rand() % (n + 1);
                    }
                    if (x == 0)
                        cout << i << "号玩家弃权" << endl;
                    else
                        cout << i << "号玩家投给了" << x << "号玩家" << endl;
                }
                else
                {//undefined
                    x = rand() % (n + 1);
                    while (x != 0 && (player[x].life == 0 || x == i || TOU[x].toupiaoquan == 1))
                    {//undefined
                        srand(time(0));
                        x = rand() % (n + 1);
                    }
                    if (x == 0)
                        cout << i << "号玩家弃权" << endl;
                    else
                        cout << i << "号玩家投给了" << x << "号玩家" << endl;
                }
            }
            if (x != 0 && TOU[i].toupiaoquan == 1)
                TOU[x].xxx++;
        }
    }
    Sleep(0);//3000
    sort(TOU + 1, TOU + n + 1, cmp);
    if (TOU[2].xxx != TOU[1].xxx)
    {//undefined
        cout << "投票结束," << TOU[1].num << "号投票出局" << endl;
        if (player[TOU[1].num].name == "耶稣   " && yesuming >= 1)
		{//undefined
			yesuming = yesuming - 1;
			player[TOU[1].num].know = 2;
		}
		else
		{//undefined
	        player[TOU[1].num].life = 0;
	        player[TOU[1].num].how = 2;
		}
    }
    else
    {//undefined
        cout << "投票结束,无人出局" << endl;
    }
    Sleep(5000);
}
bool game_over()
{//undefined
    int pingmin = 0;
    int langren = 0;
    int shenzhi = 0;
    for (int i = 1; i <= n; i++)
    {//undefined
        if (player[i].life == 0)
            continue;
        if (player[i].name == "狼人   ")
            langren++;
        else if (player[i].name == "村民   " || player[i].name == "白痴   ")
            pingmin++;
        else if (player[i].name == "女巫   " || player[i].name == "预言家 " || player[i].name == "白熊   " || player[i].name == "耶稣   ")
            shenzhi++;
    }
    if (shenzhi == 0 || langren == 0 || pingmin == 0)
        return 1;
    return 0;
}
void night()
{//undefined
    system("cls");
    system("color 0f");
    print(1, 1);
    cout << "天~黑~请~闭~眼~~~" << endl;
    if (n >= 12)
        shoushui(1, 1);
    Sleep(0);//3000
    system("cls");
    print(1, 1);
    cout << "狼~人~请~睁~眼~~~" << endl;
    if (player[MY].name == "狼人   ")
    {//undefined
        Sleep(0);//1000
        cout << "你的同伴有:";
        for (int i = 1; i <= n; i++)
        {//undefined
            if (i == MY)
                continue;
            if (player[i].name == "狼人   ")
            {//undefined
                cout << player[i].num << "号 ";
                player[i].know = 2;
            }
        }
        Sleep(0);//3000
        cout << endl << "请问你们要杀谁:" << endl << "输入:";
        cin >> kill1;
        Sleep(0);//1500
        system("cls");
        print(1, 1);
        cout << "今晚你们要杀的是" << kill1 << "号玩家" << endl;
    }
    else
    {//undefined
    Sleep(0);//4000
        system("cls");
        print(1, 1);
        cout << "请问你们要杀谁?" << endl;
        do
        {//undefined
            Sleep(rand() % 18);
            srand(time(0));
            int x = rand() % n + 1;
            if (player[x].name != "狼人   " && player[x].life == 1)
            {//undefined
                kill1 = x;
                break;
            }
        } while (1);
        Sleep(0);//5000
    }
    Sleep(3000);
    system("cls");
    print(1, 1);
    cout << "狼~人~请~闭~眼~~~" << endl;
    Sleep(0);//2000
    system("cls");
    print(1, 1);
    cout << "女~巫~请~睁~眼~~~" << endl;
    Sleep(0);//2000
    system("cls");
    print(1, 1);
    if (player[MY].name == "女巫   " && player[MY].life == 1)
    {//undefined
    	Sleep(0);//1000
        if (jieyao == 1)
        {//undefined
            cout << "今晚" << kill1 << "号玩家被杀" << endl;
            Sleep(0);//500
            cout << "请问你要救吗???" << endl << "A. 救 B.不救" << endl << "输入:";
            cin >> a;
            if (a == 'A')
            {//undefined
                system("cls");
                print(1, 1);
                cout << "请问你要毒吗???" << endl;
    			Sleep(0);//2000
                system("cls");
                print(1, 1);
                cout << "今晚" << kill1 << "号玩家被你解救" << endl;
                jieyao = 0;
                if (shou != kill1)
                    kill1 = 0;
            }
            else
            {//undefined
                if (shou == kill1)
                    kill1 = 0;
    			Sleep(0);//2000
                system("cls");
                print(1, 1);
                cout << "请问你要毒吗???" << endl << "A. 毒 B.不毒" << endl << "输入:";
                cin >> a;
                if (a == 'A')
                {//undefined
                    cout << "请问你要毒谁???" << endl << "输入:";
                    cin >> kill2;
                    while (player[kill2].life != 1)
                    {//undefined
                        cout << "输入错误,请重新输入:" << endl;
                        cin >> kill2;
                    }
                    duyao = 0;
                }
            }
        }
        else
        {//undefined
            if (shou == kill1)
                kill1 = 0;
            Sleep(0);//2000
            system("cls");
            print(1, 1);
            cout << "请问你要毒吗???" << endl << "A. 毒 B.不毒" << endl << "输入:";
            cin >> a;
            if (a == 'A')
            {//undefined
                cout << "请问你要毒谁???" << endl << "输入:";
                cin >> kill2;
                while (player[kill2].life != 1)
                {//undefined
                    cout << "输入错误,请重新输入:" << endl;
                    cin >> kill2;
                }
                duyao = 0;
            }
        }
    }
    else
    {//undefined
        bool b = 0;
        cout << "请问你是否要用解药???" << endl;
        int FFF = 0, kkkk;
        for (int i = 1; i <= n; i++)
        {//undefined
            if (player[i].life == 1 && player[i].name == "村民 ")
                FFF++;
            if (player[i].name == "女巫   ")
                kkkk = i;
        }
        if (jieyao == 1 && player[kkkk].life == 1)
        {//undefined
            if (FFF == 1)
            {//undefined
                if (shou == kill1)
                    jieyao = 1;
                else
                    jieyao = 0;
                kill1 = 0;
                b = 1;
            }
            else
                for (int i = 1; i <= n; i++)
                {//undefined
                    if (player[i].name == "女巫   " && kill1 == i)
                    {//undefined
                        kill1 = 0;
                        if (shou == kill1)
                            jieyao = 1;
                        else
                            jieyao = 0;
                        b = 1;
                        break;
                    }
                    else if (player[i].name == "预言家 " && kill1 == i)
                    {//undefined
                        kill1 = 0;
                        if (shou == kill1)
                            jieyao = 1;
                        else
                            jieyao = 0;
                        b = 1;
                        break;
                    }
                }
        }
    Sleep(0);//3000
        if (b == 0 && duyao == 1 && player[kkkk].life == 1)
        {//undefined
            system("cls");
            print(1, 1);
            cout << "请问你是否要用毒药???" << endl;
            srand(time(0));
            int x = rand() % 2;
    		Sleep(0);//1500
            cout << "请问你要毒谁???" << endl;
            if (x == 1)
            {//undefined
                duyao = 0;
                int y = rand() % n + 1;
                while ((player[y].name == "女巫   " || player[y].name == "预言家 " || y == kill1) || player[y].life == 0)
                    y = rand() % n + 1;
                kill2 = y;
            }
        }
        else
        {//undefined
    		Sleep(0);//3000
            system("cls");
            print(1, 1);
            cout << "请问你是否要用毒药???" << endl;
    		Sleep(0);//3000
            cout << "请问你要毒谁???" << endl;
    		Sleep(0);//3000
        }
    }
    Sleep(3000);
    system("cls");
    print(1, 1);
    cout << "女~巫~请~闭~眼~~~" << endl;
    if (n > 6)
    {//undefined
    		Sleep(0);//3000
        system("cls");
        print(1, 1);
        cout << "预~言~家~请~睁~眼~~~" << endl;
        if (player[MY].name == "预言家 ")
        {//undefined
    		Sleep(0);//3000
            cout << "请问你想查验谁???" << endl << "输入:";
            int x;
            cin >> x;
            player[x].know = 1;
    		Sleep(0);//2000
            system("cls");
            print(1, 1);
            cout << "他没身份。";
    		Sleep(3000);
        }
        else
        {//undefined
    		Sleep(0);//3000
            cout << "请问你想查验谁???" << endl;
    		Sleep(0);//3000
            system("cls");
            print(1, 1);
            cout << "他的身份是:......";
    		Sleep(0);//3000
        }
    	Sleep(0);//3000
        system("cls");
        print(1, 1);
        cout << "预~言~家~请~闭~眼~~~" << endl;
    }
    Sleep(0);//3000
	if (player[kill1].name == "耶稣   " && yesuming >= 1)
	{//undefined
		yesuming = yesuming - 1;
		player[kill1].know = 2;
		kill1 = 0;
	}
	if (player[kill2].name == "耶稣   " && yesuming >= 1)
	{//undefined
		yesuming = yesuming - 1;
		player[kill2].know = 2;
		kill2 = 0;
	}
    if (kill1 != 0)
        player[kill1].life = 0;
    if (kill2 != 0)
        player[kill2].life = 0;
    player[kill1].how = 1;
    player[kill2].how = 3;
    system("cls");
    system("color F0");
    print(2, 0);
}
void night2(int hhh, int hhhh)
{//undefined
    system("cls");
    system("color 0f");
    print(hhh, hhhh);
    cout << "天~黑~请~闭~眼~~~" << endl;
    if (n >= 12)
        shoushui(hhh, hhhh);
    Sleep(0);//3000
    system("cls");
    print(hhh, hhhh);
    cout << "狼~人~请~睁~眼~~~" << endl;
    if (player[MY].name == "狼人   " && player[MY].life == 1)
    {//undefined
    	Sleep(0);//3000
        cout << endl << "请问你们要杀谁:" << endl << "输入:";
        cin >> kill1;
    	Sleep(0);//1500
        system("cls");
        print(hhh, hhhh);
        cout << "今晚你们要杀的是" << kill1 << "号玩家" << endl;
    }
    else
    {//undefined
    	Sleep(0);//4000
        system("cls");
        print(hhh, hhhh);
        cout << "请问你们要杀谁?" << endl;
        do
        {//undefined
            srand(time(0));
            int x = rand() % n + 1;
            if (player[x].name != "狼人   " && player[x].life == 1)
            {//undefined
                kill1 = x;
                break;
            }
        } while (1);
        Sleep(0);//5000
    }
    Sleep(3000);
    system("cls");
    print(hhh, hhhh);
    cout << "狼~人~请~闭~眼~~~" << endl;
    Sleep(0);//2000
    system("cls");
    print(hhh, hhhh);
    cout << "女~巫~请~睁~眼~~~" << endl;
    Sleep(0);//2000
    system("cls");
    print(hhh, hhhh);
    if (player[MY].name == "女巫   " && player[MY].life == 1)
    {//undefined
    	Sleep(0);//1000
        if (jieyao == 1)
        {//undefined
            cout << "今晚" << kill1 << "号玩家被杀" << endl;
    		Sleep(0);//500
            cout << "请问你要救吗???" << endl << "A. 救 B.不救" << endl << "输入:";
            cin >> a;
            if (a == 'A')
            {//undefined
                system("cls");
                print(hhh, hhhh);
                cout << "请问你要毒吗???" << endl;
    			Sleep(0);//2000
                system("cls");
                print(hhh, hhhh);
                cout << "今晚" << kill1 << "号玩家被你解救" << endl;
                jieyao = 0;
                if (shou != kill1)
                    kill1 = 0;
            }
            else
            {//undefined
                if (shou == kill1)
                    kill1 = 0;
    			Sleep(0);//2000
                system("cls");
                print(hhh, hhhh);
                cout << "请问你要毒吗???" << endl << "A. 毒 B.不毒" << endl << "输入:";
                cin >> a;
                if (a == 'A')
                {//undefined
                    cout << "请问你要毒谁???" << endl << "输入:";
                    cin >> kill2;
                    while (player[kill2].life != 1)
                    {//undefined
                        cout << "输入错误,请重新输入:" << endl;
                        cin >> kill2;
                    }
                    duyao = 0;
                }
            }
        }
        else if (duyao == 1)
        {//undefined
            if (shou == kill1)
                kill1 = 0;
    		Sleep(0);//2000
            system("cls");
            print(hhh, hhhh);
            cout << "请问你要毒吗???" << endl << "A. 毒 B.不毒" << endl << "输入:";
            cin >> a;
            if (a == 'A')
            {//undefined
                cout << "请问你要毒谁???" << endl << "输入:";
                cin >> kill2;
                while (player[kill2].life != 1)
                {//undefined
                    cout << "输入错误,请重新输入:" << endl;
                    cin >> kill2;
                }
                duyao = 0;
            }
        }
        else
        {//undefined
    		Sleep(0);//2000
            system("cls");
            print(hhh, hhhh);
            cout << "请问你要毒吗???" << endl;
        }
    }
    else
    {//undefined
        bool b = 0;
        cout << "请问你是否要用解药???" << endl;
        int FFF = 0, kkkk;
        for (int i = 1; i <= n; i++)
        {//undefined
            if (player[i].life == 1 && player[i].name == "村民   ")
                FFF++;
            if (player[i].name == "女巫   ")
                kkkk = i;
        }
        if (jieyao == 1 && player[kkkk].life == 1)
        {//undefined
            if (FFF == 1)
            {//undefined
                if (shou == kill1)
                    jieyao = 1;
                else
                    jieyao = 0;
                kill1 = 0;
                b = 1;
            }
            else
                for (int i = 1; i <= n; i++)
                {//undefined
                    if (player[i].name == "女巫   " && kill1 == i)
                    {//undefined
                        kill1 = 0;
                        if (shou == kill1)
                            jieyao = 1;
                        else
                            jieyao = 0;
                        b = 1;
                        break;
                    }
                    else if (player[i].name == "预言家 " && kill1 == i)
                    {//undefined
                        kill1 = 0;
                        if (shou == kill1)
                            jieyao = 1;
                        else
                            jieyao = 0;
                        b = 1;
                        break;
                    }
                }
        }
    	Sleep(0);//3000
        if (b == 0 && duyao == 1 && player[kkkk].life == 1)
        {//undefined
            system("cls");
            print(hhh, hhhh);
            cout << "请问你是否要用毒药???" << endl;
            srand(time(0));
            int x = rand() % 2;
    		Sleep(0);//1500
            cout << "请问你要毒谁???" << endl;
            if (x == 1)
            {//undefined
                duyao = 0;
                int y = rand() % n + 1;
                while ((player[y].name == "女巫   " || player[y].name == "预言家   " || y == kill1) || player[y].life == 0)
                    y = rand() % n + 1;
                kill2 = y;
            }
        }
        else
        {//undefined
    		Sleep(0);//3000
            system("cls");
            print(hhh, hhhh);
            cout << "请问你是否要用毒药???" << endl;
    		Sleep(0);//3000
            cout << "请问你要毒谁???" << endl;
    		Sleep(0);//3000
        }
    }
    Sleep(3000);
    system("cls");
    print(hhh, hhhh);
    cout << "女~巫~请~闭~眼~~~" << endl;
    if (n > 6)
    {//undefined
    	Sleep(0);//3000
        system("cls");
        print(hhh, hhhh);
        cout << "预~言~家~请~睁~眼~~~" << endl;
        if (player[MY].name == "预言家 " && player[MY].life == 1)
        {//undefined
    		Sleep(0);//3000
            cout << "请问你想查验谁???" << endl << "输入:";
            int x;
            cin >> x;
            player[x].know = 1;
    		Sleep(0);//2000
            system("cls");
            print(hhh, hhhh);
            cout << "他没身份。";
            Sleep(3000);
        }
        else
        {//undefined
    		Sleep(0);//3000
            cout << "请问你想查验谁???" << endl;
    		Sleep(0);//3000
            system("cls");
            print(hhh, hhhh);
            cout << "他的身份是:......";
    		Sleep(0);//3000
        }
    	Sleep(0);//3000
        system("cls");
        print(hhh, hhhh);
        cout << "预~言~家~请~闭~眼~~~" << endl;
    }
    Sleep(0);//3000
	if (player[kill1].name == "耶稣   " && yesuming >= 1)
	{//undefined
		yesuming = yesuming - 1;
		player[kill1].know = 2;
		kill1 = 0;
	}
	if (player[kill2].name == "耶稣   " && yesuming >= 1)
	{//undefined
		yesuming = yesuming - 1;
		player[kill2].know = 2;
		kill2 = 0;
	}
    if (kill1 != 0)
        player[kill1].life = 0;
    if (kill2 != 0)
        player[kill2].life = 0;
    player[kill1].how = 1;
    player[kill2].how = 3;
    system("cls");
    system("color F0");
    print(hhh + 1, 0);
}
bool lr = 0;
void panduanlieren()
{//undefined
    if (lr == 1)
        return;
    if (MY == lieren)
    {//undefined
        cout << "请射杀一名玩家" << endl;
        int x;
        cin >> x;
        while (player[x].life != 1)
        {//undefined
            cout << "输入错误,请重新输入" << endl;
            cin >> x;
        }
        Sleep(1000);
        cout << lieren << "号猎人发动技能,开枪带走了" << x << "号" << endl;
        player[x].life = 0;
        player[x].how = 4;
    }
    else if (n >= 9)
    {//undefined
        srand(time(0));
        int x = rand() % n + 1;
        while (player[x].life != 1)
        {//undefined
            x = rand() % n + 1;
        }
        Sleep(1000);
        cout << lieren << "号猎人发动技能,开枪带走了" << x << "号" << endl;
        player[x].life = 0;
        player[x].how = 4;
    }
    lr = 1;
}
bool panduanbaixiong(){
	int baixiong = 0;
	for (int i = 1; i <= n; i++)
	{//undefined
		if (player[i].name == "白熊   " && player[i].life == 1)
		{//undefined
			baixiong = i;
			break;
		}
		else
			baixiong = 0;
	}
	if (baixiong == 0)
		return 0;
	if (baixiong == n)
	{//undefined
		if (player[n - 1].name == "狼人   " && player[n - 1].life == 1)
			return 1;
		else if (player[1].name == "狼人   " && player[1].life == 1)
			return 1;
	}
	else if (baixiong == 1)
	{//undefined
		if (player[n].name == "狼人   " && player[n].life == 1)
			return 1;
		else if (player[2].name == "狼人   " && player[2].life == 1)
			return 1;
	}
	else
	{//undefined
		if (player[baixiong - 1].name == "狼人   " && player[baixiong - 1].life == 1)
			return 1;
		else if (player[baixiong + 1].name == "狼人   " && player[baixiong + 1].life == 1)
			return 1;
	}
	for (int i = baixiong + 1; i <= n; i++)
	{//undefined
		if (player[i].name == "白熊   " && player[i].life == 1)
		{//undefined
			baixiong = i;
			break;
		}
		else
			baixiong = 0;
	}
	if (baixiong == 0)
		return 0;
	if (baixiong == n)
	{//undefined
		if (player[n - 1].name == "狼人   " && player[n - 1].life == 1)
			return 1;
		else if (player[1].name == "狼人   " && player[1].life == 1)
			return 1;
	}
	else if (baixiong == 1)
	{//undefined
		if (player[n].name == "狼人   " && player[n].life == 1)
			return 1;
		else if (player[2].name == "狼人   " && player[2].life == 1)
			return 1;
	}
	else
	{//undefined
		if (player[baixiong - 1].name == "狼人   " && player[baixiong - 1].life == 1)
			return 1;
		else if (player[baixiong + 1].name == "狼人   " && player[baixiong + 1].life == 1)
			return 1;
	}
	return 0;
}
void print1()
{//undefined
    cout << "天亮了,昨晚";
    if (kill1 != 0 || kill2 != 0)
    {//undefined
        cout << kill1 << "号";
        if (kill2 != 0)
        {//undefined
            cout << "," << kill2 << "号";
            kill2 = 0;
        }
        cout << "被杀";
    	if (panduanbaixiong())
        	cout << ",并且白熊咆哮了!" << endl;
        else
        	cout << endl;
    }
    else
    {//undefined
    	if (panduanbaixiong())
        	cout << "白熊咆哮了!" << endl;
        else
        	cout << "是平安夜" << endl;
    }
}
int main()
{//undefined
    system("cls");
    cout << " " << "狼人杀online" << endl;
    cout << "请输入人数个数:" << endl;
    scanf("%d", &n);
    cout << "加载时间长,请耐心等待";
    init1();
    init2(n);
    int k = 1;
    do
    {//undefined
        srand(time(0));
        init3(k);
        cout << ".";
        Sleep(0);//17
        k++;
    } while (k <= n);
    system("cls");
    system("color F0");
    cout << "游戏即将开始";
    for (int i = 1; i <= 6; i++)
    {//undefined
        cout << ".";
        Sleep(0);//500
    }
    Sleep(0);//1500
    cout << endl << endl << "请大家查看身份牌......" << endl;
    Sleep(0);//45
    srand(time(0));
    MY = rand() % n + 1;
    cout << "您的身份是:" << player[MY].name << endl;
    Sleep(0);//500
    cout << "在" << player[MY].num << "号位上" << endl;
    system("pause");
    system("cls");
    player[MY].know = 2;
    if (player[MY].name == "猎人   ")
        lieren = MY;
    if (player[MY].name == "守卫   ")
        shouwei = MY;
    if (n >= 32)
    {//undefined
	    for (int i = 1; i <= n; i++)
	    {//undefined
	        if (player[i].name == "白痴   ")
		    {//undefined
		        player[i].know = 2;
		        break;
		    }
	    }
    }
    print(1, 0);
    cout << "即将进入夜晚";
    for (int i = 1; i <= 6; i++)
    {//undefined
        cout << ".";
        Sleep(500);
    }
    night();
    print1();
    if (game_over())
    {//undefined
        Sleep(1000);
        system("cls");
        cout << "游戏结束" << endl; printhhh();
        return 0;
    }
    if (player[lieren].life == 0 && lr == 0)
    {//undefined
        panduanlieren();
    }
    if (game_over())
    {//undefined
        Sleep(1000);
        system("cls");
        cout << "游戏结束" << endl; printhhh();
        return 0;
    }
    toupiao(2, 0);
    system("cls");
    print(2, 0);
    if (game_over())
    {//undefined
        Sleep(1000);
        system("cls");
        cout << "游戏结束" << endl; printhhh();
        return 0;
    }
    else if (player[lieren].life == 0 && lr == 0)
    {//undefined
        panduanlieren();
    }
    cout << "即将进入夜晚";
    for (int i = 1; i <= 6; i++)
    {//undefined
        cout << ".";
        Sleep(500);
    }
    night2(2, 1);
    print1();
    if (game_over())
    {//undefined
        Sleep(1000);
        system("cls");
        cout << "游戏结束" << endl; printhhh();
        return 0;
    }
    if (player[lieren].life == 0 && lr == 0)
    {//undefined
        panduanlieren();
    }
    if (game_over())
    {//undefined
        Sleep(1000);
        system("cls");
        cout << "游戏结束" << endl; printhhh();
        return 0;
    }
    toupiao(3, 0);
    system("cls");
    print(3, 0);
    if (game_over())
    {//undefined
        Sleep(1000);
        system("cls");
        cout << "游戏结束" << endl; printhhh();
        return 0;
    }
    else if (player[lieren].life == 0 && lr == 0)
    {//undefined
        panduanlieren();
    }
    cout << "即将进入夜晚";
    for (int i = 1; i <= 6; i++)
    {//undefined
        cout << ".";
        Sleep(0);//500
    }
    night2(3, 1);
    print1();
    if (game_over())
    {//undefined
        Sleep(1000);
        system("cls");
        cout << "游戏结束" << endl; printhhh();
        return 0;
    }
    if (player[lieren].life == 0)
    {//undefined
        panduanlieren();
    }
    if (game_over())
    {//undefined
        Sleep(1000);
        system("cls");
        cout << "游戏结束" << endl; printhhh();
        return 0;
    }
    toupiao(4, 0);
    system("cls");
    print(4, 0);
    if (game_over())
    {//undefined
        Sleep(1000);
        system("cls");
        cout << "游戏结束" << endl; printhhh();
        return 0;
    }
    else if (player[lieren].life == 0 && lr == 0)
    {//undefined
        panduanlieren();
    }
    if (game_over())
    {//undefined
        Sleep(1000);
        system("cls");
        cout << "游戏结束" << endl; printhhh();
        return 0;
    }
    cout << "即将进入夜晚";
    for (int i = 1; i <= 6; i++)
    {//undefined
        cout << ".";
        Sleep(0);//500
    }
    night2(4, 1);
    print1();
    if (game_over())
    {//undefined
        Sleep(1000);
        system("cls");
        cout << "游戏结束" << endl; printhhh();
        return 0;
    }
    if (player[lieren].life == 0)
    {//undefined
        panduanlieren();
    }
    if (game_over())
    {//undefined
        Sleep(1000);
        system("cls");
        cout << "游戏结束" << endl; printhhh();
        return 0;
    }
    toupiao(5, 0);
    system("cls");
    print(5, 0);
    if (game_over())
    {//undefined
        Sleep(1000);
        system("cls");
        cout << "游戏结束" << endl; printhhh();
        return 0;
    }
    else if (player[lieren].life == 0 && lr == 0)
    {//undefined
        panduanlieren();
    }
    if (game_over())
    {//undefined
        Sleep(1000);
        system("cls");
        cout << "游戏结束" << endl; printhhh();
        return 0;
    }
    cout << "即将进入夜晚";
    for (int i = 1; i <= 6; i++)
    {//undefined
        cout << ".";
        Sleep(0);//500
    }
    night2(5, 1);
    print1();
    if (game_over())
    {//undefined
        Sleep(1000);
        system("cls");
        cout << "游戏结束" << endl; printhhh();
        return 0;
    }
    if (player[lieren].life == 0)
    {//undefined
        panduanlieren();
    }
    if (game_over())
    {//undefined
        Sleep(1000);
        system("cls");
        cout << "游戏结束" << endl; printhhh();
        return 0;
    }
    toupiao(6, 0);
    system("cls");
    print(6, 0);
    if (game_over())
    {//undefined
        Sleep(1000);
        system("cls");
        cout << "游戏结束" << endl; printhhh();
        return 0;
    }
    else if (player[lieren].life == 0 && lr == 0)
    {//undefined
        panduanlieren();
    }
    if (game_over())
    {//undefined
        Sleep(1000);
        system("cls");
        cout << "游戏结束" << endl; printhhh();
        return 0;
    }
    cout << "即将进入夜晚";
    for (int i = 1; i <= 6; i++)
    {// undefined
        cout << ".";
        Sleep(500);
    }
    night2(6, 1);
    print1();
    if (game_over())
    {//undefined
        Sleep(1000);
        system("cls");
        cout << "游戏结束" << endl; printhhh();
        return 0;
    }
    if (player[lieren].life == 0)
    {//undefined
        panduanlieren();
    }
    if (game_over())
    {//undefined
        Sleep(1000);
        system("cls");
        cout << "游戏结束" << endl; printhhh();
        return 0;
    }
    toupiao(7, 0);
    system("cls");
    print(7, 0);
    if (game_over())
    {//undefined
        Sleep(1000);
        system("cls");
        cout << "游戏结束" << endl; printhhh();
        return 0;
    }
    else if (player[lieren].life == 0 && lr == 0)
    {//undefined
        panduanlieren();
    }
    if (game_over())
    {//undefined
        Sleep(1000);
        system("cls");
        cout << "游戏结束" << endl; printhhh();
        return 0;
    }
    for (int j = 7; ; j++){ 
	    cout << "即将进入夜晚";
	    for (int i = 1; i <= 6; i++)
	    {// undefined
	        cout << ".";
	        Sleep(500);
	    }
	    night2(j, 1);
	    print1();
	    if (game_over())
	    {//undefined
	        Sleep(1000);
	        system("cls");
	        cout << "游戏结束" << endl; printhhh();
	        return 0;
	    }
	    if (player[lieren].life == 0)
	    {//undefined
	        panduanlieren();
	    }
	    if (game_over())
	    {//undefined
	        Sleep(1000);
	        system("cls");
	        cout << "游戏结束" << endl; printhhh();
	        return 0;
	    }
	    toupiao(j + 1, 0);
	    system("cls");
	    print(j + 1, 0);
	    if (game_over())
	    {//undefined
	        Sleep(1000);
	        system("cls");
	        cout << "游戏结束" << endl; printhhh();
	        return 0;
	    }
	    else if (player[lieren].life == 0 && lr == 0)
	    {//undefined
	        panduanlieren();
	    }
	    if (game_over())
	    {//undefined
	        Sleep(1000);
	        system("cls");
	        cout << "游戏结束" << endl; printhhh();
	        return 0;
	    }
    }
    return 0;
}

3.斗地主

#include<bits/stdc++.h>
#define PLAYERCOUNT 3
#define CARDSCOUNT 54
#define CURRENTPLAYER 0
#define VALUECOUNT 17
#define ERROR -1

using namespace std;
const char toFigure[]="34567890JQKA 2YZ";
enum COLOR{  //花色显示ASCII: 3~6
	eHEART=3,//红桃
	eDIAMOND,//方片
	eCLUB,   //草花
	eSPADE   //黑桃
};

class Card;
class CardsType;
class CardGroup;
class Player;
class Landlords;
class LastCards;
bool makeChoice(string tip);
bool cmp(Card* a,Card* b);

class Card{
	
public:
	char figure;
	COLOR color;
	int value;
	Card(char _figure,COLOR _color){
		figure=_figure;
		color=_color;
		value=calValue();
	}
	int calValue(){
		for(int i=0;toFigure[i];i++){
			if(toFigure[i]==figure){
				return i;
			}
		}
		return ERROR;
	}
	void print(){
		assert(value!=ERROR);
		if(figure=='Z'){
			cout<<"ZZ";
		}else if(figure=='Y'){
			cout<<"YY";
		}else{
			cout<<figure<<(char)color;
		}
		cout<<' ';
	}
};

class CardsType{
public:
	//为了规范查找对应牌的方法
	//统一为3个参数cnt1、isContinuous、cnt2
	int typeId;
	string typeStr;
	int cnt1,cnt2;
	bool isContinuous;
	CardsType(){
		typeId=ERROR;
	}
	bool operator ==(const CardsType& other)const{
		return this->typeId==other.typeId;
	}
	void init(char* _typeStr,int _typeId,int _cnt1,bool _isContinuous,int _cnt2){
		cnt1=_cnt1;
		isContinuous=_isContinuous;
		cnt2=_cnt2;
		typeStr=_typeStr;
		typeId=_typeId;
	}
};

class CardGroup{
public:
	vector<Card*> cards;
	CardsType type;
	void calType(){
		int i,n=cards.size();
		//init(typeStr,typeId,cnt1,isContinuous,cnt2)
		if(n==0){
			type.init("不出",14,0,0,0);
			return;
		}
		if(n==2&&cards[0]->value==15&&cards[1]->value==14){
			type.init("王炸",0,0,0,0);
			return;
		}
		//统计同点数牌有多少张
		int cntFlag[VALUECOUNT]={0};
		for(i=0;i<n;i++){
			cntFlag[cards[i]->value]++;
		}
		//统计点数最多和最少的牌
		int maxCnt=0,minCnt=4;
		for(i=0;i<VALUECOUNT;i++){
			if(maxCnt<cntFlag[i]){
				maxCnt=cntFlag[i];
			}
			if(cntFlag[i]&&minCnt>cntFlag[i]){
				minCnt=cntFlag[i];
			}
		}
		if(n==4&&maxCnt==4){
			type.init("炸蛋",1,4,0,0);
			return;
		}
		if(n==1){
			type.init("单牌",2,1,0,0);
			return;
		}
		if(n==2&&maxCnt==2){
			type.init("对子",3,2,0,0);
			return;
		}
		if(n==3&&maxCnt==3){
			type.init("三张 ",4,3,0,0);
			return;
		}
		if(n==4&&maxCnt==3){
			type.init("三带一",5,3,0,1);
			return;
		}
		if(n==5&&maxCnt==3&&minCnt==2){
			type.init("三带一对",6,3,0,2);
			return;
		}
		if(n==6&&maxCnt==4){
			type.init("四带二",7,4,0,1);
			return;
		}
		if(n==8&&maxCnt==4&&minCnt==2){
			type.init("四带二",8,4,0,2);
			return;
		}
		if(n>=5&&maxCnt==1&&cards[0]->value==cards[n-1]->value+n-1){
			type.init("顺子",9,1,1,0);
			return;
		}
		if(n>=6&&maxCnt==2&&minCnt==2&&cards[0]->value==cards[n-1]->value+n/2-1){
			type.init("连对",10,2,1,0);
			return;
		}
		int fjCnt;//统计连续且大于3三张的牌
		for(i=0;i<VALUECOUNT &&cntFlag[i]<3;i++);
		for(fjCnt=0;i<VALUECOUNT &&cntFlag[i]>=3;i++,fjCnt++);
		if(fjCnt>1){
			if(n==fjCnt*3)
				type.init("飞机",11,3,1,0);
			else if(n==fjCnt*4)
				type.init("飞机",12,3,1,1);
			else if(n==fjCnt*5&&minCnt==2)
				type.init("飞机",13,3,1,2);
		}
	}
	void init(string inputStr, vector<Card*> &cardsHolded){
		this->cards.clear();
		//不出
		if(inputStr=="N"){
			this->calType();
			return;
		}
		int i,j;
		//输入合法性判断
		for(i=0;i<inputStr.size();i++){
			bool find=false;
			for(j=0;toFigure[j];j++){
				if(inputStr[i]==toFigure[j]){
					find=true;
					break;
				}
			}
			if(find==false){
				//输入字符不在toFigure中
				return;
			}
		}
		//查找手中有没有这些牌
		int visitFlag[20]={0};
		for(i=0;i<inputStr.size();i++){
			Card *find=NULL;
			for(j=0;j<cardsHolded.size();j++){
				if(!visitFlag[j]&&cardsHolded[j]->figure==inputStr[i]){
					visitFlag[j]=1;
					find=cardsHolded[j];
					break;
				}
			}
			if(find){
				this->cards.push_back(find);
			}else{
				cout<<inputStr[i];
				cout<<"没有找到\t";
				this->cards.clear();
				return;
			}
		}//end for(i=0;i<inputStr.size();i++)
		this->arrange();
	}
	void init(vector<Card*> newCards){
		this->cards=newCards;
		this->arrange();
	}
	bool isCanBeat(CardGroup &cardGroup){
		if(cardGroup.type.typeStr=="王炸"){
			return false;
		}else if(this->type.typeStr=="王炸"){
			return true;
		}else if(cardGroup.type==this->type &&this->type.typeStr=="炸dan"){
			return value()>cardGroup.value();
		}else if(cardGroup.type.typeStr=="炸蛋"){
			return false;
		}else if(this->type.typeStr=="炸蛋"){
			return true;
		}else if(cardGroup.type==this->type &&this->cards.size()==cardGroup.cards.size()){
			return this->value()>cardGroup.value();
		}else{
			return false;
		}
	}
	int value(){
		//计算牌组权值
		int i;
		if(type.typeStr=="三带一"||type.typeStr=="三带一对"||type.typeStr=="飞机"){
			for(i=2;i<cards.size();i++){
				if(cards[i]->value==cards[i-2]->value){
					return cards[i]->value;
				}
			}
		}
		if(type.typeStr=="四带二"){
			for(i=3;i<cards.size();i++){
				if(cards[i]->value==cards[i-3]->value){
					return cards[i]->value;
				}
			}
		}
		return cards[0]->value;
	}
	void arrange(){
		//整理:排序、计算类型
		sort(this->cards.begin(),this->cards.end(),cmp);
		this->calType();
	}
};
class LastCards{
	static LastCards *lastCards;
public:
	Player *player;
	CardGroup cardGroup;
	static LastCards* inst(){//单例模式
		if(lastCards==NULL){
			lastCards=new LastCards();
		}
		return lastCards;
	}
	vector<Card*> findCanBeatFrom(vector<Card*> &cardsHolded){
		//查找能打得过的牌
		int i,j,k,n=cardsHolded.size(),m=cardGroup.cards.size();
		string typeStr=cardGroup.type.typeStr;
		vector<Card*> ret;
		if(typeStr=="王炸"||n<m){
			//打不过,返回空数组
			return ret;
		}
		int value=cardGroup.value();
		//统计各点牌出现的次数
		int cntFlag[VALUECOUNT]={0};
		for(i=0;i<n;i++){
			cntFlag[cardsHolded[i]->value]++;
		}
		int continuousCount=1;
		if(cardGroup.type.isContinuous){
			continuousCount=m/(cardGroup.type.cnt1+cardGroup.type.cnt2);
		}
		bool findFirstFigure;
		//cout<<"continuousCount="<<continuousCount<<endl;
		for(i=value+1;i<VALUECOUNT;i++){
			findFirstFigure=true;
			for(j=0;j<continuousCount;j++){
				if(cntFlag[i-j]<cardGroup.type.cnt1){
					findFirstFigure=false;
					break;
				}
			}
			if(findFirstFigure){
				ret.clear();
				int firstFigure=i;
				//cout<<"查找"<<cardGroup.type.cnt1<<"个"<<firstFigure+3<<endl;
				for(k=0,j=0;k<cardsHolded.size() &&j<continuousCount;k++){
					if(cardsHolded[k]->value==firstFigure-j){
						for(int kk=0;j>=0&&kk<cardGroup.type.cnt1;kk++){
							ret.push_back(cardsHolded[k+kk]);
						}
						j++;
					}
				}
				if(cardGroup.type.cnt2>0){
					int SecondFigures[5];
					int SecondCount=continuousCount;
					if(cardGroup.type.typeStr=="四带二")
						SecondCount=2;
					bool findSecondFigure=true;
					for(j=0,k=-1;j<SecondCount &&findSecondFigure;j++){
						findSecondFigure=false;
						for(k++;k<VALUECOUNT;k++){
							SecondFigures[j]=k;
							if(cntFlag[k]>=cardGroup.type.cnt2 &&cntFlag[k]<cardGroup.type.cnt1){
								findSecondFigure=true;
								break;
							}
						}
					}
					if(findSecondFigure){
						//cout<<"查找SecondFigure "<<cardGroup.type.cnt2<<"个"<<SecondFigures[0]+3<<endl;
						//cout<<"SecondCount= "<<SecondCount<<endl;
						//for(i=0;i<SecondCount;i++)cout<<"SecondFigures["<<i<<"]="<<SecondFigures[i]<<endl;
						for(i=0;i<SecondCount;i++){
							for(j=0;j<cardsHolded.size();){
								if(cardsHolded[j]->value==SecondFigures[i]){
									for(k=0;k<cardGroup.type.cnt2;k++){
										//cout<<"添加"<<cardsHolded[j]->value+3<<endl;
										ret.push_back(cardsHolded[j+k]);
									}
									do{
										j++;
									}while(j<cardsHolded.size()&&cardsHolded[j]->value==SecondFigures[i]);
								}else{
									j++;
								}
							}
						}
						return ret;
					}//if(findSecondFigure)
				}//end if(cardGroup.type.cnt2>0)
				else{
					return ret;
				}
			}//end if(findFirstFigure)
		}//end for(i=value+1;i<VALUECOUNT;i++)
		ret.clear();
		//没牌打得过时查找有没有炸dan
		if(typeStr!="炸dan"){
			for(i=cardsHolded.size()-1;i>=3;i--){
				if(cardsHolded[i]->value==cardsHolded[i-3]->value){
					for(j=0;j<4;j++){
						ret.push_back(cardsHolded[i-j]);
					}
					break;
				}
			}
		}
		return ret;  
	}//end vector<Card*> findCanBeatFrom()
};
LastCards* LastCards::lastCards = NULL;

class Player{
public:
	string name;
	vector<Card*> cards;
	void arrange(){
		sort(cards.begin(),cards.end(),cmp);
	}
	void print(){
		cout<<this->name<<":\t";
		for(int i=0;i<cards.size();i++){
			cards[i]->print();
		}
		cout<<"["<<cards.size()<<"]\n";
	}
	vector<Card*> tip(){
		//提示功能,使自己最小一张连最长
		CardGroup ret;
		string temp;
		int j,k,m=cards.size();
		for(j=0;j<m;j++){
			temp="";
			for(k=j;k<m;k++){
				temp+=cards[k]->figure;
			}
			ret.init(temp,cards);
			if(ret.type.typeId!=ERROR){
				return ret.cards;
			}
		}
		ret.cards.clear();
		return ret.cards;
	}
	void chupai(CardGroup &cardGroup){
		//出牌
		cout<<this->name<<":\t";
		cout<<cardGroup.type.typeStr<<' ';
		for(int i=0;i<cardGroup.cards.size();i++){
			cardGroup.cards[i]->print();
			this->cards.erase(find(this->cards.begin(),this->cards.end(),cardGroup.cards[i]));
		}
		cout<<"\t["<<this->cards.size()<<"]\n";
		if(cardGroup.type.typeStr!="不出"){
			//记录到 LastCards 中
			LastCards::inst()->player=this;
			LastCards::inst()->cardGroup.init(cardGroup.cards);
		}
	}
};

class Landlords{
	Player *player[PLAYERCOUNT];
	bool finished,youWin,landlordWin;
	int landlordIndex;
	Card *cards[CARDSCOUNT];
public:
	Landlords(){
		int i,j,k;
		for(i=0;i<PLAYERCOUNT;i++){
			this->player[i]=new Player();
		}
		//54张牌初始化
		for(k=i=0;i<14;i++){
			if(toFigure[i]==' '){
				continue;
			}
			for(COLOR color=eHEART;color<=eSPADE;color=(COLOR)(color+1)){
				this->cards[k++]=new Card(toFigure[i],color);
			}
		}
		this->cards[k++]=new Card('Y',eSPADE);
		this->cards[k]=new Card('Z',eHEART);
	}
	~Landlords(){
		for(int i=0;i<PLAYERCOUNT;i++){
			delete this->player[i];
		}
		for(int i=0;i<CARDSCOUNT;i++){
			delete this->cards[i];
		}
	}
	void init(){
		player[CURRENTPLAYER]->name="Bice";
		player[1]->name="玩家2";
		player[2]->name="玩家3";
		finished=false;
		youWin=false;
		landlordWin=false;
		//抢地主
		landlordIndex=ERROR;
		while(landlordIndex==ERROR){
			srand((int)time(0));
			shuffle();
			landlordIndex=chooseLandlord();
		}
		cout<<player[landlordIndex]->name<<"\t成为地主\n\n";
		this->add3Cards();
		LastCards::inst()->player=player[landlordIndex];
	}
	void startGame(){
		string inputSrt;
		CardGroup inputCards;
		for(int iTurns=landlordIndex;!finished;iTurns++){
			if(iTurns>=PLAYERCOUNT){
				iTurns=0;
			}
			if(iTurns==CURRENTPLAYER){
				cout<<endl;
				player[iTurns]->print();
				cout<<"输入提示:Z=大王 Y=小王 0=10 输入可无序 :=不出 例如:JKQ0A9\n请出牌:\t";
				do{
					cin>>inputSrt;
					inputCards.init(inputSrt,player[iTurns]->cards);
				}while(check(&inputCards)==false);
			}else{
				if(player[iTurns]==LastCards::inst()->player){
					//若是上次出牌的是自己,启用提示功能
					inputCards.init(player[iTurns]->tip());
				}else{
					//查找能打得过上家的牌
					inputCards.init(LastCards::inst()->findCanBeatFrom(player[iTurns]->cards));
				}
			}
			player[iTurns]->chupai(inputCards);//出牌
			
			if(player[iTurns]->cards.size()==0){
				//玩家手中没牌了,游戏结束
				finished=true;
				landlordWin=iTurns==landlordIndex;
				if(landlordWin){
					youWin=landlordIndex==CURRENTPLAYER;
				}else{
					youWin=landlordIndex!=CURRENTPLAYER;
				}
			}
		}
		cout<<"\n_________________________ "<<(youWin?"You Win!":"You Lose!")<<" _________________________\n\n";
	}
	void add3Cards(){
		cout<<"地主3张牌:\t";
		for(int i=PLAYERCOUNT*17;i<CARDSCOUNT;i++){
			this->cards[i]->print();
			player[landlordIndex]->cards.push_back(cards[i]);
		}
		cout<<endl;
		player[landlordIndex]->arrange();
	}
	int chooseLandlord(){
		cout<<"\n_________________________ 抢地主 _________________________\n\n";
		int first=-1,last,cnt=0,i,j=rand()%PLAYERCOUNT;
		bool decision;
		for(i=0;i<PLAYERCOUNT;i++,j==2?j=0:j++){
			if(j==CURRENTPLAYER){
				decision=makeChoice("是否抢地主?(Y=抢/N=不抢):");
			}else{
				decision=rand()%2;
			}
			if(decision){
				cnt++;
				last=j;
				if(first==-1){
					first=j;
				}
				cout<<this->player[j]->name<<"\t抢地主\n";
			}else{
				cout<<this->player[j]->name<<"\t没有抢\n";
			}
		}
		if(cnt==0){
			cout<<"没人抢,重新发牌\n";
			return ERROR;
		}
		if(cnt==1){
			//第一轮只有一人抢地主
			return first;
		}
		else{
			//最后一次争抢
			if(first==CURRENTPLAYER){
				decision=makeChoice("是否抢地主?(Y=抢/N=不抢):");
			}else{
				decision=rand()%2;
			}
			if(decision){
				cout<<this->player[first]->name<<"\t抢地主\n";
				return first;
			}else{
				cout<<this->player[first]->name<<"\t没有抢\n";
				return last;
			}
		}
	}
	void shuffle(){
		int i,j,k;    
		//洗牌
		for(i=0;i<CARDSCOUNT;i++){
			swap(this->cards[i],this->cards[rand()%CARDSCOUNT]);
		}
		//分牌
		for(k=i=0;i<PLAYERCOUNT;i++){
			this->player[i]->cards.clear();
			for(j=0;j<17;j++){
				this->player[i]->cards.push_back(this->cards[k++]);
			}
			this->player[i]->arrange();//整理
			this->player[i]->print();
		}
	}
	bool check(CardGroup *cardGroup){
		if(cardGroup->type.typeId==ERROR){
			cout<<"出牌错误,重新输入\n";
			return false;
		}else if(cardGroup->type.typeStr=="不出"){
			return true;
		}else if(LastCards::inst()->player!=player[CURRENTPLAYER]&&!cardGroup->isCanBeat(LastCards::inst()->cardGroup)){
			cout<<"打不过,重新输入\n";
			return false;
		}else{
			return true;
		}
	}
};

int main(){
	Landlords *landlords=new Landlords();
	do{
		landlords->init();//发牌、抢地主
		landlords->startGame();//游戏开始
	}while(makeChoice("\n是否继续游戏?(Y=继续/N=结束): "));
	delete landlords;
	return 0;
}

bool makeChoice(string tip){
	cout<<tip;
	string input;
	cin>>input;
	return input=="Y"||input=="y";
}

bool cmp(Card* a,Card* b){
	//比较两张牌大小
	if(a->value==b->value){
		return a->color>b->color;
	}else{
		return a->value>b->value;
	}
}

4.恶魔轮盘赌

#include<windows.h>
#include<bits/stdc++.h>
using namespace std;
int Your=6,Other=6;
string daojuname[]={"放大镜","手铐","小刀","烟","饮料"};
double Yourmoney;
int shi,kong;
int q[10],qlen;//1 实 2 空 
int Rand(int x,int y){
	int A=rand(),B=rand();
	return A*1ll*B%(y-x+1)+x;
}
int T;//ou->you
int daojulen;
int daoju[10];
int daojulen1;
int daoju1[10];
void build_gun(){
	kong=Rand(1,4);
	shi=Rand(1,4);
	qlen=0;
	printf("%d发实弹,%d发空弹\n",shi,kong);
	int a1=kong,a2=shi;
	for(int i=1;i<=kong+shi;i++){
//      Sleep(50);
		int sum=Rand(1,a1+a2);
		if(sum<=a1){
			a1--;
			q[++qlen]=2;
		}else{
			a2--;
			q[++qlen]=1;
		}
	}
	int maxn=min(4,8-daojulen);
	printf("你获得了%d个道具:\n",maxn);
	daojulen+=maxn;
	for(int i=1;i<=maxn;i++){
//      Sleep(50);
		int kkk=Rand(0,4);
		daoju[kkk]++;
		cout<<daojuname[kkk];
		if(i!=maxn){
			printf(",");
		}
	}
	printf("\n");
	maxn=min(4,8-daojulen1);
	printf("恶魔获得了%d个道具:\n",maxn);
	daojulen1+=maxn;
	for(int i=1;i<=maxn;i++){
		int kkk=Rand(0,4);
		daoju1[kkk]++;
		cout<<daojuname[kkk];
		if(i!=maxn){
			printf(",");
		}
	}
	printf("\n");
	system("pause");
	system("cls");
}
void IsOver(){
	if(Your<=0){
		printf("你输了\n");
		system("pause");
		exit(0);
	}
	if(Other<=0){
		printf("你赢了\n你获得了奖金$%.2lf\n",Yourmoney);
		system("pause");
		exit(0);
	}
}
void wait(){
	for(int i=1;i<=3;i++){
		Sleep(500);
		printf(".");
	}
	Sleep(500);
}
int Hurt=1;
int shoukao_you;
void Timeyou(){
	int x;
	while(1){
		printf("你的生命:%d/6\n恶魔生命:%d/6\n",Your,Other);
		printf("剩余实弹数:%d    剩余空弹数:%d\n",shi,kong);
		printf("你现在拥有的道具:\n");
		for(int i=0;i<=4;i++){
			cout<<daojuname[i];
			printf("%d",daoju[i]);
			printf("个");
			if(i!=4){
				printf(",");
			}
		}
		printf("\n");
		printf("恶魔现在拥有的道具:\n");
		for(int i=0;i<=4;i++){
			cout<<daojuname[i];
			printf("%d",daoju1[i]);
			printf("个");
			if(i!=4){
				printf(",");
			}
		}
		printf("\n");
		printf("现在是你的回合\n");
		printf("你要\n1.向恶魔开枪\n2.向自己开枪\n");
		for(int i=0;i<=4;i++){
			printf("%d.使用",i+3);
			cout<<daojuname[i]<<'\n';
		}
		scanf("%d",&x);
		if(1<=x&&x<=7){
			break;
		}
		printf("输入不合法\n");
		Sleep(1145);
		system("cls");
	}
	if(x==1){
		printf("你决定向恶魔开枪");
		T++;
		wait();
		if(q[qlen]==2){
			Yourmoney+=(double)(2000.0*(Hurt*1.0)*(1+(double)(shi)*1.0/(double)(shi+kong)));
			kong--;
			qlen--;
			Hurt=1;
			printf("是空弹\n");
			if(shoukao_you==1){
				shoukao_you=0;
				printf("因为你使用了手铐,所以可以再来一次\n");
				Sleep(500);
				T--;
			}
		}else{
//          printf("((%lf))\n",Yourmoney);
			Yourmoney+=(double)(5000.0*(Hurt*1.0)*(1+(double)(kong)*1.0/(double)(shi+kong)));
//          printf("{{%lf}}\n",Yourmoney);
			shi--;
			qlen--;
			Other-=Hurt;
			Hurt=1;
			printf("是实弹\n");
			Sleep(500);
			IsOver();
			if(shoukao_you==1){
				shoukao_you=0;
				Yourmoney+=1000.0;
				printf("因为你使用了手铐,所以可以再来一次\n");
				Sleep(500);
				T--;
			}
		}
	}else if(x==2){
		printf("你决定向自己开枪");
		wait();
		if(q[qlen]==2){
			Yourmoney+=(double)(2000.0*(Hurt*1.0)*(1+(double)(kong)*1.0/(double)(shi+kong)));
			kong--;
			qlen--;
			Hurt=1;
			printf("是空弹\n");
		}else{
			Yourmoney+=5000.0*(1+(double)(shi)*1.0/(double)(shi+kong));
			T++;
			shi--;
			qlen--;
			Your-=Hurt;
			Hurt=1;
			printf("是实弹\n");
			Sleep(500);
			IsOver();
			if(shoukao_you==1){
				shoukao_you=0;
				printf("因为你使用了手铐,所以可以再来一次\n");
				Sleep(500);
				T--;
			}
		}
	}else if(x==3){//{"放大镜","手铐","小刀","烟","饮料"};
		if(daoju[0]){
			daoju[0]--;
			daojulen--;
			printf("你使用了放大镜\n");
			wait();
			printf("\n你看到了");
			if(q[qlen]==1){
				printf("实弹\n");
				Yourmoney+=2500.0;
			}else{
				printf("空弹\n");
			}
			Sleep(500);
			printf("\n");
		}else{
			printf("你现在没有放大镜\n");
			Sleep(1145);
			system("cls");
		}
	}else if(x==4){
		if(daoju[1]){
			if(!shoukao_you){
				daoju[1]--;
				daojulen--;
				printf("你使用了手铐\n");
				printf("你获得了连开两枪的机会\n");
				shoukao_you=1;
			}else{
				printf("你已经用过手铐了\n");
			}
			Sleep(1145);
			system("cls"); 
		}else{
			printf("你现在没有手铐\n");
			Sleep(1145);
			system("cls");
		}
	}else if(x==5){
		if(daoju[2]){
			if(Hurt==1){
				daoju[2]--;
				daojulen--;
				printf("你使用了小刀\n");
				printf("若下一发为实弹则伤害+1\n");
				Yourmoney+=500.0;
				Hurt=2;
			}else{
				printf("你已经用过小刀了\n");
			}
			Sleep(1145);
			system("cls");
		}else{
			printf("你现在没有小刀\n");
			Sleep(1145);
			system("cls");
		}
	}else if(x==6){
		if(daoju[3]){
			if(Your^6){
				daoju[3]--;
				daojulen--;
				printf("你使用了烟\n");
				printf("你回复了一点生命\n");
				Yourmoney+=500.0;
				Your++;
			}else{
				printf("你现在不需要烟\n");
			}
			Sleep(1145);
		}else{
			printf("你现在没有烟\n");
			Sleep(1145);
			system("cls");
		}
	}else{
		if(daoju[4]){
			daoju[4]--;
			daojulen--;
			printf("你使用了饮料\n");
			wait();
			printf("\n");
			printf("你退了一发"); 
			if(q[qlen]==2){
				printf("空弹");
				kong--;
			}else{
				printf("实弹");
				Yourmoney+=500.0;
				shi--;
			}
			qlen--;
			Sleep(500);
		}else{
			printf("你现在没有饮料\n");
			Sleep(1145);
			system("cls");
		}
	}
	Sleep(1000);
	system("cls");
}
int Know;//通过放大镜得知下一发子弹 
int shoukaoemo;
void fightyou(){
	printf("恶魔决定向你开枪");
	T++;
	wait();
	if(q[qlen]==2){
		Yourmoney+=(double)(2000.0*(Hurt*1.0)*(1+(double)(kong)*1.0/(double)(shi+kong)));
		kong--;
		qlen--;
		Hurt=1;
		Know=0;
		printf("是空弹\n");
		if(shoukaoemo){
			printf("因为恶魔使用了手铐,所以可以再来一次\n");
			T--;
			Sleep(500);
			shoukaoemo=0;
		}
	}else{
		Yourmoney+=(double)(5000.0*(Hurt*1.0)*(1+(double)(kong)*1.0/(double)(shi+kong)));
		shi--;
		qlen--;
		Your-=Hurt;
		Hurt=1;
		printf("是实弹\n");
		Know=0;
		Sleep(500);
		IsOver();
		if(shoukaoemo){
			printf("因为恶魔使用了手铐,所以可以再来一次\n");
			Yourmoney+=1000.0;
			T--;
			Sleep(500);
			shoukaoemo=0;
		}
	}
}
void fightemo(){
	printf("恶魔决定向自己开枪");
	wait();
	if(q[qlen]==2){
		Yourmoney+=2000.0*(1+(double)(shi)*1.0/(double)(shi+kong));
		kong--;
		qlen--;
		printf("是空弹\n");
		Know=0;
	}else{
		Yourmoney+=5000.0*(1+(double)(kong)*1.0/(double)(shi+kong));
		shi--;
		T++;
		qlen--;
		Other-=Hurt;
		Hurt=1;
		printf("是实弹\n");
		Know=0;
		Sleep(500);
		IsOver();
		if(shoukaoemo){
			printf("因为恶魔使用了手铐,所以可以再来一次\n");
			T--;
			Sleep(500);
			shoukaoemo=0;
		}
	}
}
void Timeother(){
	printf("你的生命:%d/6\n恶魔生命:%d/6\n",Your,Other);
	printf("剩余实弹数:%d    剩余空弹数:%d\n",shi,kong);
	printf("你现在拥有的道具:\n");
	for(int i=0;i<=4;i++){
		cout<<daojuname[i];
		printf("%d",daoju[i]);
		printf("个");
		if(i!=4){
			printf(",");
		}
	}
	printf("\n");
	printf("恶魔现在拥有的道具:\n");
	for(int i=0;i<=4;i++){
		cout<<daojuname[i];
		printf("%d",daoju1[i]);
		printf("个");
		if(i!=4){
			printf(",");
		}
	}
	printf("\n");
	printf("现在是恶魔的回合\n");
	Sleep(1500);
	
	if(Other!=6){
		if(daoju1[3]){
			daoju1[3]--;
			daojulen1--;
			printf("恶魔使用了烟\n");
			printf("恶魔回复了一点生命\n");
			Other++;
			Yourmoney+=500.0;
			Sleep(1145);
			system("cls");
			return ;
		}
	}
	if(Know==0&&kong==0){
		Know=1;
	}
	if(Know==0){
		if(abs(shi-kong)<2&&kong!=0){
			if(daoju1[0]){
				daoju1[0]--;
				daojulen1--;
				printf("恶魔使用了放大镜\n");
				wait();
				printf("\n恶魔看到了");
				if(q[qlen]==1){
					printf("实弹");
					Yourmoney+=2500.0;
					Know=1;
				}else{
					printf("空弹");
					Know=2;
				}
				Sleep(1145);
				system("cls");
				return ;
			}
		}
	}else if(Know==1){
		if(Hurt==1&&daoju1[2]){
			daoju1[2]--;
			daojulen1--;
			Hurt++;
			printf("恶魔使用了小刀\n");
			printf("若下一发为实弹则伤害+1");
			Yourmoney+=500.0;
			Sleep(1145);
			system("cls");
			return ;
		}else{
			if(shi>=kong+1&&daoju1[1]&&shoukaoemo!=1){
				daoju1[1]--;
				daojulen1--;
				shoukaoemo=1;
				printf("恶魔使用了手铐\n");
				printf("恶魔获得了连开两枪的机会\n");
				Sleep(1145);
				system("cls");
				return ;
			}
			fightyou();
			system("cls");
			return ;
		}
	}else{
		if(daoju1[4]){
			daoju1[4]--;
			daojulen1--;
			printf("恶魔使用了饮料\n");
			wait();
			printf("\n");
			printf("恶魔退了一发"); 
			if(q[qlen]==2){
				printf("空弹");
				kong--;
			}else{
				printf("实弹");
				shi--;
			}
			Know=0;
			qlen--;
			Sleep(500);
			Sleep(1145);
			system("cls");
			return ;
		}else{
			fightemo();
			Sleep(1145);
			system("cls");
			return ;
		}
	}
	if(shi>=kong){
		fightyou();
	}else{
		fightemo();
	}
	Sleep(1145);
	system("cls");
}
void Play(){
	while(1){
		if(shi==0){
			build_gun();
			T=0;
			continue;
		}
		if(T%2==0){
			Timeyou();
		}else{
			Timeother();
		}
	}
}
void danrenplay(){
	for(int i=1;i<=3;i++){
		printf(".");
//      Sleep(1000);
	}
	printf("\n");
	printf("又来了一位挑战者...\n");
	Sleep(1000);
	int x;
	while(1){
		printf("准备好参与恶魔的游戏吗?胜者带走奖金,败者将会在此长眠\n1.好的\n2.没问题\n");
		scanf("%d",&x);
		if(x==1||x==2){
			break;
		}
		printf("输入不合法\n");
		Sleep(1145);
		system("cls");
	}
	while(1){
		printf("你清楚我们的规则吗?\n1.清楚\n2.不清楚\n");
		scanf("%d",&x);
		if(x==1||x==2){
			break;
		}
		printf("输入不合法\n");
		Sleep(1145);
		system("cls");
	}
	if(x==1){
		
	}else{
		for(int i=1;i<=3;i++){
			printf(".");
			Sleep(1000);
		}
		printf("\n");
		printf("规则:\n");
		printf("你和恶魔都各有6点生命\n") ;
		printf("每一回合开始前,你将知道一共有几发实弹,几发空弹,同时双方都将获得4个道具作为补给(上限为8个)\n"); 
		printf("每一回合,你可以选择对自己开枪,对恶魔开枪或者使用道具\n");
		printf("如果你对自己开枪,若为空弹,则可以继续行动,否则,停止行动\n");
		printf("如果你对恶魔开枪,无论如何,都将停止行动\n");
		printf("道具一览:\n"); 
		printf("放大镜:可以知道下一发子弹是空弹还是实弹\n");
		printf("手铐:增加一次本回合的行动次数\n");
		printf("小刀:若下一发子弹为实弹,则伤害+1\n");
		printf("烟:可以回复1点体力\n");
		printf("饮料:可以退一发子弹\n");
		system("pause");
		system("cls");
	}
	
	printf("好吧\n");
	Sleep(1145);
	printf("游戏将要开始了哦\n");
	Sleep(1145);
	system("cls");
	Play();
}
void IsOver_duo(){
	if(Your<=0){
		printf("玩家B赢了\n玩家B获得了奖金$%.2lf\n",Yourmoney); 
		system("pause");
		exit(0);
	}else if(Other<=0){
		printf("玩家A赢了\n玩家A获得了奖金$%.2lf\n",Yourmoney); 
		system("pause");
		exit(0);
	}
	
}
void build_gun_duo(){
	kong=Rand(1,4);
	shi=Rand(1,4);
	qlen=0;
	printf("%d发实弹,%d发空弹\n",shi,kong);
	int a1=kong,a2=shi;
	for(int i=1;i<=kong+shi;i++){
//      Sleep(50);
		int sum=Rand(1,a1+a2);
		if(sum<=a1){
			a1--;
			q[++qlen]=2;
		}else{
			a2--;
			q[++qlen]=1;
		}
	}
	int maxn=min(2,8-daojulen);
	printf("玩家A获得了%d个道具:\n",maxn);
	daojulen+=maxn;
	for(int i=1;i<=maxn;i++){
//      Sleep(50);
		int kkk=Rand(0,4);
		daoju[kkk]++;
		cout<<daojuname[kkk];
		if(i!=maxn){
			printf(",");
		}
	}
	printf("\n");
	maxn=min(2,8-daojulen1);
	printf("玩家B获得了%d个道具:\n",maxn);
	daojulen1+=maxn;
	for(int i=1;i<=maxn;i++){
		int kkk=Rand(0,4);
		daoju1[kkk]++;
		cout<<daojuname[kkk];
		if(i!=maxn){
			printf(",");
		}
	}
	printf("\n");
	system("pause");
	system("cls");
}
void Timeyou_duo(){
	int x;
	while(1){
		printf("玩家A的生命:%d/4\n玩家B的生命:%d/4\n",Your,Other);
		printf("剩余实弹数:%d    剩余空弹数:%d\n",shi,kong);
		printf("玩家A现在拥有的道具:\n");
		for(int i=0;i<=4;i++){
			cout<<daojuname[i];
			printf("%d",daoju[i]);
			printf("个");
			if(i!=4){
				printf(",");
			}
		}
		printf("\n");
		printf("玩家B现在拥有的道具:\n");
		for(int i=0;i<=4;i++){
			cout<<daojuname[i];
			printf("%d",daoju1[i]);
			printf("个");
			if(i!=4){
				printf(",");
			}
		}
		printf("\n");
		printf("现在是玩家A的回合\n");
		printf("玩家A要\n1.向玩家B开枪\n2.向自己开枪\n");
		for(int i=0;i<=4;i++){
			printf("%d.使用",i+3);
			cout<<daojuname[i]<<'\n';
		}
		scanf("%d",&x);
		if(1<=x&&x<=7){
			break;
		}
		printf("输入不合法\n");
		Sleep(1145);
		system("cls");
	}
	if(x==1){
		printf("玩家A决定向玩家B开枪");
		T++;
		wait();
		if(q[qlen]==2){
			Yourmoney+=(double)(2000.0*(Hurt*1.0)*(1+(double)(shi)*1.0/(double)(shi+kong)));
			kong--;
			qlen--;
			Hurt=1;
			printf("是空弹\n");
			if(shoukao_you==1){
				shoukao_you=0;
				printf("因为玩家A使用了手铐,所以可以再来一次\n");
				Sleep(500);
				T--;
			}
		}else{
//          printf("((%lf))\n",Yourmoney);
			Yourmoney+=(double)(5000.0*(Hurt*1.0)*(1+(double)(kong)*1.0/(double)(shi+kong)));
//          printf("{{%lf}}\n",Yourmoney);
			shi--;
			qlen--;
			Other-=Hurt;
			Hurt=1;
			printf("是实弹\n");
			Sleep(500);
			IsOver_duo();
			if(shoukao_you==1){
				shoukao_you=0;
				Yourmoney+=1000.0;
				printf("因为玩家A使用了手铐,所以可以再来一次\n");
				Sleep(500);
				T--;
			}
		}
	}else if(x==2){
		printf("玩家A决定向自己开枪");
		wait();
		if(q[qlen]==2){
			Yourmoney+=(double)(2000.0*(Hurt*1.0)*(1+(double)(kong)*1.0/(double)(shi+kong)));
			kong--;
			qlen--;
			Hurt=1;
			printf("是空弹\n");
		}else{
			Yourmoney+=5000.0*(1+(double)(shi)*1.0/(double)(shi+kong));
			T++;
			shi--;
			qlen--;
			Your-=Hurt;
			Hurt=1;
			printf("是实弹\n");
			Sleep(500);
			IsOver_duo();
			if(shoukao_you==1){
				shoukao_you=0;
				printf("因为玩家A使用了手铐,所以可以再来一次\n");
				Sleep(500);
				T--;
			}
		}
	}else if(x==3){//{"放大镜","手铐","小刀","烟","饮料"};
		if(daoju[0]){
			daoju[0]--;
			daojulen--;
			printf("玩家A使用了放大镜\n");
			wait();
			printf("\n玩家A看到了");
			if(q[qlen]==1){
				printf("实弹\n");
				Yourmoney+=2500.0;
			}else{
				printf("空弹\n");
			}
			Sleep(500);
			printf("\n");
		}else{
			printf("玩家A现在没有放大镜\n");
			Sleep(1145);
			system("cls");
		}
	}else if(x==4){
		if(daoju[1]){
			if(!shoukao_you){
				daoju[1]--;
				daojulen--;
				printf("玩家A使用了手铐\n");
				printf("玩家A获得了连开两枪的机会\n");
				shoukao_you=1;
			}else{
				printf("玩家A已经用过手铐了\n");
			}
			Sleep(1145);
			system("cls"); 
		}else{
			printf("玩家A现在没有手铐\n");
			Sleep(1145);
			system("cls");
		}
	}else if(x==5){
		if(daoju[2]){
			if(Hurt==1){
				daoju[2]--;
				daojulen--;
				printf("玩家A使用了小刀\n");
				printf("若下一发为实弹则伤害+1\n");
				Yourmoney+=500.0;
				Hurt=2;
			}else{
				printf("玩家A已经用过小刀了\n");
			}
			Sleep(1145);
			system("cls");
		}else{
			printf("玩家A现在没有小刀\n");
			Sleep(1145);
			system("cls");
		}
	}else if(x==6){
		if(daoju[3]){
			if(Your^4){
				daoju[3]--;
				daojulen--;
				printf("玩家A使用了烟\n");
				printf("玩家A回复了一点生命\n");
				Yourmoney+=500.0;
				Your++;
			}else{
				printf("玩家A现在不需要烟\n");
			}
			Sleep(1145);
		}else{
			printf("玩家A现在没有烟\n");
			Sleep(1145);
			system("cls");
		}
	}else{
		if(daoju[4]){
			daoju[4]--;
			daojulen--;
			printf("玩家A使用了饮料\n");
			wait();
			printf("\n");
			printf("玩家A退了一发"); 
			if(q[qlen]==2){
				printf("空弹");
				kong--;
			}else{
				printf("实弹");
				Yourmoney+=500.0;
				shi--;
			}
			qlen--;
			Sleep(500);
		}else{
			printf("玩家A现在没有饮料\n");
			Sleep(1145);
			system("cls");
		}
	}
	Sleep(1000);
	system("cls");
}
void Timeother_duo(){
	int x;
	while(1){
		printf("玩家A的生命:%d/4\n玩家B的生命:%d/4\n",Your,Other);
		printf("剩余实弹数:%d    剩余空弹数:%d\n",shi,kong);
		printf("玩家A现在拥有的道具:\n");
		for(int i=0;i<=4;i++){
			cout<<daojuname[i];
			printf("%d",daoju[i]);
			printf("个");
			if(i!=4){
				printf(",");
			}
		}
		printf("\n");
		printf("玩家B现在拥有的道具:\n");
		for(int i=0;i<=4;i++){
			cout<<daojuname[i];
			printf("%d",daoju1[i]);
			printf("个");
			if(i!=4){
				printf(",");
			}
		}
		printf("\n");
		printf("现在是玩家B的回合\n");
		printf("玩家B要\n1.向玩家A开枪\n2.向自己开枪\n");
		for(int i=0;i<=4;i++){
			printf("%d.使用",i+3);
			cout<<daojuname[i]<<'\n';
		}
		scanf("%d",&x);
		if(1<=x&&x<=7){
			break;
		}
		printf("输入不合法\n");
		Sleep(1145);
		system("cls");
	}
	if(x==1){
		printf("玩家B决定向玩家A开枪");
		T++;
		wait();
		if(q[qlen]==2){
			Yourmoney+=(double)(2000.0*(Hurt*1.0)*(1+(double)(shi)*1.0/(double)(shi+kong)));
			kong--;
			qlen--;
			Hurt=1;
			printf("是空弹\n");
			if(shoukaoemo==1){
				shoukaoemo=0;
				printf("因为玩家B使用了手铐,所以可以再来一次\n");
				Sleep(500);
				T--;
			}
		}else{
//          printf("((%lf))\n",Yourmoney);
			Yourmoney+=(double)(5000.0*(Hurt*1.0)*(1+(double)(kong)*1.0/(double)(shi+kong)));
//          printf("{{%lf}}\n",Yourmoney);
			shi--;
			qlen--;
			Your-=Hurt;
			Hurt=1;
			printf("是实弹\n");
			Sleep(500);
			IsOver_duo();
			if(shoukaoemo==1){
				shoukaoemo=0;
				Yourmoney+=1000.0;
				printf("因为玩家B使用了手铐,所以可以再来一次\n");
				Sleep(500);
				T--;
			}
		}
	}else if(x==2){
		printf("玩家B决定向自己开枪");
		wait();
		if(q[qlen]==2){
			Yourmoney+=(double)(2000.0*(Hurt*1.0)*(1+(double)(kong)*1.0/(double)(shi+kong)));
			kong--;
			qlen--;
			Hurt=1;
			printf("是空弹\n");
		}else{
			Yourmoney+=5000.0*(1+(double)(shi)*1.0/(double)(shi+kong));
			T++;
			shi--;
			qlen--;
			Other-=Hurt;
			Hurt=1;
			printf("是实弹\n");
			Sleep(500);
			IsOver_duo();
			if(shoukao_you==1){
				shoukao_you=0;
				printf("因为玩家B使用了手铐,所以可以再来一次\n");
				Sleep(500);
				T--;
			}
		}
	}else if(x==3){//{"放大镜","手铐","小刀","烟","饮料"};
		if(daoju1[0]){
			daoju1[0]--;
			daojulen1--;
			printf("玩家B使用了放大镜\n");
			wait();
			printf("\n玩家B看到了");
			if(q[qlen]==1){
				printf("实弹\n");
				Yourmoney+=2500.0;
			}else{
				printf("空弹\n");
			}
			Sleep(500);
			printf("\n");
		}else{
			printf("玩家B现在没有放大镜\n");
			Sleep(1145);
			system("cls");
		}
	}else if(x==4){
		if(daoju1[1]){
			if(!shoukaoemo){
				daoju1[1]--;
				daojulen1--;
				printf("玩家B使用了手铐\n");
				printf("玩家B获得了连开两枪的机会\n");
				shoukaoemo=1;
			}else{
				printf("玩家B已经用过手铐了\n");
			}
			Sleep(1145);
			system("cls"); 
		}else{
			printf("玩家B现在没有手铐\n");
			Sleep(1145);
			system("cls");
		}
	}else if(x==5){
		if(daoju1[2]){
			if(Hurt==1){
				daoju1[2]--;
				daojulen1--;
				printf("玩家B使用了小刀\n");
				printf("若下一发为实弹则伤害+1\n");
				Yourmoney+=500.0;
				Hurt=2;
			}else{
				printf("玩家B已经用过小刀了\n");
			}
			Sleep(1145);
			system("cls");
		}else{
			printf("玩家B现在没有小刀\n");
			Sleep(1145);
			system("cls");
		}
	}else if(x==6){
		if(daoju1[3]){
			if(Other^4){
				daoju1[3]--;
				daojulen1--;
				printf("玩家B使用了烟\n");
				printf("玩家B回复了一点生命\n");
				Yourmoney+=500.0;
				Other++;
			}else{
				printf("玩家B现在不需要烟\n");
			}
			Sleep(1145);
		}else{
			printf("玩家B现在没有烟\n");
			Sleep(1145);
			system("cls");
		}
	}else{
		if(daoju1[4]){
			daoju1[4]--;
			daojulen1--;
			printf("玩家B使用了饮料\n");
			wait();
			printf("\n");
			printf("玩家B退了一发"); 
			if(q[qlen]==2){
				printf("空弹");
				kong--;
			}else{
				printf("实弹");
				Yourmoney+=500.0;
				shi--;
			}
			qlen--;
			Sleep(500);
		}else{
			printf("玩家B现在没有饮料\n");
			Sleep(1145);
			system("cls");
		}
	}
	Sleep(1000);
	system("cls");
}
int asdasd;
void duorenplay(){
	while(1){
		if(shi==0){
			build_gun_duo();
			T=asdasd;
			asdasd++;
			continue;
		}
		if(T%2==0){
			Timeyou_duo();
		}else{
			Timeother_duo();
		}
	}
}
int main(){
	srand(time(0));
	int x;
	while(1){
		printf("请选择你想要的模式:\n1.单人\n2.双人(此模式中,生命值为4,道具补给为2)\n");
		scanf("%d",&x);
		if(x==1||x==2){
			break;
		}
		printf("输入不合法\n");
		Sleep(1145);
		system("cls");
	}
	system("cls");
	if(x==1){
		danrenplay();
	}else{
		Your=Other=4;
		duorenplay();
	}
	return 0;
}

5.俄罗斯方块

#include <iostream>
#include <string>
#include <ctime>
#include <cstdlib>
#include <windows.h>
#include <conio.h>

using namespace std;

int block00[4][4] = { { 10, 0, 0, 0 }, { 1, 1, 1, 1 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 } };
int block01[4][4] = { { 11, 0, 1, 0 }, { 0, 0, 1, 0 }, { 0, 0, 1, 0 }, { 0, 0, 1, 0 } };
int block02[4][4] = { { 12, 0, 0, 0 }, { 0, 0, 0, 0 }, { 1, 1, 1, 0 }, { 0, 1, 0, 0 } };
int block03[4][4] = { { 13, 0, 0, 0 }, { 0, 1, 0, 0 }, { 1, 1, 0, 0 }, { 0, 1, 0, 0 } };
int block04[4][4] = { { 14, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 1, 0, 0 }, { 1, 1, 1, 0 } };
int block05[4][4] = { { 15, 0, 0, 0 }, { 0, 1, 0, 0 }, { 0, 1, 1, 0 }, { 0, 1, 0, 0 } };
int block06[4][4] = { { 16, 0, 0, 0 }, { 0, 0, 0, 0 }, { 1, 1, 1, 0 }, { 1, 0, 0, 0 } };
int block07[4][4] = { { 17, 0, 0, 0 }, { 1, 1, 0, 0 }, { 0, 1, 0, 0 }, { 0, 1, 0, 0 } };
int block08[4][4] = { { 18, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 1, 0 }, { 1, 1, 1, 0 } };
int block09[4][4] = { { 19, 0, 0, 0 }, { 0, 1, 0, 0 }, { 0, 1, 0, 0 }, { 0, 1, 1, 0 } };
int block10[4][4] = { { 20, 0, 0, 0 }, { 0, 0, 0, 0 }, { 1, 1, 1, 0 }, { 0, 0, 1, 0 } };
int block11[4][4] = { { 21, 0, 0, 0 }, { 0, 1, 0, 0 }, { 0, 1, 0, 0 }, { 1, 1, 0, 0 } };
int block12[4][4] = { { 22, 0, 0, 0 }, { 0, 0, 0, 0 }, { 1, 0, 0, 0 }, { 1, 1, 1, 0 } };
int block13[4][4] = { { 23, 0, 0, 0 }, { 0, 1, 1, 0 }, { 0, 1, 0, 0 }, { 0, 1, 0, 0 } };
int block14[4][4] = { { 24, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 1, 1, 0 }, { 1, 1, 0, 0 } };
int block15[4][4] = { { 25, 0, 0, 0 }, { 1, 0, 0, 0 }, { 1, 1, 0, 0 }, { 0, 1, 0, 0 } };
int block16[4][4] = { { 26, 0, 0, 0 }, { 0, 0, 0, 0 }, { 1, 1, 0, 0 }, { 0, 1, 1, 0 } };
int block17[4][4] = { { 27, 0, 0, 0 }, { 0, 0, 1, 0 }, { 0, 1, 1, 0 }, { 0, 1, 0, 0 } };
int block18[4][4] = { { 28, 0, 0, 0 }, { 0, 0, 0, 0 }, { 1, 1, 0, 0 }, { 1, 1, 0, 0 } };
void initialWindow (HANDLE hOut);//初始化窗口
void initialPrint (HANDLE hOut);//初始化界面
void gotoXY (HANDLE hOut, int x, int y);//移动光标
void roundBlock (HANDLE hOut, int block[4][4]);//随机生成方块并打印到下一个方块位置
bool collisionDetection (int block[4][4], int map[21][12], int x, int y);//检测碰撞
void printBlock (HANDLE hOut, int block[4][4], int x, int y);//打印方块
void clearBlock (HANDLE hOut, int block[4][4], int x, int y);//消除方块
void myLeft (HANDLE hOut, int block[4][4], int map[21][12], int x, int &y);//左移
void myRight (HANDLE hOut, int block[4][4], int map[21][12], int x, int &y);//右移
void myUp (HANDLE hOut, int block[4][4], int map[21][12], int x, int &y);//顺时针旋转90度
int myDown (HANDLE hOut, int block[4][4], int map[21][12], int &x, int y);//加速下落
void myStop (HANDLE hOut, int block[4][4]);//游戏暂停
void gameOver (HANDLE hOut, int block[4][4], int map[21][12]);//游戏结束
//判断是否能消行并更新分值
void eliminateRow (HANDLE hOut, int map[21][12], int &val, int &fraction, int &checkpoint);
int main () {
    MessageBox (NULL, "欢迎来到俄罗斯方块游戏!", "温馨提示", MB_OK);
    system ("mode coon cols=200 lines=100");
    system ("mode con cols=70 lines=35");
    int map[21][12];
    int blockA[4][4];//候选区的方块
    int blockB[4][4];//下落中的方块
    int positionX, positionY;//方块左上角的坐标
    bool check;//检查方块还能不能下落
    char key;//用来存储按键
    int val;//用来控制下落速度
    int fraction;//用来存储得分
    int checkpoint;//用来存储关卡
    int times;
    HANDLE hOut = GetStdHandle (STD_OUTPUT_HANDLE);//获取标准输出设备句柄
    initialWindow (hOut);
initial:
    gotoXY (hOut, 0, 0);
    initialPrint (hOut);
    check = true;
    val = 50;
    fraction = 0;
    checkpoint = 1;
    times = val;
    for (int i = 0; i < 20; i++) {
        for (int j = 1; j < 11; j++) {
            map[i][j] = 0;
        }
    }
    for (int i = 0; i < 20; i++) {
        map[i][0] = map[i][11] = 1;
    }
    for (int i = 0; i < 12; i++) {
        map[20][i] = 1;
    }
    srand ((unsigned) time (NULL));
    roundBlock (hOut, blockA);
    while (true) {
        if (check) {
            eliminateRow (hOut, map, val, fraction, checkpoint);
            check = false;
            positionX = -3;
            positionY = 4;
            if (collisionDetection (blockA, map, positionX, positionY)) {
                for (int i = 0; i < 4; i++) {
                    for (int j = 0; j < 4; j++) {
                        blockB[i][j] = blockA[i][j];
                    }
                }
                roundBlock (hOut, blockA);
            } else {
                gameOver (hOut, blockA, map);
                goto initial;
            }
        }
        printBlock (hOut, blockB, positionX, positionY);
        if (_kbhit ()) {
            key = _getch ();
            switch (key) {
                case 72:
                    myUp (hOut, blockB, map, positionX, positionY);
                    break;
                case 75:
                    myLeft (hOut, blockB, map, positionX, positionY);
                    break;
                case 77:
                    myRight (hOut, blockB, map, positionX, positionY);
                    break;
                case 80:
                    switch (myDown (hOut, blockB, map, positionX, positionY)) {
                        case 0:
                            check = false;
                            break;
                        case 1:
                            check = true;
                            break;
                        case 2:
                            gameOver (hOut, blockB, map);
                            goto initial;
                        default:
                            break;
                    }
                    break;
                case 32:
                    myStop (hOut, blockA);
                    break;
                case 27:
                    exit (0);
                default:
                    break;
            }
        }
        Sleep (20);
        if (--times == 0) {
            switch (myDown (hOut, blockB, map, positionX, positionY)) {
                case 0:
                    check = false;
                    break;
                case 1:
                    check = true;
                    break;
                case 2:
                    gameOver (hOut, blockB, map);
                    goto initial;
                default:
                    break;
            }
            times = val;
        }
    }
    cin.get ();
    return 0;
}

void initialWindow (HANDLE hOut) {
    SetConsoleTitle ("俄罗斯方块");
    COORD size = { 80, 25 };
    SetConsoleScreenBufferSize (hOut, size);
    SMALL_RECT rc = { 0, 0, 79, 24 };
    SetConsoleWindowInfo (hOut, true, &rc);
    CONSOLE_CURSOR_INFO cursor_info = { 1, 0 };
    SetConsoleCursorInfo (hOut, &cursor_info);
}

void initialPrint(HANDLE hOut) {
    SetConsoleTextAttribute (hOut, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
    for (int i = 0; i < 20; i++) {
        cout << "■                    ■☆                      ☆" << endl;
    }
    gotoXY (hOut, 26, 0);
    cout << "☆☆☆☆☆☆☆☆☆☆☆";
    gotoXY (hOut, 0, 20);
    cout << "■■■■■■■■■■■■☆☆☆☆☆☆☆☆☆☆☆☆☆";
    gotoXY (hOut, 26, 1);
    cout << "分    数:      ";
    gotoXY (hOut, 26, 2);
    cout << "关    卡:      ";
    gotoXY (hOut, 26, 4);
    cout << "下一方块:";
    gotoXY (hOut, 26, 9);
    cout << "操作方法:";
    gotoXY (hOut, 30, 11);
    cout << "↑:旋转 ↓:速降";
    gotoXY (hOut, 30, 12);
    cout << "→:右移 ←:左移";
    gotoXY (hOut, 30, 13);
    cout << "空格键:开始/暂停";
    gotoXY (hOut, 30, 14);
    cout << "Esc 键:退出";
    gotoXY (hOut, 26, 16);
    cout << "关    于:";
    gotoXY (hOut, 30, 18);
    cout << "俄罗斯方块V1.0";
    gotoXY (hOut, 35, 19);
}
void gotoXY (HANDLE hOut, int x, int y) {
    COORD pos;
    pos.X = x;
    pos.Y = y;
    SetConsoleCursorPosition (hOut, pos);
}
void roundBlock(HANDLE hOut, int block[4][4]) {
    clearBlock (hOut, block, 5, 15);
    switch (rand() % 19) {
        case 0:
            for (int i = 0; i < 4; i++) {
                for (int j = 0; j < 4; j++) {
                    block[i][j] = block00[i][j];
                }
            }
            break;
        case 1:
            for (int i = 0; i < 4; i++) {
                for (int j = 0; j < 4; j++) {
                    block[i][j] = block01[i][j];
                }
            }
            break;
        case 2:
            for (int i = 0; i < 4; i++) {
                for (int j = 0; j < 4; j++) {
                    block[i][j] = block02[i][j];
                }
            }
            break;
        case 3:
            for (int i = 0; i < 4; i++) {
                for (int j = 0; j < 4; j++) {
                    block[i][j] = block03[i][j];
                }
            }
            break;
        case 4:
            for (int i = 0; i < 4; i++) {
                for (int j = 0; j < 4; j++) {
                    block[i][j] = block04[i][j];
                }
            }
            break;
        case 5:
            for (int i = 0; i < 4; i++) {
                for (int j = 0; j < 4; j++) {
                    block[i][j] = block05[i][j];
                }
            }
            break;
        case 6:
            for (int i = 0; i < 4; i++) {
                for (int j = 0; j < 4; j++) {
                    block[i][j] = block06[i][j];
                }
            }
            break;
        case 7:
            for (int i = 0; i < 4; i++) {
                for (int j = 0; j < 4; j++) {
                block[i][j] = block07[i][j];
            }
        }
        break;
        case 8:
            for (int i = 0; i < 4; i++) {
                for (int j = 0; j < 4; j++) {
                    block[i][j] = block08[i][j];
                }
            }
            break;
        case 9:
            for (int i = 0; i < 4; i++) {
                for (int j = 0; j < 4; j++)
                {
                    block[i][j] = block09[i][j];
                }
            }
            break;
        case 10:
            for (int i = 0; i < 4; i++) {
                for (int j = 0; j < 4; j++) {
                    block[i][j] = block10[i][j];
                }
            }
            break;
        case 11:
            for (int i = 0; i < 4; i++) {
                for (int j = 0; j < 4; j++) {
                    block[i][j] = block11[i][j];
                }
            }
            break;
        case 12:
            for (int i = 0; i < 4; i++) {
                for (int j = 0; j < 4; j++) {
                    block[i][j] = block12[i][j];
                }
            }
            break;
        case 13:
            for (int i = 0; i < 4; i++) {
                for (int j = 0; j < 4; j++) {
                    block[i][j] = block13[i][j];
                }
            }
            break;
        case 14:
            for (int i = 0; i < 4; i++) {
                for (int j = 0; j < 4; j++) {
                    block[i][j] = block14[i][j];
                }
            }
            break;
        case 15:
            for (int i = 0; i < 4; i++) {
                for (int j = 0; j < 4; j++) {
                    block[i][j] = block15[i][j];
                }
            }
            break;
        case 16:
            for (int i = 0; i < 4; i++) {
                for (int j = 0; j < 4; j++) {
                    block[i][j] = block16[i][j];
                }
            }
            break;
        case 17:
            for (int i = 0; i < 4; i++) {
                for (int j = 0; j < 4; j++) {
                    block[i][j] = block17[i][j];
                }
            }
            break;
        case 18:
            for (int i = 0; i < 4; i++) {
                for (int j = 0; j < 4; j++) {
                    block[i][j] = block18[i][j];
                }
            }
            break;
        default:
            break;
    }
    printBlock(hOut, block, 5, 15);
}
bool collisionDetection (int block[4][4], int map[21][12], int x, int y) {
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 4; j++) {
            if (x + i >= 0 && y + j >= 0 && map[x + i][y + j] == 1 && block[i][j] == 1) {
                return false;
            }
        }
    }
    return true;
}
void printBlock (HANDLE hOut, int block[4][4], int x, int y) {
    switch (block[0][0]) {
        case 10:
        case 11:
            SetConsoleTextAttribute (hOut, FOREGROUND_GREEN);
            break;
        case 12:
        case 13:
        case 14:
        case 15:
            SetConsoleTextAttribute (hOut, FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
            break;
        case 16:
        case 17:
        case 18:
        case 19:
            SetConsoleTextAttribute (hOut, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
            break;
        case 20:
        case 21:
        case 22:
        case 23:
            SetConsoleTextAttribute (hOut, FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
            break;
        case 24:
        case 25:
            SetConsoleTextAttribute (hOut, FOREGROUND_GREEN | FOREGROUND_INTENSITY);
            break;
        case 26:
        case 27:
            SetConsoleTextAttribute (hOut, FOREGROUND_BLUE | FOREGROUND_INTENSITY);
            break;
        case 28:
            SetConsoleTextAttribute (hOut, FOREGROUND_RED | FOREGROUND_INTENSITY);
            break;
        default:
            break;
    }
    for (int i = 0; i < 4; i++) {
        if (i + x >= 0) {
            for (int j = 0; j < 4; j++) {
                if (block[i][j] == 1) {
                    gotoXY (hOut, 2 * (y + j), x + i);
                    cout << "■";
                }
            }
        }
    }
}
void clearBlock (HANDLE hOut, int block[4][4], int x, int y) {
    for (int i = 0; i < 4; i++) {
        if (i + x >= 0) {
            for (int j = 0; j < 4; j++) {
                if (block[i][j] == 1) {
                    gotoXY (hOut, 2 * (y + j), x + i);
                    cout << "  ";
                }
            }
        }
    }
}
void gameOver (HANDLE hOut, int block[4][4], int map[21][12]) {
    SetConsoleTextAttribute (hOut, FOREGROUND_RED | FOREGROUND_INTENSITY);
    gotoXY (hOut, 9, 8);
    string s = "GAME OVER";
    for (int i = 0; i < s.size (); i++) {
        Sleep (80);
        cout << s[i];
    }
    gotoXY (hOut, 8, 9);
    s = "空格键:重来";
    for (int i = 0; i < s.size (); i++) {
        Sleep (80);
        cout << s[i];
    }
    cout << endl;
    gotoXY (hOut, 8, 10);
    s = "ESC键:退出";
    MessageBox (NULL, "很遗憾,您输了!", "温馨提示", MB_OK);
    for (int i = 0; i < s.size (); i++) {
        Sleep (80);
        cout << s[i];
    }
    char key;
    while (true) {
        key = _getch ();
        if (key == 32) {
            return;
        } else if (key == 27) {
            exit(0);
        }
    }
}
int myDown (HANDLE hOut, int block[4][4], int map[21][12], int &x, int y) {
    if (collisionDetection(block, map, x + 1, y)) {
        clearBlock (hOut, block, x, y);
        ++x;
        return 0;
    }
    if (x < 0) {
        return 2;
    }
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 4; j++) {
            if (block[i][j] == 1) {
                map[x + i][y + j] = 1;
                SetConsoleTextAttribute (hOut, FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY);
                gotoXY (hOut, 2 * (y + j), x + i);
                cout << "■";
            }
        }
    }
    return 1;
}
void myLeft (HANDLE hOut, int block[4][4], int map[21][12], int x, int &y) {
    if (collisionDetection (block, map, x, y - 1)) {
        clearBlock (hOut, block, x, y);
        --y;
    }
}
void myRight (HANDLE hOut, int block[4][4], int map[21][12], int x, int &y) {
    if (collisionDetection (block, map, x, y + 1)) {
        clearBlock (hOut, block, x, y);
        ++y;
    }
}
void myUp (HANDLE hOut, int block[4][4], int map[21][12], int x, int &y) {
    switch (block[0][0]) {
        case 10:
            if (collisionDetection (block01, map, x, y)) {
                clearBlock (hOut, block, x, y);
                for (int i = 0; i < 4; i++) {
                    for (int j = 0; j < 4; j++) {
                        block[i][j] = block01[i][j];
                    }
                }
            }
            break;
        case 11:
            if (collisionDetection (block00, map, x, y)) {
                clearBlock (hOut, block, x, y);
                for (int i = 0; i < 4; i++) {
                    for (int j = 0; j < 4; j++) {
                        block[i][j] = block00[i][j];
                    }
                }
            } else if (collisionDetection (block00, map, x, y - 1)) {
                clearBlock (hOut, block, x, y);
                for (int i = 0; i < 4; i++) {
                    for (int j = 0; j < 4; j++) {
                        block[i][j] = block00[i][j];
                    }
                }
                --y;
            } else if (collisionDetection (block00, map, x, y + 1)) {
                clearBlock (hOut, block, x, y);
                for (int i = 0; i < 4; i++) {
                    for (int j = 0; j < 4; j++) {
                        block[i][j] = block00[i][j];
                    }
                }
                ++y;
            } else if (collisionDetection (block00, map, x, y - 2)) {
                clearBlock (hOut, block, x, y);
                for (int i = 0; i < 4; i++) {
                    for (int j = 0; j < 4; j++) {
                        block[i][j] = block00[i][j];
                    }
                }
                y -= 2;
            } else if (collisionDetection (block00, map, x, y + 2)) {
                clearBlock (hOut, block, x, y);
                for (int i = 0; i < 4; i++) {
                    for (int j = 0; j < 4; j++) {
                        block[i][j] = block00[i][j];
                    }
                }
                y += 2;
            }
            break;
        case 12:
            if (collisionDetection (block03, map, x, y)) {
                clearBlock (hOut, block, x, y);
                for (int i = 0; i < 4; i++) {
                    for (int j = 0; j < 4; j++) {
                        block[i][j] = block03[i][j];
                    }
                }
            } else if (collisionDetection (block03, map, x, y - 1)) {
                clearBlock (hOut, block, x, y);
                for (int i = 0; i < 4; i++) {
                    for (int j = 0; j < 4; j++) {
                        block[i][j] = block03[i][j];
                    }
                }
                --y;
            } else if (collisionDetection (block03, map, x, y + 1)) {
                clearBlock (hOut, block, x, y);
                for (int i = 0; i < 4; i++) {
                    for (int j = 0; j < 4; j++) {
                        block[i][j] = block03[i][j];
                    }
                }
                ++y;
            }
            break;
        case 13:
            if (collisionDetection (block04, map, x, y)) {
                clearBlock (hOut, block, x, y);
                for (int i = 0; i < 4; i++) {
                    for (int j = 0; j < 4; j++) {
                        block[i][j] = block04[i][j];
                    }
                }
            } else if (collisionDetection (block04, map, x, y - 1)) {
                clearBlock (hOut, block, x, y);
                for (int i = 0; i < 4; i++) {
                    for (int j = 0; j < 4; j++) {
                        block[i][j] = block04[i][j];
                    }
                }
                --y;
            } else if (collisionDetection (block04, map, x, y + 1)) {
                clearBlock (hOut, block, x, y);
                for (int i = 0; i < 4; i++) {
                    for (int j = 0; j < 4; j++) {
                        block[i][j] = block04[i][j];
                    }
                }
                ++y;
            }
            break;
        case 14:
            if (collisionDetection (block05, map, x, y)) {
                clearBlock (hOut, block, x, y);
                for (int i = 0; i < 4; i++) {
                    for (int j = 0; j < 4; j++) {
                        block[i][j] = block05[i][j];
                    }
                }
            } else if (collisionDetection (block05, map, x, y - 1)) {
                clearBlock (hOut, block, x, y);
                for (int i = 0; i < 4; i++) {
                    for (int j = 0; j < 4; j++) {
                        block[i][j] = block05[i][j];
                    }
                }
                --y;
            } else if (collisionDetection (block05, map, x, y + 1)) {
                clearBlock (hOut, block, x, y);
                for (int i = 0; i < 4; i++) {
                    for (int j = 0; j < 4; j++) {
                        block[i][j] = block05[i][j];
                    }
                }
                ++y;
            }
            break;
        case 15:
            if (collisionDetection (block02, map, x, y)) {
                clearBlock (hOut, block, x, y);
                for (int i = 0; i < 4; i++) {
                    for (int j = 0; j < 4; j++) {
                        block[i][j] = block02[i][j];
                    }
                }
            } else if (collisionDetection (block02, map, x, y - 1)) {
                clearBlock (hOut, block, x, y);
                for (int i = 0; i < 4; i++) {
                    for (int j = 0; j < 4; j++) {
                        block[i][j] = block02[i][j];
                    }
                }
                --y;
            } else if (collisionDetection (block02, map, x, y + 1)) {
                clearBlock (hOut, block, x, y);
                for (int i = 0; i < 4; i++) {
                    for (int j = 0; j < 4; j++) {
                        block[i][j] = block02[i][j];
                    }
                }
                ++y;
            }
            break;
        case 16:
            if (collisionDetection (block07, map, x, y)) {
                clearBlock (hOut, block, x, y);
                for (int i = 0; i < 4; i++) {
                    for (int j = 0; j < 4; j++) {
                        block[i][j] = block07[i][j];
                    }
                }
            } else if (collisionDetection (block07, map, x, y - 1)) {
                clearBlock (hOut, block, x, y);
                for (int i = 0; i < 4; i++) {
                    for (int j = 0; j < 4; j++) {
                        block[i][j] = block07[i][j];
                    }
                }
                --y;
            } else if (collisionDetection (block07, map, x, y + 1)) {
                clearBlock (hOut, block, x, y);
                for (int i = 0; i < 4; i++) {
                    for (int j = 0; j < 4; j++) {
                        block[i][j] = block07[i][j];
                    }
                }
                ++y;
            }
            break;
        case 17:
            if (collisionDetection (block08, map, x, y)) {
                clearBlock (hOut, block, x, y);
                for (int i = 0; i < 4; i++) {
                    for (int j = 0; j < 4; j++) {
                        block[i][j] = block08[i][j];
                    }
                }
            } else if (collisionDetection (block08, map, x, y - 1)) {
                clearBlock (hOut, block, x, y);
                for (int i = 0; i < 4; i++) {
                    for (int j = 0; j < 4; j++) {
                        block[i][j] = block08[i][j];
                    }
                }
                --y;
            } else if (collisionDetection (block08, map, x, y + 1)) {
                clearBlock (hOut, block, x, y);
                for (int i = 0; i < 4; i++) {
                    for (int j = 0; j < 4; j++) {
                        block[i][j] = block08[i][j];
                    }
                }
                ++y;
            }
            break;
        case 18:
            if (collisionDetection (block09, map, x, y)) {
                clearBlock (hOut, block, x, y);
                for (int i = 0; i < 4; i++) {
                    for (int j = 0; j < 4; j++) {
                        block[i][j] = block09[i][j];
                    }
                }
            } else if (collisionDetection (block09, map, x, y - 1)) {
                clearBlock (hOut, block, x, y);
                for (int i = 0; i < 4; i++) {
                    for (int j = 0; j < 4; j++) {
                        block[i][j] = block09[i][j];
                    }
                }
                --y;
            } else if (collisionDetection (block09, map, x, y + 1)) {
                clearBlock (hOut, block, x, y);
                for (int i = 0; i < 4; i++) {
                    for (int j = 0; j < 4; j++) {
                        block[i][j] = block09[i][j];
                    }
                }
                ++y;
            }
            break;
        case 19:
            if (collisionDetection (block06, map, x, y)) {
                clearBlock (hOut, block, x, y);
                for (int i = 0; i < 4; i++) {
                    for (int j = 0; j < 4; j++) {
                        block[i][j] = block06[i][j];
                    }
                }
            } else if (collisionDetection (block06, map, x, y - 1)) {
                clearBlock (hOut, block, x, y);
                for (int i = 0; i < 4; i++) {
                    for (int j = 0; j < 4; j++) {
                        block[i][j] = block06[i][j];
                    }
                }
                --y;
            } else if (collisionDetection(block06, map, x, y + 1)) {
                clearBlock (hOut, block, x, y);
                for (int i = 0; i < 4; i++) {
                    for (int j = 0; j < 4; j++) {
                        block[i][j] = block06[i][j];
                    }
                }
                ++y;
            }
            break;
        case 20:
            if (collisionDetection (block11, map, x, y)) {
                clearBlock (hOut, block, x, y);
                for (int i = 0; i < 4; i++) {
                    for (int j = 0; j < 4; j++) {
                        block[i][j] = block11[i][j];
                    }
                }
            } else if (collisionDetection (block11, map, x, y - 1)) {
                clearBlock (hOut, block, x, y);
                for (int i = 0; i < 4; i++) {
                    for (int j = 0; j < 4; j++) {
                        block[i][j] = block11[i][j];
                    }
                }
                --y;
            } else if (collisionDetection (block11, map, x, y + 1)) {
                clearBlock (hOut, block, x, y);
                for (int i = 0; i < 4; i++) {
                    for (int j = 0; j < 4; j++) {
                        block[i][j] = block11[i][j];
                    }
                }
                ++y;
            }
            break;
        case 21:
            if (collisionDetection (block12, map, x, y)) {
                clearBlock (hOut, block, x, y);
                for (int i = 0; i < 4; i++) {
                    for (int j = 0; j < 4; j++) {
                        block[i][j] = block12[i][j];
                    }
                }
            } else if (collisionDetection(block12, map, x, y - 1)) {
                clearBlock (hOut, block, x, y);
                for (int i = 0; i < 4; i++) {
                    for (int j = 0; j < 4; j++) {
                        block[i][j] = block12[i][j];
                    }
                }
                --y;
            } else if (collisionDetection (block12, map, x, y + 1)) {
                clearBlock (hOut, block, x, y);
                for (int i = 0; i < 4; i++) {
                    for (int j = 0; j < 4; j++) {
                        block[i][j] = block12[i][j];
                    }
                }
                ++y;
            }
            break;
        case 22:
            if (collisionDetection (block13, map, x, y)) {
                clearBlock (hOut, block, x, y);
                for (int i = 0; i < 4; i++) {
                    for (int j = 0; j < 4; j++) {
                        block[i][j] = block13[i][j];
                    }
                }
            } else if (collisionDetection (block13, map, x, y - 1)) {
                clearBlock (hOut, block, x, y);
                for (int i = 0; i < 4; i++) {
                    for (int j = 0; j < 4; j++) {
                        block[i][j] = block13[i][j];
                    }
                }
                --y;
            } else if (collisionDetection (block13, map, x, y + 1)) {
                clearBlock (hOut, block, x, y);
                for (int i = 0; i < 4; i++) {
                    for (int j = 0; j < 4; j++) {
                        block[i][j] = block13[i][j];
                    }
                }
                ++y;
            }
            break;
        case 23:
            if (collisionDetection (block10, map, x, y)) {
                clearBlock (hOut, block, x, y);
                for (int i = 0; i < 4; i++) {
                    for (int j = 0; j < 4; j++) {
                        block[i][j] = block10[i][j];
                    }
                }
            } else if (collisionDetection (block10, map, x, y - 1)) {
                clearBlock (hOut, block, x, y);
                for (int i = 0; i < 4; i++) {
                    for (int j = 0; j < 4; j++) {
                        block[i][j] = block10[i][j];
                    }
                }
                --y;
            } else if (collisionDetection (block10, map, x, y + 1)) {
                clearBlock (hOut, block, x, y);
                for (int i = 0; i < 4; i++) {
                    for (int j = 0; j < 4; j++) {
                        block[i][j] = block10[i][j];
                    }
                }
                ++y;
            }
            break;
        case 24:
            if (collisionDetection (block15, map, x, y)) {
                clearBlock (hOut, block, x, y);
                for (int i = 0; i < 4; i++) {
                    for (int j = 0; j < 4; j++) {
                        block[i][j] = block15[i][j];
                    }
                }
            } else if (collisionDetection (block15, map, x, y - 1)) {
                clearBlock (hOut, block, x, y);
                for (int i = 0; i < 4; i++) {
                    for (int j = 0; j < 4; j++) {
                        block[i][j] = block15[i][j];
                    }
                }
                --y;
            } else if (collisionDetection (block15, map, x, y + 1)) {
                clearBlock (hOut, block, x, y);
                for (int i = 0; i < 4; i++) {
                    for (int j = 0; j < 4; j++) {
                        block[i][j] = block15[i][j];
                    }
                }
                ++y;
            }
            break;
        case 25:
            if (collisionDetection (block14, map, x, y)) {
                clearBlock (hOut, block, x, y);
                for (int i = 0; i < 4; i++) {
                    for (int j = 0; j < 4; j++) {
                        block[i][j] = block14[i][j];
                    }
                }
            } else if (collisionDetection (block14, map, x, y - 1)) {
                clearBlock (hOut, block, x, y);
                for (int i = 0; i < 4; i++) {
                    for (int j = 0; j < 4; j++) {
                        block[i][j] = block14[i][j];
                    }
                }
                --y;
            } else if (collisionDetection (block14, map, x, y + 1)) {
                clearBlock (hOut, block, x, y);
                for (int i = 0; i < 4; i++) {
                    for (int j = 0; j < 4; j++) {
                        block[i][j] = block14[i][j];
                    }
                }
                ++y;
            }
            break;
        case 26:
            if (collisionDetection (block17, map, x, y)) {
                clearBlock (hOut, block, x, y);
                for (int i = 0; i < 4; i++) {
                    for (int j = 0; j < 4; j++) {
                        block[i][j] = block17[i][j];
                    }
                }
            } else if (collisionDetection (block17, map, x, y - 1)) {
                clearBlock (hOut, block, x, y);
                for (int i = 0; i < 4; i++) {
                    for (int j = 0; j < 4; j++) {
                        block[i][j] = block17[i][j];
                    }
                }
                --y;
            } else if (collisionDetection (block17, map, x, y + 1)) {
                clearBlock (hOut, block, x, y);
                for (int i = 0; i < 4; i++) {
                    for (int j = 0; j < 4; j++) {
                        block[i][j] = block17[i][j];
                    }
                }
                ++y;
            }
            break;
        case 27:
            if (collisionDetection (block16, map, x, y)) {
                clearBlock (hOut, block, x, y);
                for (int i = 0; i < 4; i++) {
                    for (int j = 0; j < 4; j++) {
                        block[i][j] = block16[i][j];
                    }
                }
            } else if (collisionDetection (block16, map, x, y - 1)) {
                clearBlock (hOut, block, x, y);
                for (int i = 0; i < 4; i++) {
                    for (int j = 0; j < 4; j++) {
                        block[i][j] = block16[i][j];
                    }
                }
                --y;
            } else if (collisionDetection (block16, map, x, y + 1)) {
                clearBlock (hOut, block, x, y);
                for (int i = 0; i < 4; i++) {
                    for (int j = 0; j < 4; j++) {
                        block[i][j] = block16[i][j];
                    }
                }
                ++y;
            }
            break;
        default:
            break;
    }
}
void myStop (HANDLE hOut, int block[4][4]) {
    clearBlock (hOut, block, 5, 15);
    SetConsoleTextAttribute (hOut, FOREGROUND_RED | FOREGROUND_INTENSITY);
    gotoXY (hOut, 30, 7);
    cout << "游戏暂停";
    char key;
    while (true) {
        key = _getch ();
        if (key == 32) {
            gotoXY (hOut, 30, 7);
            cout << "        ";
            printBlock (hOut, block, 5, 15);
            return;
        }
        if (key == 27) {
            exit (0);
        }
    }
}
void eliminateRow (HANDLE hOut, int map[21][12], int &val, int &fraction, int &checkpoint) {
    SetConsoleTextAttribute(hOut, FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY);
    for (int i = 19; i >= 0; i--) {
        int x = 0;
        for (int j = 1; j < 11; j++) {
            x += map[i][j];
        }
        if (x == 10) {
            fraction += 100;
            if (val > 1 && fraction / 1000 + 1 != checkpoint) {
                checkpoint = fraction / 1000 + 1;
                val -= 5;
            }
            for (int m = i; m > 0; m--) {
                for (int n = 1; n < 11; n++) {
                    map[m][n] = map[m - 1][n];
                    gotoXY (hOut, 2 * n, m);
                    if (map[m][n] == 1) {
                        cout << "■";
                    } else {
                        cout << "  ";
                    }
                }
            }
            i++;
        }
    }
    gotoXY (hOut, 36, 1);
    cout << fraction;
    gotoXY (hOut, 36, 2);
    cout << checkpoint;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值