Dos界面C++贪吃蛇设计报告

上传人:飞*** 文档编号:37881462 上传时间:2018-04-23 格式:PDF 页数:8 大小:193.62KB
返回 下载 相关 举报
Dos界面C++贪吃蛇设计报告_第1页
第1页 / 共8页
Dos界面C++贪吃蛇设计报告_第2页
第2页 / 共8页
Dos界面C++贪吃蛇设计报告_第3页
第3页 / 共8页
Dos界面C++贪吃蛇设计报告_第4页
第4页 / 共8页
Dos界面C++贪吃蛇设计报告_第5页
第5页 / 共8页
点击查看更多>>
资源描述

《Dos界面C++贪吃蛇设计报告》由会员分享,可在线阅读,更多相关《Dos界面C++贪吃蛇设计报告(8页珍藏版)》请在金锄头文库上搜索。

1、第 1 页 共 10 页综合实验项目:贪吃蛇游戏 1、问题需求(1)控制游戏:按方向键 “ “,“ “,“ “,“ “能控制蛇的移动;(2)蛇在固定的范围内移动,不能碰触边界。不能撞到自身,否则,游戏结束。(3)固定范围内随机出现白子,蛇每吃一个白子长长一格,分数增加,每增加5 分蛇的移动速度自动增加。2、程序流程图3、详细设计设计说明:本程序运行代码如下:#include #include #include #include #include using namespace std; int score=0,t=300,f=1;/得分与时间间隔/ms (控制贪吃蛇的速度)double ss=

2、0,tt=0;/统计时间所用参数class Node 第 2 页 共 10 页Node(): x(0), y(0), prior(0), next(0) int x; int y; Node *prior; Node *next; friend class Snake; ; class Snake public: Snake(); Snake(); void output(); void move(); void change_point(char); private: Node *head; Node *tail; enum p UP, RIGHT, DOWN, LEFT point; /方

3、向int food_x, food_y; /食物的坐标static const int N = 23; int gameNN; void add_head(int, int); /添加坐标为a,b 的结点void delete_tail(); /删除最后一个结点void greate_food(); /产生食物void gotoxy(int, int); ; void menu(); / 游戏操作菜单int main() system(“color a“); / 初始 cmd窗口颜色为黑(背景)淡绿(文字)coutnext; delete temp; void Snake:add_head(i

4、nt a, int b) Node *temp = new Node; temp-x = a; temp-y = b; if (NULL = head) /如果头结点为空,那么就将这个点设为头结点 head = tail = temp; else /否则添加到头结点的前面,作为新的头结点 head-prior = temp; temp-next = head; head = head-prior; /这里 head前移,使 head一直指向头结点 gameab = 1; void Snake:delete_tail() Node *temp = tail; gametail-xtail-y =

5、 0; /将该结点的坐标对应的值置为tail = tail-prior; /tail尾结点前移,删除保存了原来尾结点的temp; 第 5 页 共 10 页tail-next = NULL; delete temp; void Snake:output() int i, j; gotoxy(0, 0); coutx; int b = head-y; switch (point) case UP: -a; break; case DOWN: +a; break; case RIGHT: +b; break; case LEFT: -b; break; if (1 = gameab gameover

6、(); if (a = food_x score+=f; if(score%5=0 system(“cls“); if(score=15) cout“nnnnnnn 太棒了,已经是最高时速了“endl; else cout“nnnnnnn 很不错,要加速了,请小心!“endl; Sleep(3000);system(“cls“);menu();ss-=3; greate_food(); return; add_head(a, b); delete_tail(); void Snake:greate_food() srand(unsigned(time(0); do food_x = rand(

7、) % 21 + 1; /产生 -21 的随机数food_y = rand() % 21 + 1; 第 7 页 共 10 页 while (1 = gamefood_xfood_y); /对应的坐标已经有点存在就重新产生食物gamefood_xfood_y = 1; /食物坐标对应的值赋为 void Snake:gotoxy(int x, int y) /定位光标 HANDLE hOutput; COORD loc; loc.X = x; loc.Y = y; hOutput = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleCursorPosition(hOutput, loc); 4、程序运行结果截图:游戏欢迎界面:(1)游戏运行界面:第 8 页 共 10 页(2)当前分数以及时间:(3) (4) 加速提示:(5) 速度最大时(得分 =15 分):

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 商业/管理/HR > 其它文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号