#include<stdio.h>
#include<stdlib.h>
#include<Windows.h>
#include<conio.h>
#include<time.h>
void Gamestart();
void Gotoxy(int x, int y);
void Creatbg();
void Initsnake();
void snakemove(int direction);
void Rungame();
void HideCursor();
void produce_food();
void die_1();
void die_2();
int endgamestatus = 0;
int food_x, food_y;
int score=0;
enum { UP = 72, DOWN = 80, LEFT = 75, RIGHT = 77 };
int main()
{
HideCursor();
Gamestart();
Creatbg();
produce_food();
Initsnake();
Rungame();
return 0;
}
void HideCursor()//隐藏控制台光标
{
CONSOLE_CURSOR_INFO cursor;
cursor.bVisible = FALSE;
cursor.dwSize = sizeof(cursor);
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorInfo(handle, &cursor);
};
void Gamestart()
{
system("mode con cols=110 lines=35");
printf("\n\n\n\n\n\n\n\n\n\n");
printf("\t\t\t\t\t欢迎来到贪吃蛇世界!\t\t\t\n");
printf("\t\t\t\t\t游戏设计者-xxx\t\t\t");
printf("\n\n\n\n\n\n\n\n\n\n");
system("pause");
system("cls"); //清屏
};
void Gotoxy(int x, int y) //设置光标,用来找xy的位置
{
COORD pos = { x,y };
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); //相当于控制台的ID
SetConsoleCursorPosition(hOut, pos);
};
void Creatbg()
{
for (int i = 0; i < 60; i++)
{
Gotoxy(i, 0);
printf("■");
Gotoxy(i, 29);
printf("■");
}
for (int j = 0; j < 30; j++)
{
Gotoxy(0, j);
printf("■");
Gotoxy(60, j);
printf("■");
}
Gotoxy(64, 16);
printf("不能穿墙,不能咬到自己");