#include<bits/stdc++.h>
#include <windows.h>
#include <stdio.h>
#include<conio.h>
#include<time.h>
using namespace std;
int x = 0;
int* X = &x;
char Void[10000] = "\0";
int Key = 0;
int KeyOut = 0;
int User;
int User2;
int* Q1;
int* Q2;
int* Q3;
int score; //游戏得分
const int nn = 809;
struct Point { int x, y; };
int dali;
int fx[4] = { -1,27,1,-27 };
int fxfx[4][2] = { {0,-1},{1,0},{0,1},{-1,0} };
int dis[1000][1000];
int changdi[30][27] = {
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,0},
{0,1,0,0,0,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,0,0,0,1,0},
{0,1,0,0,0,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,0,0,0,1,0},
{0,1,0,0,0,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,0,0,0,1,0},
{0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0},
{0,1,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,1,0},
{0,1,1,1,1,1,1,0,0,1,1,1,1,0,1,1,1,1,0,0,1,1,1,1,1,1,0},
{0,0,0,0,0,0,1,0,0,0,0,0,2,0,2,0,0,0,0,0,1,0,0,0,0,0,0},
{0,0,0,0,0,0,1,0,0,0,0,0,2,0,2,0,0,0,0,0,1,0,0,0,0,0,0},
{0,0,0,0,0,0,1,0,0,2,2,2,2,2,2,2,2,2,0,0,1,0,0,0,0,0,0},
{0,0,0,0,0,0,1,0,0,2,0,0,0,3,0,0,0,2,0,0,1,0,0,0,0,0,0},
{0,0,0,0,0,0,1,0,0,2,0,3,3,3,3,3,0,2,0,0,1,0,0,0,0,0,0},
{2,2,2,2,2,2,1,2,2,2,0,3,3,3,3,3,0,2,2,2,1,2,2,2,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2, t1, t2, stopped; //T:计时 t1:玩家速度 t2:怪物速度
int ff = 0; //f:{0:继续 1:被吃 2:赢了 3:输了}
int beichi;
#define high 20 //定义地图的高度
#define width 30 //定义地图的宽度
#define snake_maxlength 200 //蛇长最大值
int snake_x[snake_maxlength], snake_y[snake_maxlength]; //蛇的坐标
int snake_length; //蛇现在的长度
int Map[high][width] = { 0 }; //初始化地图,0表示空格,1表示蛇身,2表示食物,3表示墙,4表示蛇头,现在地图中什么也没有
int food_x, food_y; //食物的坐标
int SCORE; //本局分数
char input;
char primeinput = '.';
int op = 100;
int Death = 0;
int Guesstimes;
struct account{
char user[1000]; //用户名
char password[1000]; //密码
int coin = 0; //硬币
int number; //编号
int award = 0; //奖励次数,主要用于恋爱测试器奖励次数的限定
};
struct account peo[100]; //初设100人,可更改
void HideCursor()
{
CONSOLE_CURSOR_INFO cursor_info = { 1, 0 };
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}
float Check(int a)
{
if (a == 0) //针对字符和字符串
{
float m;
if (cin >> m)
{
return m;
}
else
{
cout << "输入错误,请重新输入:";
cin.clear(); //清除这个错误状态
cin.sync(); //清理缓冲区内容
cin.get();
while (!(cin >> m))
{
cout << "输入错误,请重新输入:";
cin.clear(); //清除这个错误状态
cin.sync(); //清理缓冲区内容
cin.get();
}
return m;
}
}
else if (a == 1){
float m;
float c;
if (cin >> m){
while (1){
if (m == 1 || m == 2 || m == 0){
return m;
break;
}
else{
cout << "输入错误,请重新输入:";
c = Check(1); //递归调用,重新检测输入
return c;
break;
}
}
}
else{
cout << "输入错误,请重新输入:";
cin.clear(); //清除这个错误状态
cin.sync(); //清理缓冲区内容
cin.get();
while (!(cin >> m)){
cout << "输入错误,请重新输入:";
cin.clear(); //清除这个错误状态
cin.sync(); //清理缓冲区内容
cin.get();
}
while (1){
if (m == 1 || m == 2 || m == 0){
return m;
break;
}
else{
cout << "抱歉!输入错误,请重新输入:";
c = Check(1);
return c;
break;
}
}
}
}
else if (a == 2) //针对字符和字符串以及特定的数字(1、2)
{
float m;
float c;
if (cin >> m)
{
while (1)
{
if (m == 1 || m == 2)
{
return m;
break;
}
else
{
cout << "输入错误,请重新输入:";
c = Check(2);
return c;
break;
}
}
}
else
{
cout << "输入错误,请重新输入:";
cin.clear(); //清除这个错误状态
cin.sync();//清理缓冲区内容
cin.get();
while (!(cin >> m))
{
cout << "输入错误,请重新输入:";
cin.clear(); //清除这个错误状态
cin.sync(); //清理缓冲区内容
cin.get();
}
while (1)
{
if (m == 1 || m == 2)
{
return m;
break;
}
else
{
cout << "输入错误,请重新输入:";
a = Check(2);
return a;
break;
}
}
}
}
else if (a == 3) //针对字符和字符串以及特定的数字(1、2、3)
{
float m;
float c;
if (cin >> m)
{
while (1)
{
if (m == 1 || m == 2 || m == 3)
{
return m;
break;
}
else
{
cout << "输入错误,请重新输入:";
c = Check(3);
return c;
break;
}
}
}
else
{
cout << "输入错误,请重新输入:";
cin.clear(); //清除这个错误状态
cin.sync(); //清理缓冲区内容
cin.get();
while (!(cin >> m))
{
cout << "输入错误,请重新输入:";
cin.clear(); //清除这个错误状态
cin.sync(); //清理缓冲区内容
cin.get();
}
while (1){
if (m == 1 || m == 2 || m == 3){
return m;
break;
}
else{
cout << "输入错误,请重新输入:";
a = Check(3);
return a;
break;
}
}
}
}
else if (a == 4) { //针对字符和字符串以及特定的数字(1、0)
float m;
float c;
if (cin >> m){
while (1){
if (m == 1 || m == 0){
return m;
break;
}
else{
cout << "输入错误,请重新输入:";
c = Check(4);
return c;
break;
}
}
}
else{
cout << "输入错误,请重新输入:";
cin.clear(); //清除这个错误状态
cin.sync(); //清理缓冲区内容
cin.get();
while (!(cin >> m)){
cout << "输入错误,请重新输入:";
cin.clear(); //清除这个错误状态
cin.sync(); //清理缓冲区内容
cin.get();
}
while (1){
if (m == 1 || m == 0){
return m;
break;
}
else
{
cout << "输入错误,请重新输入:";
a = Check(4);
return a;
break;
}
}
}
}
}
void Progress(){
int c = 1, d = 0;
for (int i = 0; i < 50; i++)
{
cout << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl;
cout << "\t\t\t\t+-------------------------------------------------+" << endl;
cout << "\t\t\t\t|";
for (int a = 0; a < i; a++) //打印▋
{
cout << "▋";
}
for (int b = 49 - i; b > 0; b--) //打印空格
{
cout << " ";
}
d += 2; //进度数
cout << "| " << d << "%" << endl;
cout << "\t\t\t\t+-------------------------------------------------+" << endl;
cout << "\t\t\t\t 亲爱的用户!正在进入游戏世界,请稍后.";
for (int j = 0; j < c % 6; j++)
{
cout << ".";
}
c++;
cout << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl;
Sleep(150); //进度条读取速度
if (i != 49)
{
system("cls"); //清屏
}
}
Sleep(3000);
system("cls");
}
int NormalizeName(char name[1000], int n)
{
int a = 0; //计数器
if (n <= 15)
{
for (int i = 0; i < n; i++)
{
if (name[i] <= 32 || name[i] == 127) //为空格或其他特殊情况
{
break;
}
else
{
a++;
}
}
if (a == n)
{
return 1;
}
else
{
return 0;
}
}
else
{
return 0;
}
}
//--------------------------------------------------------------------------------------------------------------
// 用户名查重系统
int CheckName(char name[1000])
{
int a = 0; //计数器
if (x == 0) //第一个注册的人无重复
{
return 1;
}
else
{
for (int i = 0; i < x; i++)
{
if (strcmp(name, peo[i].user) == 0)
{
break;
}
else
{
a++;
}
}
if (a == x) //用户名无重复
{
return 1;
}
else
{
return 0;
}
}
}
//--------------------------------------------------------------------------------------------------------------
// 密码规范系统
int NormalizePassword(char password[1000], int n)
{
int a = 0; //计数器
if (n >= 6 && n <= 15)
{
for (int i = 0; i < n; i++)
{
if ((password[i] >= 48 && password[i] <= 57) || (password[i] >= 65 && password[i] <= 90) || (password[i] >= 97 && password[i] <= 122)) //为字母或数字
{
a++;
}
else
{
break;
}
}
if (a == n)
{
return 1;
}
else
{
return 0;
}
}
else
{
return 0;
}
}
//--------------------------------------------------------------------------------------------------------------
// 密码找回系统
int RefoundPassword()
{
while (1)
{
char Name2[1000];
int Key1 = 0;
cout << "请输入用户名:";
cin >> Name2;
for (int i = 0; i < *X; i++) //逐个人员遍历
{
if (strcmp(Name2, peo[i].user) == 0) //判断输入的用户名有无注册或是否正确
{
Key1 = 1;
User2 = i;
}
}
system("cls"); //清屏
if (Key1 == 0) //钥匙解锁失败
{
cout << "抱歉,您的用户名未注册或输入错误!!!" << endl << endl;
cout << "1.继续找回密码" << endl;
cout << "2.退出系统" << endl;
cout << "请输入数字实现对应功能:";
int m2 = Check(2); //只返回1、2
cout << endl;
if (m2 == 1)
{
system("cls"); //清屏
continue;
}
else if (m2 == 2)
{
system("cls"); //清屏
return 0;
}
}
else if (Key1 == 1) //钥匙解锁成功
{
cout << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl;
cout << "\t\t\t\t\t\t 您的密码为:" << peo[User2].password << endl;
Sleep(2000);
system("pause");
system("cls"); //清屏
return 1;
}
}
}
//--------------------------------------------------------------------------------------------------------------
// 账号注册系统:
int Register()
{
int key1 = 0; //注册成功的钥匙
int key2 = 0; //用户名设置成功的钥匙
int key3 = 0; //密码设置成功钥匙
int key4 = 0; //退出程序的钥匙
int h = 0; //轮转片
char recheck[100];
peo[x].number = x + 1; //标号