#include <graphics.h>
#include <conio.h>
#include <time.h>
#include <stdio.h>
#include<iostream>
#include<string.h>
#include<time.h>
#include <tchar.h>
#include <mmsystem.h>//导入声音头文件
#pragma comment(lib,"Winmm.lib")
#define MAP_HEIGHT 30
#define MAP_WIDE 30
#define SIZE 16
#define SPEED 200
//定义蛇的结点
typedef struct Snakes
{
int x;//蛇的结点的位置坐标
int y;
struct Snakes* next;
}snake;
snake* head, * tail;
//定义食物的结构
struct Food
{
int x;
int y;
}food;
int grow = 0;
int yuan[100];
int aa = -1;
//int COUNT = 0;
char ch1 = 1;
int a1 = 0, a2 = 1, a3 = 0;;//grow =0 表示没吃到食物,grow = 1表示吃到食物
TCHAR str[100];
TCHAR str1[100];
TCHAR str2[100];
TCHAR str3[100];
int score = 0;
int count=1;
char ch = 'a';//初始方向向左
void BGM()
{
PlaySound(TEXT("平凡之路.wav"), NULL, SND_FILENAME | SND_ASYNC | SND_LOOP);
}
void login() //登录界面//
{
char name[100];
initgraph(1200, 900);
setbkcolor(BLUE);
cleardevice();
settextcolor(WHITE);
setfont(100, 0, _T("华文行楷"));
outtextxy(300, 150, _T("WELCOME"));
wchar_t username[1000];
errno_t err;
//FILE* fb;
InputBox(username, 100, _T("请输入你的昵称"));
FILE* fb = fopen("username.txt", "a");
fprintf(fb, "%S ", username);
fprintf(fb, "%c", '\n');
fclose(fb);
// err = fopen_s(&fp, "username.txt", "a");
//fprintf(fp, "%d", username);
//fclose(fp);
}
void Count()
{
FILE* fp11 = fopen("count.txt", "r");
fscanf(fp11, "%d", &aa);
aa = aa + 1;
fclose(fp11);
FILE* fp111 = fopen("count.txt", "w");
fprintf(fp111, "%d", aa);
fclose(fp111);
}
//void Count()
//{
// FILE* fp11 = fopen("count.txt", "r+");
// fscanf(fp11, "%d", &aa);
// aa = aa + 1;
// fclose(fp11);
// FILE* fp111 = fopen("count.txt", "w");
// fprintf(fp111, "%d", aa);
// fclose(fp111);
//}
void DrawMap()//打印地图
{
setbkcolor(YELLOW);
cleardevice(); //调用清屏cleardevice用背景色刷新背景
for (int i = 0; i < MAP_WIDE; i++)
{
setfillcolor(BLUE);
//上边框
fillrectangle(i * SIZE, 0, (i + 1) * SIZE, SIZE);
//下边框
fillrectangle(i * SIZE, (MAP_HEIGHT - 1) * SIZE, (i + 1) * SIZE, MAP_HEIGHT * SIZE);
}
for (int i = 0; i < MAP_HEIGHT; i++)
{
setfillcolor(BLUE);
//左边框
fillrectangle(0, i * SIZE, SIZE, (i + 1) * SIZE);
//右边框
fillrectangle((MAP_WIDE - 1) * SIZE, i * SIZE, MAP_WIDE * SIZE, (i + 1) * SIZE);
}
settextcolor(GREEN);
_stprintf_s(str1, _T("%d"), score);
outtextxy(500, 20, str1);
}
//打印结点
void PrintNode(int x, int y)
{
setfillcolor(RED);
fillcircle(x * SIZE, y * SIZE, SIZE / 2);
setcolor(WHITE);
circle(x * SIZE, y * SIZE, SIZE / 2);
}
//删除结点
void DeleteNode(int x, int y)
{
setfillcolor(YELLOW);
fillcircle(x * SIZE, y * SIZE, SIZE / 2);
setcolor(YELLOW);
circle(x * SIZE, y * SIZE, SIZE / 2);
}
void InitMap()
{
//初始化蛇
head = (snake*)malloc(sizeof(snake));
head->x = (MAP_WIDE) / 2;
head->y =