用链表实现简单贪吃蛇

#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("不能穿墙,不能咬到自己");

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值