贪吃蛇 (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 },
{ 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,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, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
};
char direc[MAP][MAP] =
{
{ '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0' },
{ '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '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;
}