如何用 C++ 编写 PacMan 地图
谁能告诉我如何用 C++ 创建 PacMan 地图。 对于开始使用有什么建议吗?
提前致谢。
Can anyone plese tell me How do i create a Map for PacMan in C++.
Any Suggestions for getting m Started.?
Thanx in Advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一个相当广泛的问题,取决于其他要求。基本上我会选择一个二维数组来简单地表示单元格。每个单元格将包含以下其中之一:
怪物和吃豆人本身不会出现在地图中。相反,每个人都应该在地图上有自己的位置。
这不需要 C++,它只需要 C,但如果您故意想要 C++ 解决方案,您可以用向量替换数组,或者在本例中是向量的向量。
怪物将如何移动
如果您想从地图上的 B 点到达 A 点,您可以使用多种算法中的任何一种来找到地图内的最短路径 - 就像A* 算法。但是,在这种情况下,您需要考虑一些事项:
我建议当怪物到达“十字路口”时使用一些随机决策,以及对吃豆人本身的普遍偏见。因此,如果怪物位于有 3 个方向的点,例如东、西、北,而吃豆人在北,我会做出随机决定,有 40% 的机会向北,30% 向东,30% % 向西。
That's quite a wide question and depends on additional requirements. Basically I would go for a two-dimensional array that will simply represent the cells. Each cell would contain either:
The monsters and the pacman itself will not be represented in the map. Instead each should just have his position in the map.
This doesn't require C++, it only requires C, but if you deliberately want a C++ solution you can replace the arrays with a vector, or in this case, a vector of vectors.
How will the monsters move
If you want to reach point A from point B in a map, you can use any of a variety of algorithms that will find you the shortest path within the map - like the A* algorithm. However, in this case, you need to take a few things into account:
I would suggest using some random decisions when the monster reaches a "crossroad", along with a general bias towards the pacman itself. So if the monster is at a point where there are 3 directions, like East, West and North, and the pacman is to the north, I would make a random decision with 40% chance to the north, 30% to the east and 30% to the west.
这里有一个提示:
Here's a tip: