兔兔 的 游戏 —— 贪吃蛇

   日期:2020-08-20     浏览:71    评论:0    
核心提示:贪吃蛇兔兔辛辛苦苦打了2个小时的啦!兔兔辛辛苦苦打了2个小时的啦!兔兔辛辛苦苦打了2个小时的啦!感谢大家的支持哦~——暂时没有写注释呢…(请读者见谅哈~)#include #include #include #include #include #include #include #

贪吃蛇 (1.2)

兔 兔 辛 辛 苦 苦 打 了 2 个 小 时 的 啦 ! 兔兔辛辛苦苦打了2个小时的啦! 2!
感谢大家的支持哦~
——暂时没有写注释呢…(请读者见谅哈~)

  • 1.1 修复闪屏bug
  • 1.2 修复不好看的倒计时
#include <cstdio>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <iostream>
#include <string>

#include <map>
#include <set>
#include <vector>

#include <bits/stdc++.h>
#include <conio.h>
#include <windows.h>
using namespace std;

const int MAP = 21;
int TOT = (MAP - 1) * (MAP - 1) - 2;
struct Snake {
	int R, C;
}head, tail, node[900];
map<char, char> mp;
int cnt;
bool book;
int fraction = 1;
bool wall[MAP][MAP] =
{
	{ 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, 1, 1, 1, 1, 1, 1, 1, 1 }, 
	{ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, 
	{ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, 
	{ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, 
	{ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, 
	{ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },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'0', '0', '0', '0', '0', '0' }, 
	{ '0', '0', 'd', 'd', '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', '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', '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', '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', '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', '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', '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', '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', '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', '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', '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', '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', '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', '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', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0' }, 
};

void Put_String(char *s)
{
	while (1)
	{
		if (*s != 0) printf("%c", *s++);
		else break;
		Sleep(100);
	}
}

void Jin_Du_Tiao(int T)
{
	COORD Pos0, Pos1, Pos2;
	Pos1.X = 2, Pos1.Y = 1;
	Pos2.X = 50, Pos2.Y = 1;
	system("cls");
	SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), Pos0);
	cout << "╔══════════════════════════════════════════╗" << endl;
	cout << "║ ║"<<endl;
	cout << "╚══════════════════════════════════════════╝" << endl;
	for (int i = 1; i <= 20; i++)
	{
		Sleep(T);
		SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), Pos1);
		cout << "█";
		Pos1.X += 2;
		SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), Pos2);
		printf("%d%%\n\n", i * 5);
	}
	system("cls");
	SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), Pos0);
	cout << "■■■■■■■■" << endl;
	cout << " ■" << endl;
	cout << " ■" << endl;
	cout << " ■" << endl;
	cout << "■■■■■■■■" << endl;
	cout << " ■" << endl;
	cout << " ■" << endl;
	cout << " ■" << endl;
	cout << "■■■■■■■■" << endl;
	Sleep(1000);
	system("cls");
	SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), Pos0);
	cout << "■■■■■■■■" << endl;
	cout << " ■" << endl;
	cout << " ■" << endl;
	cout << " ■" << endl;
	cout << "■■■■■■■■" << endl;
	cout << "■ " << endl;
	cout << "■ " << endl;
	cout << "■ " << endl;
	cout << "■■■■■■■■" << endl;
	Sleep(1000);
	system("cls");
	SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), Pos0);
	cout << " ■" << endl;
	cout << " ■" << endl;
	cout << " ■" << endl;
	cout << " ■" << endl;
	cout << " ■" << endl;
	cout << " ■" << endl;
	cout << " ■" << endl;
	cout << " ■" << endl;
	cout << " ■" << endl;
	Sleep(1000);
	system("cls");
}

void Rand_Bean()
{
	int num = rand() % cnt + 1;
	bean[node[num].R][node[num].C] = 1;
	book = 1;
}

void Print_Map()
{
	COORD Pos;
	Pos.X = 0, Pos.Y = 0;
	SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), Pos);
	cnt = 0;
	for (int r = 1; r <= MAP - 1; r++)
	{
		for (int c = 1; c <= MAP - 1; c++)
		{
			if (wall[r][c]) printf("■");
			else if (snake[r][c] == 1) printf("●");
			else if (snake[r][c] == 2) printf("");
			else if (bean[r][c] == 1) printf("◇");
			else printf(" "), ++cnt, node[cnt].R = r, node[cnt].C = c;
		}
		printf("\n");
	}
	printf("尾巴长度:%d\n", fraction);
}

void over()
{
	system("cls");
	Put_String("游戏结束...\n");
	exit(0);
}

bool Check()
{
	int sr = head.R, sc = head.C;
	return bean[sr][sc];
}

void Move()
{
	if (kbhit())
	{
		int sr = head.R, sc = head.C;
		int tr = tail.R, tc = tail.C;
		char C = getch();
		if (C != direc[sr][sc] && C != mp[direc[sr][sc]])
		{
			if (C == 'w')
			{
				if (snake[sr - 1][sc] == 2 || wall[sr - 1][sc]) over();
				else
				{
					direc[sr - 1][sc] = 'w', direc[sr][sc] = 'w';
					snake[sr - 1][sc] = 1, snake[sr][sc] = 2;
					--head.R;
					char dir = direc[tr][tc];
					if (!Check())
					{
						if (dir == 'w') --tail.R, direc[tr][tc] = '0', snake[tr][tc] = 0;
						if (dir == 's') ++tail.R, direc[tr][tc] = '0', snake[tr][tc] = 0;
						if (dir == 'a') --tail.C, direc[tr][tc] = '0', snake[tr][tc] = 0;
						if (dir == 'd') ++tail.C, direc[tr][tc] = '0', snake[tr][tc] = 0;
					}
					else bean[sr - 1][sc] = 0, book = 0, fraction += 1;
				}
			}
			if (C == 's')
			{
				if (snake[sr + 1][sc] == 2 || wall[sr + 1][sc]) over();
				else
				{
					direc[sr + 1][sc] = 's', direc[sr][sc] = 's';
					snake[sr + 1][sc] = 1, snake[sr][sc] = 2;
					++head.R;
					char dir = direc[tr][tc];
					if (!Check())
					{
						if (dir == 'w') --tail.R, direc[tr][tc] = '0', snake[tr][tc] = 0;
						if (dir == 's') ++tail.R, direc[tr][tc] = '0', snake[tr][tc] = 0;
						if (dir == 'a') --tail.C, direc[tr][tc] = '0', snake[tr][tc] = 0;
						if (dir == 'd') ++tail.C, direc[tr][tc] = '0', snake[tr][tc] = 0;
					}
					else bean[sr + 1][sc] = 0, book = 0, fraction += 1;
				}
			}
			if (C == 'a')
			{
				if (snake[sr][sc - 1] == 2 || wall[sr][sc - 1]) over();
				else
				{
					direc[sr][sc - 1] = 'a', direc[sr][sc] = 'a';
					snake[sr][sc - 1] = 1, snake[sr][sc] = 2;
					--head.C;
					char dir = direc[tr][tc];
					if (!Check())
					{
						if (dir == 'w') --tail.R, direc[tr][tc] = '0', snake[tr][tc] = 0;
						if (dir == 's') ++tail.R, direc[tr][tc] = '0', snake[tr][tc] = 0;
						if (dir == 'a') --tail.C, direc[tr][tc] = '0', snake[tr][tc] = 0;
						if (dir == 'd') ++tail.C, direc[tr][tc] = '0', snake[tr][tc] = 0;
					}
					else bean[sr][sc - 1] = 0, book = 0, fraction += 1;
				}
			}
			if (C == 'd')
			{
				if (snake[sr][sc + 1] == 2 || wall[sr][sc + 1]) over();
				else
				{
					direc[sr][sc + 1] = 'd', direc[sr][sc] = 'd';
					snake[sr][sc + 1] = 1, snake[sr][sc] = 2;
					++head.C;
					char dir = direc[tr][tc];
					if (!Check())
					{
						if (dir == 'w') --tail.R, direc[tr][tc] = '0', snake[tr][tc] = 0;
						if (dir == 's') ++tail.R, direc[tr][tc] = '0', snake[tr][tc] = 0;
						if (dir == 'a') --tail.C, direc[tr][tc] = '0', snake[tr][tc] = 0;
						if (dir == 'd') ++tail.C, direc[tr][tc] = '0', snake[tr][tc] = 0;
					}
					else bean[sr][sc + 1] = 0, book = 0, fraction += 1;
				}
			}
		}
	}
	else
	{
		int sr = head.R, sc = head.C;
		int tr = tail.R, tc = tail.C;
		char C = direc[sr][sc];
		if (C == 'w')
		{
			if (snake[sr - 1][sc] == 2 || wall[sr - 1][sc]) over();
			else
			{
				direc[sr - 1][sc] = 'w', direc[sr][sc] = 'w';
				snake[sr - 1][sc] = 1, snake[sr][sc] = 2;
				--head.R;
				char dir = direc[tr][tc];
				if (!Check())
				{
					if (dir == 'w') --tail.R, direc[tr][tc] = '0', snake[tr][tc] = 0;
					if (dir == 's') ++tail.R, direc[tr][tc] = '0', snake[tr][tc] = 0;
					if (dir == 'a') --tail.C, direc[tr][tc] = '0', snake[tr][tc] = 0;
					if (dir == 'd') ++tail.C, direc[tr][tc] = '0', snake[tr][tc] = 0;
				}
				else bean[sr - 1][sc] = 0, book = 0, fraction += 1;
			}
		}
		if (C == 's')
		{
			if (snake[sr + 1][sc] == 2 || wall[sr + 1][sc]) over();
			else
			{
				direc[sr + 1][sc] = 's', direc[sr][sc] = 's';
				snake[sr + 1][sc] = 1, snake[sr][sc] = 2;
				++head.R;
				char dir = direc[tr][tc];
				if (!Check())
				{
					if (dir == 'w') --tail.R, direc[tr][tc] = '0', snake[tr][tc] = 0;
					if (dir == 's') ++tail.R, direc[tr][tc] = '0', snake[tr][tc] = 0;
					if (dir == 'a') --tail.C, direc[tr][tc] = '0', snake[tr][tc] = 0;
					if (dir == 'd') ++tail.C, direc[tr][tc] = '0', snake[tr][tc] = 0;
				}
				else bean[sr + 1][sc] = 0, book = 0, fraction += 1;
			}
		}
		if (C == 'a')
		{
			if (snake[sr][sc - 1] == 2 || wall[sr][sc - 1]) over();
			else
			{
				direc[sr][sc - 1] = 'a', direc[sr][sc] = 'a';
				snake[sr][sc - 1] = 1, snake[sr][sc] = 2;
				--head.C;
				char dir = direc[tr][tc];
				if (!Check())
				{
					if (dir == 'w') --tail.R, direc[tr][tc] = '0', snake[tr][tc] = 0;
					if (dir == 's') ++tail.R, direc[tr][tc] = '0', snake[tr][tc] = 0;
					if (dir == 'a') --tail.C, direc[tr][tc] = '0', snake[tr][tc] = 0;
					if (dir == 'd') ++tail.C, direc[tr][tc] = '0', snake[tr][tc] = 0;
				}
				else bean[sr][sc - 1] = 0, book = 0, fraction += 1;
			}
		}
		if (C == 'd')
		{
			if (snake[sr][sc + 1] == 2 || wall[sr][sc + 1]) over();
			else
			{
				direc[sr][sc + 1] = 'd', direc[sr][sc] = 'd';
				snake[sr][sc + 1] = 1, snake[sr][sc] = 2;
				++head.C;
				char dir = direc[tr][tc];
				if (!Check())
				{
					if (dir == 'w') --tail.R, direc[tr][tc] = '0', snake[tr][tc] = 0;
					if (dir == 's') ++tail.R, direc[tr][tc] = '0', snake[tr][tc] = 0;
					if (dir == 'a') --tail.C, direc[tr][tc] = '0', snake[tr][tc] = 0;
					if (dir == 'd') ++tail.C, direc[tr][tc] = '0', snake[tr][tc] = 0;
				}
				else bean[sr][sc + 1] = 0, book = 0, fraction += 1;
			}
		}
	}
	Check();
}

void init()
{
	head.R = 2, head.C = 3;
	tail.R = 2, tail.C = 2;
	mp['w'] = 's', mp['s'] = 'w';
	mp['a'] = 'd', mp['d'] = 'a';
	cnt = 0;
	for (int r = 1; r <= MAP - 1; r++)
	{
		for (int c = 1; c <= MAP - 1; c++)
		{
			++cnt;
			node[cnt].R = r;
			node[cnt].C = c;
		}
	}
}

int main()
{
	Jin_Du_Tiao(100);
	init();
	while (1)
	{
		Print_Map();
		if (book == 0) Rand_Bean();
		Move();
		Sleep(50);
		Check();
	}
	return 0;
}

 
打赏
 本文转载自:网络 
所有权利归属于原作者,如文章来源标示错误或侵犯了您的权利请联系微信13520258486
更多>最近资讯中心
更多>最新资讯中心
0相关评论

推荐图文
推荐资讯中心
点击排行
最新信息
新手指南
采购商服务
供应商服务
交易安全
关注我们
手机网站:
新浪微博:
微信关注:

13520258486

周一至周五 9:00-18:00
(其他时间联系在线客服)

24小时在线客服