湖南人文科技学院 数据结构课程设计
课程名称 题 目 年级/专业/班 组长姓名(学号) 成员姓名(学号)
数据结构课程设计 校园导游咨询系统 14级信工系网工二班 刘贵成(14420221)
康子祺(14420211)
何旭亚(14420206) 罗豪(14420233)
: : :
: :
湖南人文科技学院·课程设计
《数据结构》课程设计
--校园导游咨询系统设计
一、引 言
随着现代社会生活节奏的加快,人们外出旅行以寻求放松的时间越来越多。考虑到游客不可能对所有景点都有所了解,因此可能无法找到游玩景点最省时,最高效的路径,而人工导游成本又过高,故使用C++,基于《数据结构》中图的相关算法与HGE引擎的窗口界面开发了“湖南人文科技学院导游咨询系统”。
开发本系统目的在于为来访我校的游客提供一条最短游览路径,本系统从实际出发,通过对校园平面图的分析,将其转化为数据并保存在系统中,因此系统提供的路径具有较大的可信性。而且本系统使用引擎创建窗口,更加方便,更加美观,更加易懂。
本系统界面友好,提示信息充分,在实际使用过程中运行良好。
二、设计目的与任务
1、设计目的:
通过本课程设计教学所要求达到的目的是:巩固和加深对数据结构的理解,通
过上机实验、调试程序,加深对课本知识的理解;能熟练掌握几种基本数据结构的基本操作;能针对给定题目,选择相应的数据结构,分析并设计算法,进而给出问题的正确求解过程并编写代码实现。能简单的运用HGE引擎创建窗口,更好地实现校园导游咨询功能。 2、设计任务:
校园导游程序:用窗口界面实现以下功能: (1)景点信息的查询和简介; (2)两景点间路径的查询;
(3)增加、删除、更新有关景点和道路的信息。
湖南人文科技学院·课程设计
三、设计方案与实施(小三号、黑体、加粗) (一级标题)
1、总体设计//写总体的设计思想
根据题目要求,程序需要实现校园景点的信息查询和修改。首先使用HGE引擎创建基本的窗口界面,定义一个二维数组(40X40)来表示地图的属性,,然后从文件中加载一张图片并用纹理句柄保存,再创建一个精灵,并绑定一张纹理图片等来将图片设置进窗口界面。再建立更新函数和渲染函数来进行逻辑处理(获取鼠标位置,获取图片的矩形区域,判断一个点是否在矩形中,判断鼠标是否在增加删除选项框内,判断鼠标是否在增加删除选项框内)和显示(背景,颜色,景点名字,景点坐标,景点简介等)
在窗口查询中,全是用鼠标来实现景点简介、景点间路径、景点和道路的增加、删除、更新等操作,方便易懂又美观。景点简介的查询是:将鼠标放在景点上就会实现;景点间路径的查询是:用鼠标在已有道路上点出起点和终点,就会自动计算出最短路径并且显示在右边的路径框上;景点和道路的增加、删除、更新:用鼠标点击已有的两个编辑按钮来实现对地图上的修改。
2、详细设计
(1)HGE的应用
HGE *hge = 0;//定义一个全局变量:hge引擎指针 hgeFont* pFont;
hgeSprite *sprite = NULL;//精灵指针:(指向一张图片) HTEXTURE tex = NULL;//纹理句柄(对应一张图片)
hgeSprite *sprite_1 = NULL;//精灵指针:(指向一张图片) HTEXTURE tex_1 = NULL;//纹理句柄(对应一张图片)
hgeSprite *sprite_2 = NULL;//精灵指针:(指向一张图片) HTEXTURE tex_2 = NULL;//纹理句柄(对应一张图片)
hgeSprite *sprite_menu = NULL;//精灵指针:开始按钮 HTEXTURE tex_menu = NULL;//纹理句柄(开始)
hgeSprite *sprite_3 = NULL; HTEXTURE tex_3 = NULL;
hgeSprite* sprite_4 = NULL; HTEXTURE tex_4 = NULL;
hgeSprite* sprite_5 = NULL; HTEXTURE tex_5 = NULL;
湖南人文科技学院·课程设计
hgeSprite* sprite_6 = NULL; HTEXTURE tex_6 = NULL;
GfxFont *g_pGfxFont0 = NULL;//中文显示 GfxFont *g_pGfxFont1 = NULL;//中文显示
GfxFont* p_Font = NULL; //创建一个字体指针 GfxFont* p_Font_1 = NULL; GfxFont* p_Font_2 = NULL;
float scaling_1 = 1.0f;//设置按钮缩放比列 float scaling_2 = 1.0f; float scaling_3 = 1.0f;
(2)更新函数(逻辑处理): bool FrameFunc() { hge->Effect_PlayEx(heffect, 20);//播放音效: if (hge->Input_KeyDown(HGEK_ESCAPE))//返回值为true,程序结束:按下ESC键 return true; switch (gamestate) { case Start: if (hge->Input_KeyDown(HGEK_LBUTTON)) { hge->Input_GetMousePos(&mouse_x, &mouse_y);//获取鼠标的位置 sprite_menu->GetBoundingBox(300, 100, &rect_menu);//获取图片的矩形区域 if (rect_menu.TestPoint(mouse_x, mouse_y))//判断一个点是否在矩形中 gamestate = Play; } b_state = false; break; case Play: if (hge->Input_KeyDown(HGEK_LBUTTON)) { if (changestate==Add) { hge->Input_GetMousePos(&mouse_x, &mouse_y); x_1 = (int)(mouse_y - 100) / 16;//16表示图片的高 y_1 = (int)(mouse_x - 100) / 16;//16表示图片的宽
湖南人文科技学院·课程设计
n[x_1][y_1] = 1; n1[x_1][y_1] = 1;
}
else if (changestate == Del) { hge->Input_GetMousePos(&mouse_x, &mouse_y); x_1 = (int)(mouse_y - 100) / 16;//16表示图片的高 y_1 = (int)(mouse_x - 100) / 16;//16表示图片的宽 n[x_1][y_1] = 0; n1[x_1][y_1] = 0; }
hge->Input_GetMousePos(&mouse_x, &mouse_y);//获取鼠标的位置 sprite_5->GetBoundingBox(750, 500, &rect_5);//获取图片的矩形区域 sprite_6->GetBoundingBox(750, 550, &rect_6); if (rect_5.TestPoint(mouse_x, mouse_y))//判断鼠标是否在增加删除选项框内 { scaling_1 = 1.2f;; changestate = Add; } else if (rect_6.TestPoint(mouse_x, mouse_y)) { scaling_2 = 1.2f; changestate = Del; } }
if (hge->Input_KeyUp(HGEK_LBUTTON)) { hge->Input_GetMousePos(&mouse_x, &mouse_y);//获取鼠标的位置 sprite_5->GetBoundingBox(750, 500, &rect_5);//获取图片的矩形区域 sprite_6->GetBoundingBox(750, 550, &rect_6); if (rect_5.TestPoint(mouse_x, mouse_y))//判断鼠标是否在增加删除选项框内 scaling_1 = 1.0f; else if (rect_6.TestPoint(mouse_x, mouse_y)) scaling_2 = 1.0f; }
hge->Input_GetMousePos(&mouse_x, &mouse_y);
if (mouse_x > 510 && mouse_x < 540 && mouse_y >410 && mouse_y < 440) IsShow = true; else IsShow = false;
湖南人文科技学院·课程设计
if (mouse_x >510 && mouse_x < 550 && mouse_y >300 && mouse_y < 340) IsShow_1 = true; else IsShow_1 = false; if (mouse_x >410 && mouse_x < 450 && mouse_y >310 && mouse_y < 350) IsShow_2=true; else IsShow_2 = false; if (mouse_x >225 && mouse_x < 265 && mouse_y >130 && mouse_y < 170) IsShow_3=true; else IsShow_3 = false; if (mouse_x >310 && mouse_x < 350 && mouse_y >540 && mouse_y < 580) IsShow_4=true; else IsShow_4 = false; if (mouse_x >400 && mouse_x < 440 && mouse_y >610 && mouse_y < 650) IsShow_5=true; else IsShow_5 = false; if (mouse_x >315 && mouse_x < 355 && mouse_y >430 && mouse_y < 470) IsShow_6=true; else IsShow_6 = false; if (mouse_x >200 && mouse_x < 240 && mouse_y >430 && mouse_y < 470) IsShow_7=true; else IsShow_7 = false; if (mouse_x >400 && mouse_x < 440 && mouse_y >405 && mouse_y < 445) IsShow_8=true; else IsShow_8 = false; if (mouse_x >645 && mouse_x < 685 && mouse_y >380 && mouse_y < 420) IsShow_9=true; else IsShow_9 = false; if (hge->Input_GetKeyState(HGEK_RBUTTON) && b_state == false)//判断鼠标左键是否按下,按下开始导游 { b_state = TRUE; hge->Input_GetMousePos(&mouse_x, &mouse_y); end_x = (int)(mouse_y - 100) / 16;//16表示图片的高 end_y = (int)(mouse_x - 100) / 16;//16表示图片的宽
湖南人文科技学院·课程设计
} if (hge->Input_GetKeyState(HGEK_SPACE)) { step = 0; memcpy(n, n1, sizeof(n)); x = end_x; y = end_y; point *start = (point*)malloc(sizeof(point));//起点 start->x = x; start->y = y; n[x][y] = 3; if (x != 1 && y != 1) n[1][1] = 0; q.push(start); } if (b_state) { while (!q.empty()){ point *front = q.front(); q.pop();//弹出队头 if (front->x == end_x &&front->y == end_y) { flag = 1; //cout<<\"成功找到出路.\"<<\"最少需要\"< 湖南人文科技学院·课程设计 front = front->last; } //cout<<\"->\"< 湖南人文科技学院·课程设计 { hge->Gfx_BeginScene();//通知系统开始绘制 hge->Gfx_Clear(0xFFFFFFFF);// 清屏(屏幕的背景颜色,每两位:红、绿、蓝) switch (gamestate)//自己的绘制: { case Start: sprite_4->Render(0, 0); sprite_menu->RenderEx(300, 100,0.0f,1.0f,1.0f); break; case Play: sprite_3->Render(0, 0);//绘制背景 sprite_5->RenderEx(795, 515, 0.0f, scaling_1, scaling_1);//绘制按钮 sprite_6->RenderEx(795, 565, 0.0f, scaling_2, scaling_2 );//绘制按钮 for (int i = 0; i<40; ++i)//遍历数组的元素并根据其值绘制图形 { for (int j = 0; j<40; ++j) { switch (n[i][j]) { case 0://sprite_1->Render(j*16,i*16); break; case 1://第一个参数表示x坐标,第二参数y坐标 sprite->Render(100 + j * 16, 100 + i * 16); break; case 2://第一个参数表示x坐标,第二参数y坐标 sprite_1->Render(100 + j * 16, 100 + i * 16); break; case 3://第一个参数表示x坐标,第二参数y坐标 sprite_2->Render(100 + j * 16, 100 + i * 16); break; } } } p_Font_2->Render(750, 400, L\"距离 米\"); p_Font_2->Print(790, 400, \" %d\ p_Font_1->Render(200, 50, L\"湖南人文科技学院导游图\"); p_Font->Render(248, 150, L\"阳\\n光\\n公\\n寓\"); //设置字体的位置 p_Font->Render(220, 450, L\"体\\n育\\n馆\"); //设置字体的位置 p_Font->Render(335, 450, L\"田\\n径\\n场\"); //设置字体的位置 p_Font->Render(525, 425, L\"海园广场\"); //设置字体的位置 p_Font->Render(530, 320, L\"致远楼\"); //设置字体的位置 p_Font->Render(430, 330, L\"图\\n书\\n馆\"); //设置字体的位置 p_Font->Render(420, 425, L\"生活\\n服务\\n大楼\"); //设置字体的位置 湖南人文科技学院·课程设计 p_Font->Render(420, 630, L\"逸\\n夫\\n楼\"); //设置字体的位置 p_Font->Render(330, 560, L\"惠风\\n篮球场\"); //设置字体的位置 p_Font->Render(670, 360, L\"毓\\n师\\n园\"); //设置字体的位置 if (IsShow) { p_Font_2->Render(mouse_x,mouse_y,L\"休闲散步的最佳场所\"); } if (IsShow_1) { p_Font_2->Render(mouse_x, mouse_y, L\"全校最大的一栋综合教学楼,\\n各系上课得主要场所\"); } if (IsShow_2) { p_Font_2->Render(mouse_x, mouse_y, L\"学校的心脏,藏有图书上百万册,\\n三楼为咖啡书吧,环境优雅\"); } if (IsShow_3) { p_Font_2->Render(mouse_x, mouse_y, L\"全校最豪华的学生公寓,共有六栋,\\n有标准四人寝和豪华两人寝\"); } if (IsShow_4) { p_Font_2->Render(mouse_x, mouse_y, L\"全校最大篮球场,挥洒汗水的赛场\"); } if (IsShow_5) { p_Font_2->Render(mouse_x, mouse_y, L\"学校最具艺术色彩的一栋大楼\"); } if (IsShow_6) { p_Font_2->Render(mouse_x, mouse_y, L\"现在化塑胶标准报道,人造草坪,\\n适宜锻炼身体的场所\"); } if (IsShow_7) { p_Font_2->Render(mouse_x, mouse_y, L\"举办各种大型比赛和开展大型活动的场所,\\n能容纳五千多人\"); } if (IsShow_8) { p_Font_2->Render(mouse_x, mouse_y, L\"为学生和老师提供生活服务的地方\"); } 湖南人文科技学院·课程设计 if (IsShow_9) { p_Font_2->Render(mouse_x, mouse_y, L\"绿树成荫,幽静小道,适宜读书和休息\"); } break; } hge->Gfx_EndScene();//通知系统结束绘制 return false; } (4)主函数(入口函数) int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) { hge = hgeCreate(HGE_VERSION);//hge指针赋值。 hge->System_SetState(HGE_FRAMEFUNC, FrameFunc);// 设置自己的更新函数//第二个参数是函数的名字 hge->System_SetState(HGE_RENDERFUNC, RenderFunc);//设置自己的渲染函数.第二个参数是函数的名字 hge->System_SetState(HGE_TITLE, \"校园导游系统\");// 设置窗口标题.第二个参数标题名 hge->System_SetState(HGE_WINDOWED, true);//设置窗口模式,true为窗口模式,false全屏 hge->System_SetState(HGE_SCREENWIDTH,900);//设置窗口宽和高 hge->System_SetState(HGE_SCREENHEIGHT,800); hge->System_SetState(HGE_FPS, 60);//设置窗口的刷新率(每一秒钟渲染的次数) hge->System_SetState(HGE_HIDEMOUSE, false);//是否隐藏鼠标 hge->System_SetState(HGE_USESOUND, true);// 设置是否开启声音 //系统初始化 if (hge->System_Initiate()) { p_Font = new GfxFont(\"宋体\ //20表示字体大小 p_Font->SetColor(0xff000000);//设置颜色 p_Font_1 = new GfxFont(\"华文行楷\ p_Font_1->SetColor(0xff000000); p_Font_2 = new GfxFont(\"楷体\ p_Font_2->SetColor(0xffff0000); //自己的初始化: //从文件中加载一张图片并用纹理句柄保存 tex_3 = hge->Texture_Load(\"wall.jpg\"); sprite_3 = new hgeSprite(tex_3, 0, 0, 900, 800); 湖南人文科技学院·课程设计 tex = hge->Texture_Load(\"blue.png\"); sprite = new hgeSprite(tex, 0, 0, 16, 16);//创建一个精灵,并绑定一张纹理图片,蓝色 tex_1 = hge->Texture_Load(\"yellow.png\");//从文件中加载一张图片并用纹理句柄保存 sprite_1 = new hgeSprite(tex_1, 0, 0, 16, 16);//创建一个精灵,并绑定一张纹理图片 tex_5 = hge->Texture_Load(\"delete.jpg\"); sprite_5 = new hgeSprite(tex_5, 0, 0, 90, 30); sprite_5->SetHotSpot(45, 15); tex_6 = hge->Texture_Load(\"add.jpg\"); sprite_6 = new hgeSprite(tex_6, 0, 0, 90, 30); sprite_6->SetHotSpot(45, 15); tex_4 = hge->Texture_Load(\"school.jpg\");//从文件中加载一张图片并用纹理句柄保存 sprite_4 = new hgeSprite(tex_4, 0, 0, 900, 800);//创建一个精灵,并绑定一张纹理图片 tex_2 = hge->Texture_Load(\"red.png\");//从文件中加载一张图片并用纹理句柄保存 sprite_2 = new hgeSprite(tex_2, 0, 0, 16, 16);//创建一个精灵,并绑定一张纹理图片 tex_menu = hge->Texture_Load(\"start.jpg\");//从文件中加载一张图片并用纹理句柄保存 sprite_menu = new hgeSprite(tex_menu, 0, 0, 260, 80);//创建一个精灵,并绑定一张纹理图片 heffect_1 = hge->Effect_Load(\"button.mp3\"); memcpy(n1, n, sizeof(n)); point *start = (point*)malloc(sizeof(point));//起点 start->x = x; start->y = y; n[x][y] = 3; q.push(start); //启动系统: hge->System_Start(); } else { MessageBoxA(NULL, hge->System_GetErrorMessage(), \"Error\MB_OK | MB_ICONERROR | MB_APPLMODAL); } //程序结束时,资源的释放: 湖南人文科技学院·课程设计 } //系统关闭和hge指针的释放 hge->System_Shutdown(); hge->Release(); return 0; 3、程序调试与体会//对整个程序在高度过程中的一些体会(二级标题 程序经过调试完成了对景点简介信息,景点之间的路径的查询以及对景点信息的增加,删除和更新。 本次程序设计是对全学期数据结构课程学习的一次实践,通过亲自编写编译调试程序,逐步掌握了编程方法。也说明了一个深刻道理,知识只有在实践中才能充分理解并运用。从传统的被动接受变为主动探索,起初不是很适应,什么也不懂,茫然无措。渐渐地开始自己编写时候,发现了其中之乐趣。我相信,这样的学习坚持到底,必将有所成就。 设计过程需要查找各种资料,在百度等搜索工具与指导老师的帮助下,在自己理解的基础上参照方法写出属于自己的程序。虽然过程中出现多次程序报错,在同学的指导和老师的帮助下顺利完成,值得为之欣喜。 其中编程过程中显露出来的问题也必须引起高度重视,在今后的学习中必当万分注意绝不再犯。比如细心问题,有次的一个小小的“取地址符”没有添加,导致整个程序无法运行,检查了好久才发现。所以说,编程是个细活,只有严谨的态度,细心的思路以及良好的学习习惯,最终才能收获成功的喜悦。 最后感谢在编程过程中给予充分帮助的老师和同学们,这又使我认识到团队力量的强大作用。加强团队协作也是今后程序设计道路上的必备能力。 4、运行结果 四、结 论 经过这次课程设计,我对程序中算法的概念理解的更加透彻。算法是程序中必不可少的部分,它是指解题方案的准确而完整的描述,是一系列解决问题的清晰指令,算法代表着用系统的方法描述解决问题的策略机制。也就是说,能够对一定规范的输入,在有限时间内获得所要求的输出。如果一个算法有缺陷,或不适合于某个问题,执行这个算法将不会解决这个问题。不同的算法可能用不同的时间、空间或效率来完成同样的任务。同时,在选择算法时必须考虑算法的时间复杂度和空间复杂度,这样才能让程序正常高效的运行。 在这次的课程设计中,我们认识到了我们的不足和知识的广阔。使我们对我们课本的知识有了新的理解,让我们对C语言,C++和数据结构的理解更深,把我们学到的知识串通起 湖南人文科技学院·课程设计 来。 对于校园导游咨询系统,让我们把平时古板的知识用在了现实的社会实践中,对我们学习新的知识有了巨大的帮助,提高了我们的积极性。对我们把学到的知识用在生活中起到了作用,打到学以致用。 通过这次课程设计,我们学到了很多,有专业的知识,有分析的方法;有新的认识(HGE引擎),有学习的方向;有知识的充实,有心灵的升华。 实践是检验真理的唯一方法。 。 五、参考文献 [1]《数据结构》(C语言版) 严蔚敏 清华大学出版社 [2]《数据结构课程设计》 舒仕华 机械工业出版社 六、附录(源代码) #include \"hge.h\" #include bool IsShow_1 = false;//判断是否显示 bool IsShow_2 = false; bool IsShow_3 = false; bool IsShow_4 = false; bool IsShow_5 = false; bool IsShow_6 = false; bool IsShow_7 = false; bool IsShow_8 = false; bool IsShow_9 = false; enum ChangeState{ Del, Add, Usl }; ChangeState changestate = Usl; 湖南人文科技学院·课程设计 HGE *hge = 0;//定义一个全局变量:hge引擎指针 hgeFont* pFont; hgeSprite *sprite = NULL;//精灵指针:(指向一张图片) HTEXTURE tex = NULL;//纹理句柄(对应一张图片) hgeSprite *sprite_1 = NULL;//精灵指针:(指向一张图片) HTEXTURE tex_1 = NULL;//纹理句柄(对应一张图片) hgeSprite *sprite_2 = NULL;//精灵指针:(指向一张图片) HTEXTURE tex_2 = NULL;//纹理句柄(对应一张图片) hgeSprite *sprite_menu = NULL;//精灵指针:开始按钮 HTEXTURE tex_menu = NULL;//纹理句柄(开始) hgeSprite *sprite_3 = NULL; HTEXTURE tex_3 = NULL; hgeSprite* sprite_4 = NULL; HTEXTURE tex_4 = NULL; hgeSprite* sprite_5 = NULL; HTEXTURE tex_5 = NULL; hgeSprite* sprite_6 = NULL; HTEXTURE tex_6 = NULL; GfxFont *g_pGfxFont0 = NULL;//中文显示 GfxFont *g_pGfxFont1 = NULL;//中文显示 GfxFont* p_Font = NULL; //创建一个字体指针 GfxFont* p_Font_1 = NULL; GfxFont* p_Font_2 = NULL; float scaling_1 = 1.0f;//设置按钮缩放比列 float scaling_2 = 1.0f; float scaling_3 = 1.0f; //定义一个二维数组:表示地图的属性 int n1[40][40] = { 0 }; int n[40][40] = { { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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 1, 1, 1, 1, 0, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, }; //表示玩家位置(对应的数组下标) int x = 5, y = 18;//表示起始位置 int end_x = 3, end_y = 4;//结束的位置。 int x_1 = 0, y_1 = 0; //表示开始的状态: bool b_state = false; struct point{ int x; int y; point *last;//上一步的坐标 }; //空队列 湖南人文科技学院·课程设计 queue HEFFECT heffect;//音效的句柄. HEFFECT heffect_1;//音效的句柄. bool b_Find = false;//判断是否已经找到路径. bool b_dontFind = false; int aspect[4][2] = { { 0, -1 }, { 0, 1 }, { -1, 0 }, { 1, 0 } };//转向:上下左右 int flag = 0;//是否有路可走的标志 float mouse_x, mouse_y;//鼠标的位置 enum GameState{ Start, Play }; GameState gamestate = Start; hgeRect rect_menu; hgeRect rect_5; hgeRect rect_6; int step = 0; //更新函数(逻辑处理): bool FrameFunc() { hge->Effect_PlayEx(heffect, 20);//播放音效: if (hge->Input_KeyDown(HGEK_ESCAPE))//返回值为true,程序结束:按下ESC键 return true; switch (gamestate) { case Start: if (hge->Input_KeyDown(HGEK_LBUTTON)) { hge->Input_GetMousePos(&mouse_x, &mouse_y);//获取鼠标的位置 sprite_menu->GetBoundingBox(300, 100, &rect_menu);//获取图片的矩形区域 if (rect_menu.TestPoint(mouse_x, mouse_y))//判断一个点是否在矩形中 gamestate = Play; } b_state = false; break; case Play: if (hge->Input_KeyDown(HGEK_LBUTTON)) { if (changestate==Add) { hge->Input_GetMousePos(&mouse_x, &mouse_y); x_1 = (int)(mouse_y - 100) / 16;//16表示图片的高 y_1 = (int)(mouse_x - 100) / 16;//16表示图片的宽 湖南人文科技学院·课程设计 n[x_1][y_1] = 1; n1[x_1][y_1] = 1; } else if (changestate == Del) { hge->Input_GetMousePos(&mouse_x, &mouse_y); x_1 = (int)(mouse_y - 100) / 16;//16表示图片的高 y_1 = (int)(mouse_x - 100) / 16;//16表示图片的宽 n[x_1][y_1] = 0; n1[x_1][y_1] = 0; } hge->Input_GetMousePos(&mouse_x, &mouse_y);//获取鼠标的位置 sprite_5->GetBoundingBox(750, 500, &rect_5);//获取图片的矩形区域 sprite_6->GetBoundingBox(750, 550, &rect_6); if (rect_5.TestPoint(mouse_x, mouse_y))//判断鼠标是否在增加删除选项框内 { scaling_1 = 1.2f;; changestate = Add; } else if (rect_6.TestPoint(mouse_x, mouse_y)) { scaling_2 = 1.2f; changestate = Del; } } if (hge->Input_KeyUp(HGEK_LBUTTON)) { hge->Input_GetMousePos(&mouse_x, &mouse_y);//获取鼠标的位置 sprite_5->GetBoundingBox(750, 500, &rect_5);//获取图片的矩形区域 sprite_6->GetBoundingBox(750, 550, &rect_6); if (rect_5.TestPoint(mouse_x, mouse_y))//判断鼠标是否在增加删除选项框内 scaling_1 = 1.0f; else if (rect_6.TestPoint(mouse_x, mouse_y)) scaling_2 = 1.0f; } hge->Input_GetMousePos(&mouse_x, &mouse_y); if (mouse_x > 510 && mouse_x < 540 && mouse_y >410 && mouse_y < 440) IsShow = true; else IsShow = false; 湖南人文科技学院·课程设计 if (mouse_x >510 && mouse_x < 550 && mouse_y >300 && mouse_y < 340) IsShow_1 = true; else IsShow_1 = false; if (mouse_x >410 && mouse_x < 450 && mouse_y >310 && mouse_y < 350) IsShow_2=true; else IsShow_2 = false; if (mouse_x >225 && mouse_x < 265 && mouse_y >130 && mouse_y < 170) IsShow_3=true; else IsShow_3 = false; if (mouse_x >310 && mouse_x < 350 && mouse_y >540 && mouse_y < 580) IsShow_4=true; else IsShow_4 = false; if (mouse_x >400 && mouse_x < 440 && mouse_y >610 && mouse_y < 650) IsShow_5=true; else IsShow_5 = false; if (mouse_x >315 && mouse_x < 355 && mouse_y >430 && mouse_y < 470) IsShow_6=true; else IsShow_6 = false; if (mouse_x >200 && mouse_x < 240 && mouse_y >430 && mouse_y < 470) IsShow_7=true; else IsShow_7 = false; if (mouse_x >400 && mouse_x < 440 && mouse_y >405 && mouse_y < 445) IsShow_8=true; else IsShow_8 = false; if (mouse_x >645 && mouse_x < 685 && mouse_y >380 && mouse_y < 420) IsShow_9=true; else IsShow_9 = false; if (hge->Input_GetKeyState(HGEK_RBUTTON) && b_state == false)//判断鼠标左键是否按下,按下开始导游 { b_state = TRUE; hge->Input_GetMousePos(&mouse_x, &mouse_y); end_x = (int)(mouse_y - 100) / 16;//16表示图片的高 end_y = (int)(mouse_x - 100) / 16;//16表示图片的宽 湖南人文科技学院·课程设计 } if (hge->Input_GetKeyState(HGEK_SPACE)) { step = 0; memcpy(n, n1, sizeof(n)); x = end_x; y = end_y; point *start = (point*)malloc(sizeof(point));//起点 start->x = x; start->y = y; n[x][y] = 3; if (x != 1 && y != 1) n[1][1] = 0; q.push(start); } if (b_state) { while (!q.empty()){ point *front = q.front(); q.pop();//弹出队头 if (front->x == end_x &&front->y == end_y) { flag = 1; //cout<<\"成功找到出路.\"<<\"最少需要\"< 湖南人文科技学院·课程设计 front = front->last; } //cout<<\"->\"< 湖南人文科技学院·课程设计 hge->Gfx_BeginScene();//通知系统开始绘制 hge->Gfx_Clear(0xFFFFFFFF);// 清屏(屏幕的背景颜色,每两位:红、绿、蓝) switch (gamestate)//自己的绘制: { case Start: sprite_4->Render(0, 0); sprite_menu->RenderEx(300, 100,0.0f,1.0f,1.0f); break; case Play: sprite_3->Render(0, 0);//绘制背景 sprite_5->RenderEx(795, 515, 0.0f, scaling_1, scaling_1);//绘制按钮 sprite_6->RenderEx(795, 565, 0.0f, scaling_2, scaling_2 );//绘制按钮 for (int i = 0; i<40; ++i)//遍历数组的元素并根据其值绘制图形 { for (int j = 0; j<40; ++j) { switch (n[i][j]) { case 0://sprite_1->Render(j*16,i*16); break; case 1://第一个参数表示x坐标,第二参数y坐标 sprite->Render(100 + j * 16, 100 + i * 16); break; case 2://第一个参数表示x坐标,第二参数y坐标 sprite_1->Render(100 + j * 16, 100 + i * 16); break; case 3://第一个参数表示x坐标,第二参数y坐标 sprite_2->Render(100 + j * 16, 100 + i * 16); break; } } } p_Font_2->Render(750, 400, L\"距离 米\"); p_Font_2->Print(790, 400, \" %d\ p_Font_1->Render(200, 50, L\"湖南人文科技学院导游图\"); p_Font->Render(248, 150, L\"阳\\n光\\n公\\n寓\"); //设置字体的位置 p_Font->Render(220, 450, L\"体\\n育\\n馆\"); //设置字体的位置 p_Font->Render(335, 450, L\"田\\n径\\n场\"); //设置字体的位置 p_Font->Render(525, 425, L\"海园广场\"); //设置字体的位置 p_Font->Render(530, 320, L\"致远楼\"); //设置字体的位置 p_Font->Render(430, 330, L\"图\\n书\\n馆\"); //设置字体的位置 p_Font->Render(420, 425, L\"生活\\n服务\\n大楼\"); //设置字体的位置 p_Font->Render(420, 630, L\"逸\\n夫\\n楼\"); //设置字体的位置 湖南人文科技学院·课程设计 p_Font->Render(330, 560, L\"惠风\\n篮球场\"); //设置字体的位置 p_Font->Render(665, 400, L\"毓\\n师\\n园\"); //设置字体的位置 if (IsShow) { p_Font_2->Render(mouse_x,mouse_y,L\"休闲散步的最佳场所\"); } if (IsShow_1) { p_Font_2->Render(mouse_x, mouse_y, L\"全校最大的一栋综合教学楼,\\n各系上课得主要场所\"); } if (IsShow_2) { p_Font_2->Render(mouse_x, mouse_y, L\"学校的心脏,藏有图书上百万册,\\n三楼为咖啡书吧,环境优雅\"); } if (IsShow_3) { p_Font_2->Render(mouse_x, mouse_y, L\"全校最豪华的学生公寓,共有六栋,\\n有标准四人寝和豪华两人寝\"); } if (IsShow_4) { p_Font_2->Render(mouse_x, mouse_y, L\"全校最大篮球场,挥洒汗水的赛场\"); } if (IsShow_5) { p_Font_2->Render(mouse_x, mouse_y, L\"学校最具艺术色彩的一栋大楼\"); } if (IsShow_6) { p_Font_2->Render(mouse_x, mouse_y, L\"现在化塑胶标准报道,人造草坪,\\n适宜锻炼身体的场所\"); } if (IsShow_7) { p_Font_2->Render(mouse_x, mouse_y, L\"举办各种大型比赛和开展大型活动的场所,\\n能容纳五千多人\"); } if (IsShow_8) { p_Font_2->Render(mouse_x, mouse_y, L\"为学生和老师提供生活服务的地方\"); } if (IsShow_9) 湖南人文科技学院·课程设计 { p_Font_2->Render(mouse_x, mouse_y, L\"绿树成荫,幽静小道,适宜读书和休息\"); } break; } hge->Gfx_EndScene();//通知系统结束绘制 return false; } //主函数(入口函数) int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) { hge = hgeCreate(HGE_VERSION);//hge指针赋值。 hge->System_SetState(HGE_FRAMEFUNC, FrameFunc);// 设置自己的更新函数//第二个参数是函数的名字 hge->System_SetState(HGE_RENDERFUNC, RenderFunc);//设置自己的渲染函数.第二个参数是函数的名字 hge->System_SetState(HGE_TITLE, \"校园导游系统\");// 设置窗口标题.第二个参数标题名 hge->System_SetState(HGE_WINDOWED, true);//设置窗口模式,true为窗口模式,false全屏 hge->System_SetState(HGE_SCREENWIDTH,900);//设置窗口宽和高 hge->System_SetState(HGE_SCREENHEIGHT,800); hge->System_SetState(HGE_FPS, 60);//设置窗口的刷新率(每一秒钟渲染的次数) hge->System_SetState(HGE_HIDEMOUSE, false);//是否隐藏鼠标 hge->System_SetState(HGE_USESOUND, true);// 设置是否开启声音 //系统初始化 if (hge->System_Initiate()) { p_Font = new GfxFont(\"宋体\ //20表示字体大小 p_Font->SetColor(0xff000000);//设置颜色 p_Font_1 = new GfxFont(\"华文行楷\ p_Font_1->SetColor(0xff000000); p_Font_2 = new GfxFont(\"楷体\ p_Font_2->SetColor(0xffff0000); //自己的初始化: //从文件中加载一张图片并用纹理句柄保存 tex_3 = hge->Texture_Load(\"wall.jpg\"); sprite_3 = new hgeSprite(tex_3, 0, 0, 900, 800); tex = hge->Texture_Load(\"blue.png\"); sprite = new hgeSprite(tex, 0, 0, 16, 16);//创建一个精灵,并绑定一张纹理图片,蓝色 湖南人文科技学院·课程设计 tex_1 = hge->Texture_Load(\"yellow.png\");//从文件中加载一张图片并用纹理句柄保存 sprite_1 = new hgeSprite(tex_1, 0, 0, 16, 16);//创建一个精灵,并绑定一张纹理图片 tex_5 = hge->Texture_Load(\"delete.jpg\"); sprite_5 = new hgeSprite(tex_5, 0, 0, 90, 30); sprite_5->SetHotSpot(45, 15); tex_6 = hge->Texture_Load(\"add.jpg\"); sprite_6 = new hgeSprite(tex_6, 0, 0, 90, 30); sprite_6->SetHotSpot(45, 15); tex_4 = hge->Texture_Load(\"school.jpg\");//从文件中加载一张图片并用纹理句柄保存 sprite_4 = new hgeSprite(tex_4, 0, 0, 900, 800);//创建一个精灵,并绑定一张纹理图片 tex_2 = hge->Texture_Load(\"red.png\");//从文件中加载一张图片并用纹理句柄保存 sprite_2 = new hgeSprite(tex_2, 0, 0, 16, 16);//创建一个精灵,并绑定一张纹理图片 tex_menu = hge->Texture_Load(\"start.jpg\");//从文件中加载一张图片并用纹理句柄保存 sprite_menu = new hgeSprite(tex_menu, 0, 0, 260, 80);//创建一个精灵,并绑定一张纹理图片 heffect_1 = hge->Effect_Load(\"button.mp3\"); memcpy(n1, n, sizeof(n)); point *start = (point*)malloc(sizeof(point));//起点 start->x = x; start->y = y; n[x][y] = 3; q.push(start); //启动系统: hge->System_Start(); } else { MessageBoxA(NULL, hge->System_GetErrorMessage(), \"Error\MB_OK | MB_ICONERROR | MB_APPLMODAL); } //程序结束时,资源的释放: //系统关闭和hge指针的释放 hge->System_Shutdown(); 湖南人文科技学院·课程设计 } hge->Release(); return 0; 因篇幅问题不能全部显示,请点此查看更多更全内容 #include