实训题目——数字迷宫——优秀
数字迷宫
相关文件下载到我的资源下载.
第一部分 案例描述
案例目的
本案例为实现动态的刷新Dos界面,使用用户控制头像“消灭”窗口中出现的数字(无固定顺序)的游戏,来使学员加深对一维数组、二维数组、循环语句、选择程序设计以及相关系统函数的使用。
案例难度
★★★★
案例覆盖技能点
a) 选择程序设计
b) 循环程序设计
c) 用户、屏幕窗口的输入输出
d) 相关系统函数
e) 一维、二维数组
推荐案例完成时间
4天
适用课程和对象
C语言案例(T阶段)
第二部分 需求和开发环境
使用技术和开发环境
Microsoft Visual C++ 6.0
案例需求
本案例要求制作一个《数字迷宫》的游戏,该游戏的玩法描述为:
1、 系统主要地图为固定模式
2、 地图内部包含墙体、走廊、阿拉伯数字(1~7)、玩家头像(1个)四种不同内容
3、 用户通过上、下、左、右按键来控制玩家头像在地图范围内的走动
4、 在玩家走动过程中,碰撞墙壁时,该步的走动无效,玩家头像原地不变
5、 玩家允许在设计走廊内部进行走动
6、 玩家头像遇到阿拉布数字时,数字消失,并且对玩家走动无影响
7、 玩家头像遭遇所有数字之后(地图上无阿拉伯数字),该局游戏结束,并自动开始下一局游戏
8、 在某一局游戏中,游戏走廊、墙体与其他游戏相同,但数字位置会随机产生
9、 阿拉伯数字产生在走廊内而非墙体上
10、 在玩家游戏过程中按下Esc键,游戏无条件退出。
11、 在玩家未使用Esc键时,程序正常运行
数字迷宫工作原理
1. 本程序分为初始——玩家运行——重启一局——结束四个阶段
a) 初始化阶段
i. 程序当中存在一18*24大小的固定地图数组
ii. 该数组以0/-1分别标识程序地图当中的“墙体”以及“走廊”
iii. 通过随机函数在走廊中产生1~7阿拉伯数字,并且将该系列数字写入二维数组的相应位置当中,对-1(走廊)进行覆盖
iv. 产生玩家位置:数组的(1,1)处
v. 使用循环语句遍历打印出数组元素,元素包括
1. 墙体(0):■
2. 走廊(-1): 空格*2
3. 数字(1~7):数字本身+空格*1
4. 玩家头像:\1 即:J+空格*1
b) 玩家运行阶段
i. 玩家使用上下左右键进行头像控制
ii. 与墙体碰撞时,走动无效,原地不动(通过玩家头像位置标示与数组内部数据是否为墙体(0)来判断)
iii. 为一般走廊时,玩家原头像位置清空为双空格(通过玩家头像位置标示与数组内部数据是否为走廊(-1)来判断),玩家当前位置输出玩家头像,并更新玩家头像位置全局变量。
iv. 为数字时(通过玩家头像位置标示与数组内部数据是否为数字(>0)来判断),该数字消失,玩家原位置头像消失,新位置出现玩家头像,并将数组内消失数字位置置为走廊(-1), 并更新玩家头像位置全局变量。
v. 每走动一次系统遍历数组元素,判断数字(>0)多少,当数字存在数量>0时,该局继续,=0时,进入重启一局步骤。
c) 重启一局
i. 重复初始化阶段(注意要移动头像到(1,1)位置)
d) 结束程序
i. 用户点击Esc或强行关闭应用程序时,程序无条件退出。
第三部分功能点介绍
头文件引用列表
头文件名 |
功能简述 |
#include <stdio.h> |
使用一般输入输出函数 |
#include <conio.h> |
使用getch函数达到输入数据不敲回车进行下步计算功能 |
#include <time.h> |
使用time(int)函数 |
#include "windows.h" |
使用光标移动函数对光标进行编码定位 |
系统函数使用列表
函数名称 |
功能简述 |
getch(); |
|
printf |
|
srand(); |
设置系统rand函数随机引资 |
time(NULL); |
以时间作为随机因子产生不重复的随机数,提高程序效率 |
rand() |
得到随机数 |
GetStdHandle |
得到该程序HANDLE的函数 |
GetLastError(); |
得到系统最近错误编号函数 |
SetConsoleCursorPosition(Handle, {x,y}); |
代码设置系统光标位置函数 |
公共变量列表
变量名称 |
初始值 |
功能简述 |
int code[17][24] |
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,-1,0,0,0,0,0,0,0,0,0,0,0,-1,0,0,0,0,0,0,0,0,0,0, 0,-1,-1,-1,-1,-1,-1,0,0,0,0,0,0,-1,0,0,0,0,0,-1,-1,-1,0,0, 0,-1,0,0,0,-1,0,0,0,0,0,0,0,-1,0,0,0,0,0,-1,0,0,0,0, 0,-1,-1,-1,-1,-1,0,-1,-1,-1,-1,-1,0,-1,0,-1,-1,-1,-1,-1,-1,-1,0,0, 0,-1,0,0,-1,0,-1,0,0,0,0,-1,0,-1,-1,-1,0,0,0,0,0,0,0,0, 0,-1,-1,-1,-1,-1,-1,0,0,0,0,-1,0,0,0,-1,0,0,0,0,0,0,0,0, 0,-1,0,0,0,0,0,0,0,0,0,-1,0,0,0,-1,-1,-1,-1,-1,-1,-1,-1,0, 0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,-1,0,0,-1,0,0,0,0, 0,0,0,0,0,0,-1,0,0,0,0,0,0,0,-1,0,-1,0,0,-1,0,0,0,0, 0,0,0,0,0,0,-1,0,0,0,0,0,0,0,-1,0,-1,-1,-1,-1,0,-1,-1,0, 0,0,0,0,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,0,0,0,-1,0,0, 0,0,0,0,0,-1,0,0,0,0,0,0,0,-1,0,0,0,0,0,0,0,-1,0,0, 0,0,-1,-1,-1,-1,0,0,0,0,0,0,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,0, 0,-1,-1,0,0,0,0,0,0,0,0,0,0,-1,0,0,0,0,0,0,0,0,0,0, 0,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, }; |
地图数组,0表示墙体,-1表示走廊 |
int postionX, postionY |
postionX=1; postionY=1; |
玩家的初始位置 |
函数功能列表
函数名称 |
功能简述 |
void main() |
程序接口函数,负责程序整体运行 |
void SetCode(int num); |
该函数通过传入的num值来判断并输出为:■,空格*2,或者数字本身 |
void SetWindow(); |
生成地图主体函数:遍历公共数组,在位置部位(1,1)时,调用SetCode函数,并在(1,1)位置输出玩家头像 |
void SetNum(); |
程序初始化时,用于使用随机函数在数组“走廊”位置生成1~7的阿拉伯数字 |
void Begin(); |
初始化主体函数,设置玩家头像初始位置,调用SetNum函数 |
void LeftKey(); void UpKey(); void DownKey() void RightKey(); |
玩家按下,上下左右按键时,分别调用的函数,该函数可判断玩家是否为被墙体阻挡、正常行走、“吃”掉数字三种状态,并改变玩家头像的位置。 |
int CheckLeftNum(); |
该函数判断数组内剩余的数字(>0)数量,返回该数量 |
void GoToXY(int x, int y); |
该函数用于在x,y位置输出用户头像 |
void GoToXYSpace(int x, int y); |
/*
**项目名称:数字迷宫
**开发负责人:武志祥
**开发日期:2017/7/8 - 2017/7/11
**盗版必究!!!!!!!
*/
#include <stdio.h>
#include <windows.h>
#include <conio.h>
#include <time.h>
#include <queue>
#define ROWS 24
#define COLUMN 60using namespace std;
int score = 0,score2 = 0; //分数记录
int step = 0, step2 = 0; //记录步数
int postionX = -1, postionY = -1; //玩家1的位置
int postionX2 = -1, postionY2 = -1; //玩家2 或 电脑的位置
int sum; //剩余数字的数量
int sound = 1; //是否开启声音,默认开启
int numnum = 7; //生成数字的数量bool visit[17][24]; //记录点是否被访问过
typedef struct point
{int x,y;struct point *pre;int step;
} point; //记录路径struct node
{int x;int y;
} path[100]; // 记录最短路径
int l = 0; //最短路径的长度
int dirt[4][2] =
{{0,-1},{0,1},{-2,0},{2,0}
};//行走的方向
int code[17][24] =
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-1,0,0,0,0,0,0,0,0,0,0,0,-1,0,0,0,0,0,0,0,0,0,0,0,-1,-1,-1,-1,-1,-1,0,0,0,0,0,0,-1,0,0,0,0,0,-1,-1,-1,0,0,0,-1,0,0,0,-1,0,0,0,0,0,0,0,-1,0,0,0,0,0,-1,0,0,0,0,0,-1,-1,-1,-1,-1,0,-1,-1,-1,-1,-1,0,-1,0,-1,-1,-1,-1,-1,-1,-1,0,0,0,-1,0,0,-1,0,-1,0,0,0,0,-1,0,-1,-1,-1,0,0,0,0,0,0,0,0,0,-1,-1,-1,-1,-1,-1,0,0,0,0,-1,0,0,0,-1,0,0,0,0,0,0,0,0,0,-1,0,0,0,0,0,0,0,0,0,-1,0,0,0,-1,-1,-1,-1,-1,-1,-1,-1,0,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,-1,0,0,-1,0,0,0,0,0,0,0,0,0,0,-1,0,0,0,0,0,0,0,-1,0,-1,0,0,-1,0,0,0,0,0,0,0,0,0,0,-1,0,0,0,0,0,0,0,-1,0,-1,-1,-1,-1,0,-1,-1,0,0,0,0,0,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,0,0,0,-1,0,0,0,0,0,0,0,-1,0,0,0,0,0,0,0,-1,0,0,0,0,0,0,0,-1,0,0,0,0,-1,-1,-1,-1,0,0,0,0,0,0,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,0,0,-1,-1,0,0,0,0,0,0,0,0,0,0,-1,0,0,0,0,0,0,0,0,0,0,0,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
}; //地图数据
int code2[17][24]; //记录生成的数字位置
void ShowMain(); // 主菜单
void Begin(); // 单人模式初始化
void Operation(); // 单模式操作
void GoToXYSpace(int x, int y,int mode); // 输出空格
void Go(int x,int y); // 移动光标
void Print(int x,int y,const char words[]); //输出一段话
void GoToXY(int x, int y); // 输出头像
void HideCursor(); // 隐藏光标
void SetCode(int num); // 判断地图的每个点应该输出什么
void border(); // 地图边框
void SetWindow(); // 打印地图
int PositionCheck(int x,int y,int id); //碰撞检测
void UpKey(int *x,int *y,int id); // 上
void DownKey(int *x,int *y,int id); //下
void LeftKey(int *x,int *y,int id); //左
void RightKey(int *x,int *y,int id); //右
void SetNum(int mode); // 生成随机数
void loading(); // 加载进度条
int CheckLeftNum(); // 检查剩余随机数的数量
void help(); // 帮助函数
void Setting(); // 设置函数
void DoubleBegin(); // 双人模式初始化
void DoubleOperation(); // 双人模式操作
bool judge(point each); // bfs 检测
void PrintPath(point *p); // 把最短路径保存到数组
point bfs(point start); // 宽度优先搜索
void Operationrj(); // 人机模式操作
void Rjbegin(); // 人机模式初始化
void init();//分数归零int main()
{system("mode con cols=100 lines=26"); //设置窗口的大小HideCursor();////ShowMain();help();
}//输出空格覆盖上次的头像
void GoToXYSpace(int x, int y,int mode)
{COORD c;c.X=x;c.Y=y;SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),c);if(mode==1){if(!(x==postionX2&&y==postionY2))printf(" ");}else if(mode==2){if(!(x==postionX&&y==postionY))printf(" ");}}//移动光标
void Go(int x,int y)
{COORD c;c.X=x;c.Y=y;SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),c);
}//在指定的位置输出一段话
void Print(int x,int y,const char words[])
{Go(x,y);printf("%s",words);
}//在指定位置输出玩家的头像
void GoToXY(int x, int y,int mode)
{Go(x,y);if(mode==1)printf("\1");else if(mode==2)printf("\2");
}
//隐藏光标
void HideCursor()
{CONSOLE_CURSOR_INFO cursor_info = {1, 0};SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}
//判断地图位置的状态
void SetCode(int num)
{if(num == 0)printf("■");else if(num==-1)printf(" ");
}
//输出外边界
void border()
{int i;Print(4,2,"■");for(i = 0; i<COLUMN; i+=2){printf("■");//Sleep(5);}for(i = 2; i<ROWS; i++){Print(COLUMN+4,i,"■");//Sleep(5);}for(i = COLUMN+4; i>=4; i-=2){Print(i,ROWS,"■");//Sleep(5);}for(i = ROWS; i>=2; i--){Print(4,i,"■");//Sleep(5);}
}
//输出地图
void SetWindow()
{int i,j;border();for(i = 0; i<17; i++){Go(11,i+5);for(j = 0; j<24; j++){SetCode(code[i][j]);}printf("\n");}
}//检查制定位置是否可以到达
int PositionCheck(int x,int y,int id)
{x=((x-11)/2);y=y-5;if(code[y][x]==0){if(sound)Beep(20,200);return 0;}else if(code2[y][x]>0||code2[y][x]==-1){if(id==1)score += 10;elsescore2 += 10;sum--;code2[y][x]=0;}if(id==1)step ++;elsestep2++;return 1;
}
//向上移动
void UpKey(int *x,int *y,int id)
{if(PositionCheck(*x,(*y)-1,id)){GoToXYSpace(*x,*y,id);GoToXY(*x,--(*y),id);}
}
//向下移动
void DownKey(int *x,int *y,int id)
{if(PositionCheck(*x,*y+1,id)){GoToXYSpace(*x,*y,id);GoToXY(*x,++(*y),id);}
}
//向左移动
void LeftKey(int *x,int *y,int id)
{if(PositionCheck((*x)-2,*y,id)) //{GoToXYSpace(*x,*y,id);(*x)-=2;GoToXY(*x,*y,id);}
}
//向右移动
void RightKey(int *x,int *y,int id)
{if(PositionCheck(*x+2,*y,id)) //{GoToXYSpace(*x,*y,id);(*x)+=2;GoToXY(*x,*y,id);}
}
//生成随机数
void SetNum(int mode)
{srand((unsigned) time(NULL));sum = 0;int x,y;while(sum<numnum){x = rand()%44 + 13;if(x%2==0)x--;y = rand()%15 + 6;if((y==6&&x==13)||(y==6&&x==14)){continue;}if((y==7&&x==53)||(y==7&&x==54)){continue;}if(code[y-5][(x-11)/2]==-1&&code2[y-5][(x-11)/2]==0){Go(x,y);code2[y-5][(x-11)/2] = sum+1;printf("%d",sum+1);sum++;}}
}//loding
void loading()
{int i;Print(35,9,"游戏加载中\n");Print(12,13,"|");Print(12,14,"|");Print(12,15,"|");for(i = 0; i<56; i++){Print(13+i,13,"-");Print(13+i,15,"-");}Print(69,13,"|");Print(69,14,"|");Print(69,15,"|");for(i = 0; i<56; i+=2){Print(i+13,14,"■");Sleep(20);}Print(30,16,"加载完成!尽情享受吧!");Sleep(1500);
}
//游戏初始化
void Begin()
{init();int i,j;system("cls");loading();system("cls");postionX = 13;postionY = 6;for(i = 0; i<24; i++){for(j = 0; j<17; j++){code2[j][i] = 0;}}SetWindow();SetNum(0);GoToXY(postionX,postionY,1);Print(70,6,"得分");Print(80,6,"步数");Print(70,15,"按 W A S D 键移动");Go(71,7);printf("%d",score);Go(81,7);printf("%d",step);Operation();
}//检查剩余的数字数量
int CheckLeftNum()
{return sum;
}
//游戏中具体操作的判断
void Operation()
{while(true){int cmd;cmd = getch();if(cmd==27){system("cls");postionX = -1, postionY = -1; //玩家的位置postionX2 = -1, postionY2 = -1;ShowMain();break;}else if(cmd == 119) //{UpKey(&postionX,&postionY,1);}else if(cmd == 115) //{DownKey(&postionX,&postionY,1);}else if(cmd == 97) //{LeftKey(&postionX,&postionY,1);}else if(cmd == 100){RightKey(&postionX,&postionY,1);}Go(71,7);printf("%d",score);Go(81,7);printf("%d",step);if(CheckLeftNum()==0){system("cls");Print(25,9,"游戏胜利,新的一局马上开始!\n");Sleep(1000);break;}}Begin();
}
//帮助函数
void help()
{system("cls");border();Print(15,4,"基本操作介绍: 按Esc键返回主菜单");Print(10,6,"主菜单:用↑ ↓ 键移动光标选择");Print(10,8,"按enter键确认你的选择!");Print(10,10,"游戏中:↑ ↓ ← → 或 w a s d 功能键移动游戏中的人物,");Print(10,12,"具体操作看游戏中的要求");Print(10,14,"吃掉所有的数字后,游戏成功!开始下一局,规则不变。");Print(10,16,"设置:可以设置生成数字的数量。和声音的开关");Print(10,18,"请仔细阅读,按Esc键返回主菜单。开始游戏吧!!");int cmd;while(true){cmd = getch();if(cmd==27){system("cls");ShowMain();}}
}
//游戏设置
void Setting()
{char num[50];int cmd;system("cls");border();int index = 5;Print(30,5,"设置生成数的数量");if(sound){Print(34,6,"关闭声音");}else{Print(34,6,"开启声音");}Print(27,index,"<");Print(48,index,">");while(true){cmd = getch();Print(27,index," ");Print(48,index," ");if(cmd == 72){if(index>5){index--;}}else if(cmd==80){if(index<6){index++;}}else if(cmd == 13){break;}else if(cmd == 27){ShowMain();}Print(27,index,"<");Print(48,index,">");}if(index==5){system("cls");while(1){Print(20,5,"输入生成数字的数量(1-9)___:");scanf("%s",num);if(strlen(num)==1){if(num[0]-'0'<1||num[0]-'0'>9){Print(25,8,"数据有误!重新输入");Print(45,5," ");continue;}else{Print(25,8," ");Print(20,8,"设置成功,按任意键返回主页面");getch();numnum = num[0] - '0';ShowMain();}}else{Print(25,8,"数据有误,重新输入__");Print(45,5," ");continue;}}}else if(index==6){system("cls");sound = !sound;Print(20,8,"设置成功,按任意键返回主页面");getch();ShowMain();}}
//双人模式初始化
void DoubleBegin()
{init();int i,j;system("cls");loading();system("cls");postionX = 13;postionY = 6;for(i = 0; i<24; i++){for(j = 0; j<17; j++){code2[j][i] = 0;}}SetWindow();SetNum(1);postionX2 = 53, postionY2 = 7;GoToXY(postionX,postionY,1);GoToXY(postionX2,postionY2,2);Print(70,6,"玩家1");Print(71,7,"\1");Print(80,6,"得分");Print(90,6,"步数");Go(81,7);printf("%d",score);Go(91,7);printf("%d",step);Print(70,11,"玩家2");Print(71,12,"\2");Print(80,11,"得分");Print(90,11,"步数");Print(70,15,"玩家 1 按 W A S D 键移动");Print(70,16,"玩家 2 按 ↑ ↓ ← → 键移动");Go(81,12);printf("%d",score2);Go(91,12);printf("%d",step2);DoubleOperation();
}
//双人模式操作
void DoubleOperation()
{while(true){int cmd;cmd = getch();if(cmd==27){system("cls");postionX = -1, postionY = -1; //玩家的位置postionX2 = -1, postionY2 = -1;ShowMain();break;}else if(cmd == 72) //{UpKey(&postionX2,&postionY2,2);}else if(cmd == 80) //{DownKey(&postionX2,&postionY2,2);}else if(cmd == 75) //{LeftKey(&postionX2,&postionY2,2);}else if(cmd == 77){RightKey(&postionX2,&postionY2,2);}else if(cmd == 119) //{UpKey(&postionX,&postionY,1);}else if(cmd == 115) //{DownKey(&postionX,&postionY,1);}else if(cmd == 97) //{LeftKey(&postionX,&postionY,1);}else if(cmd == 100){RightKey(&postionX,&postionY,1);}Go(81,7);printf("%d",score);Go(91,7);printf("%d",step);Go(81,12);printf("%d",score2);Go(91,12);printf("%d",step2);if(CheckLeftNum()==0){system("cls");if(score>score2)Print(25,9,"玩家 1 胜利,开始新一局较量吧!\n");else if(score<score2){Print(25,9,"玩家 2 胜利,开始新一局较量吧!\n");}else{Print(25,9,"分数相等哎,开始新一局较量吧!\n");}Sleep(1000);break;}}DoubleBegin();
}//主菜单bool judge(point each)//判断访问的点是否合法
{if(each.x>=11&&each.x<57&&each.y>=5&&each.y<22&&code[each.y-5][(each.x-11)/2]==-1){return true;}elsereturn false;
}
//输出最短路径到数组
void PrintPath(point *p)
{//int minstep = p->step;while(p->pre!=NULL){//GoToXY(p->x,p->y);path[l].x = p->x;path[l++].y = p->y;//cout<<"("<<p->x<<","<<p->y<<")"<<endl;p=p->pre;}path[l].x = p->x;path[l++].y = p->y;//GoToXY(p->x,p->y);//cout<<"("<<p->x<<","<<p->y<<")"<<endl;}
//广度优先搜索
point bfs(point start)
{queue<point> q;q.push(start);point cur;memset(visit,false,sizeof(visit));while(!q.empty()){cur = q.front();q.pop();//if(code2[f.y-5][(f.x-11)/2]>0)//return f.step;visit[cur.y-5][(cur.x-11)/2] = true;for(int i = 0; i<4; i++){//printf("123");point next = cur;next.x += dirt[i][0];next.y += dirt[i][1];next.step = 0;next.pre = NULL;if(judge(next)&&!visit[next.y-5][(next.x-11)/2]){point *tmp = new point;memcpy(tmp,&cur,sizeof(point));next.pre = tmp;next.step = cur.step+1;visit[next.y-5][(next.x-11)/2] = 1;if(code2[next.y-5][(next.x-11)/2]>0){PrintPath(&next);code2[next.y-5][(next.x-11)/2] = -1;return next;}q.push(next);}}}return start;
}//人机操作
void Operationrj()
{while(1){int cmd;cmd = getch();if(cmd==27){system("cls");postionX = -1, postionY = -1; //玩家的位置postionX2 = -1, postionY2 = -1;ShowMain();}else if(cmd == 119) //{UpKey(&postionX,&postionY,1);break;}else if(cmd == 115) //{DownKey(&postionX,&postionY,1);break;}else if(cmd == 97) //{LeftKey(&postionX,&postionY,1);break;}else if(cmd == 100){RightKey(&postionX,&postionY,1);break;}//Go(81,7);//printf("%d",score);//Go(91,7);//printf("%d",step);if(sum==0){system("cls");Print(25,9,"游戏胜利,新的一局马上开始!\n");Sleep(1000);}}//Begin();
}
//人机模式初始化
void Rjbegin()
{init();system("cls");loading();system("cls");for(int i = 0; i<17; i++){for(int j = 0; j<24; j++)code2[i][j]=0;}point start;start.x = 53;start.y = 7;start.step = 0;start.pre = NULL;SetWindow();SetNum(2);postionX = 13, postionY = 6;postionX2 = 53, postionY2 = 7;GoToXY(postionX2,postionY2,2);GoToXY(postionX,postionY,1);start = bfs(start);start.pre = NULL;start.step = 0;//printf("%d %d",start.x,start.y);Print(70,15,"玩家 按 W A S D 键移动");Print(71,7,"玩家");Print(72,8,"\1");Print(71,10,"电脑");Print(72,11,"\2");Print(81,7,"得分");Print(81,10,"得分");Print(91,7,"步数");Print(91,10,"步数");Go(81,8);printf("%d",score);Go(91,8);printf("%d",step);Go(81,11);printf("%d",score2);Go(91,11);printf("%d",step2);while(sum>0){for(int i = l-1; i>=0; i--){GoToXYSpace(path[i+1].x,path[i+1].y,2);GoToXY(path[i].x,path[i].y,2);step2++;if(code2[path[i].y-5][(path[i].x-11)/2]==-1){score2+= 10;sum--;code2[path[i].y-5][(path[i].x-11)/2]=0;}if(code2[start.y-5][(start.x-11)/2]==0){start.x = path[i].x;start.y = path[i].y;break;}elseOperationrj();Go(81,8);printf("%d",score);Go(91,8);printf("%d",step);Go(81,11);printf("%d",score2);Go(91,11);printf("%d",step2);}l = 0;start = bfs(start);start.pre = NULL;start.step = 0;}system("cls");if(score>score2)Print(25,9,"玩家 胜利,开始新一局较量吧!\n");else if(score<score2){Print(25,9,"电脑 胜利,开始新一局较量吧!\n");}else{Print(25,9,"分数相等哎,开始新一局较量吧!\n");}Sleep(1500);Rjbegin();
}
//主菜单
void ShowMain()
{system("cls");border();int index = 5,cmd;Print(30,5,"单人模式");Print(30,6,"双人模式");Print(30,7,"人机模式");Print(32,8,"帮助");Print(32,9,"设置");Print(32,10,"退出");Print(27,index,"<");Print(40,index,">");Print(25,15,"按 ↑ ↓ 键选择!");while(true){cmd = getch();if(cmd==72){if(index>5){Print(27,index," ");Print(40,index," ");index--;Print(27,index,"<");Print(40,index,">");}}else if(cmd==80){if(index<10){Print(27,index," ");Print(40,index," ");index++;Print(27,index,"<");Print(40,index,">");}}else if(cmd==13){break;}}switch(index){case 5:Begin();break;case 6:DoubleBegin();break;case 7:Rjbegin();break;case 8:help();break;case 9:Setting();break;case 10:system("cls");exit(1);break;}
}
// 分数步数初始化
void init()
{score = score2 = 0;step = step2 = 0;
}
实训题目——数字迷宫——优秀相关推荐
- 实训项目 数字迷宫小游戏
数字迷宫 第一部分 案例描述 案例目的 本案例为实现动态的刷新Dos界面,使用用户控制头像"消灭"窗口中出现的数字(无固定顺序)的游戏,来使学员加深对一维数组.二维数组.循环语句. ...
- c语言程序设计中北大学,《中北大学软件学院2013届C语言程序设计实训题目.doc...
<中北大学软件学院2013届C语言程序设计实训题目 C语言程序课程设计题目 (孟龙)题目1:年历显示 功能要求: 输入一个年份,输出是在屏幕上显示该年的日历.假定输入的年份在1940-2040年 ...
- 中北c语言程序设计,中北大学软件学2013届C语言程序设计实训题目.doc
中北大学软件学2013届C语言程序设计实训题目 C语言程序课程设计题目 (孟龙)题目1:年历显示 功能要求: 输入一个年份,输出是在屏幕上显示该年的日历.假定输入的年份在1940-2040年之间. 输 ...
- 转专业考试c语言试题,C语言程序设计实训题目.doc
C语言程序设计实训题目 C语言程序课程设计题目 题目1:年历显示 功能要求: 输入一个年份,输出是在屏幕上显示该年的日历.假定输入的年份在1940-2040年之间. 输入年月,输出该月的日历. 输入年 ...
- c语言 电报翻译的题目,C语言程序设计实训题目.doc
C语言程序设计实训题目.doc C语言程序课程设计题目题目1年历显示功能要求(1) 输入一个年份,输出是在屏幕上显示该年的日历.假定输入的年份在1940-2040年之间.(2) 输入年月,输出该月的日 ...
- c语言编写加油站课设题目,城市学院c语言实训题目求答案.doc
城市学院c语言实训题目求答案 <C程序设计>题目 任务训练: 剪刀.石头.布游戏 [掌握编程的基本思路与方法.分析数据.算法(操作.控制)] 模拟该游戏的进行.要求有提示信息表征游戏进行和 ...
- Java语言程序设计实训题目练习
前言:这是怀化学院Java实训平台实训题目总目录 说明:怀化学院的Java实训平台JDK是1.6,相信各位都知道这是什么概念吧,也就是说许多新特性在这个平台用不了,同时平台还有一定的缺陷,只能告诉你答 ...
- 用python写银行叫号系统(这个是学校的实训题目,真的没什么技术含量)
一. 项目概述 智能排队叫号系统是在银行等待业务办理区域所使用的智能叫号系统,系统可有效解决客户办理业务时排队的无序.业务员工作量的不平衡.就诊环境嘈杂等问题. 二. 需求分析 主要分为取号.排队等待 ...
- 设计c语言程序得到回文数,C语言程序设计实训题目.pdf
C语言程序课程设计题目 题目1:年历显示 功能要求: (1) 输入一个年份,输出是在屏幕上显示该年的日历.假定输入的年份在1940-2040年之间. (2) 输入年月,输出该月的日历. (3) 输入年 ...
最新文章
- Python使用Redis实现IP代理池
- docker(3)docker下的centos7下安装jdk
- java网络编程之TCP通讯
- 最好用的 Python 虚拟环境,没有之一
- 实例57:python
- 如何在IIS上配置多个网站,及网站发布配置讲解
- java 多态 重载的区别_重写、覆盖、重载、多态几个概念的区别分析
- kubernetes视频教程笔记 (31)-安全-鉴权Authorization
- 微信小程序模板文件的引入
- 2004-2020年数学建模美赛O奖论文合集(免费)
- 计算机图形图像设计构图的基本形式,设计构图的八大基本表现手法!你造吗?...
- 二、循环神经网络(RNN与LSTM)
- Android最新API获取北斗卫星定位信息(全网最新)
- Linux下vi使用手册
- 透过J2Cache的吐槽,领悟代码的设计
- java笔试题分类集锦
- hadoop成功启动后,重新formatamp;nbs…
- C#深入学习--委托
- 独立开发者接入防沉迷尽然如此简单?-TapTap 防沉迷模块Android版
- ORACLE甚而,PL/SQL基础