C语言贪吃蛇Linux版

/* ======================================= */

Update: 20170713

新版贪吃蛇:传送门

/* ======================================= */
最近闲来无事用C语言写了个贪吃蛇解解闷, 其实这玩意儿也不难写, 其一就是如何绘制蛇和背景, 其二就是怎么把用户的输入实现成蛇的转向. 我这里使用了curses.h和pthread.h库, 前者是在Cmdline下绘制图形, 后者是多线程库.
当蛇撞到边界或者自己身体里, 画面就会停住, 表示游戏结束, 这时按任意键就会回到主菜单.
注意,本游戏在窗口模式下正常运行,全屏可能会有BUG。
Menu
Game1
Game2
编译:
g++ main.c -lcurses -pthread

#include <iostream>
#include <cstdio>
#include <cstring>
#include <curses.h>//graph lib
#include <unistd.h>//usleep
#include <pthread.h>// mul process
#include <time.h>
#include <cstdlib>
const int DMENU=1;//the manu status
const int DGAME=2;//start game
const int MENU_START=1;
const int MENU_EXIT=2;
const int MENU_ABOUT=3;
const int HEAD_LEFT=1;
const int HEAD_DOWN=2;
const int HEAD_UP=3;
const int HEAD_RIGHT=4;
using namespace std;
struct curPoint
{
    int x, y;   
};
struct MainSnack
{
    curPoint body[10000]    ;
    int len, arrowHead, score, dead;
};
char StrMenuOption[10][255];
int MenuTotalLine;
int MenuChosed;
pthread_t Pid;
MainSnack Ms;
void xcInit();//Initial for the program
  • 5
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值