本文整理汇总了C++中Guard::joinMap方法的典型用法代码示例。如果您正苦于以下问题:C++ Guard::joinMap方法的具体用法?C++ Guard::joinMap怎么用?C++ Guard::joinMap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Guard
的用法示例。
在下文中一共展示了Guard::joinMap方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main() {
Point path[] = {{0, 0}, {10, 10}, {5, 5}, {15, 15}, {19, 19}};
int32_t pathSize = sizeof(path)/sizeof(Point);
int32_t mapWidth = 20;
int32_t mapHeight = 20;
Map map = newMap(mapWidth, mapHeight);
Guard guard = newGuard("wiwi", (Point) {0, 0});
guard.joinMap(&guard, &map);
int i, j = 0;
int32_t rectWallCount = randNum(3, 5);
printf("rectWallCount: %d\n", rectWallCount);
RectWall *rectWalls = malloc(sizeof(RectWall) * rectWallCount);
for (i = 0; i < rectWallCount; i++) { // each rectWalls
rectWalls[i].area[0].x = randNum(i, mapWidth - 1);
rectWalls[i].area[0].y = randNum(i+1, mapHeight - 1);
rectWalls[i].area[1].x = rectWalls[i].area[0].x + 1;
rectWalls[i].area[1].y = rectWalls[i].area[0].y;
rectWalls[i].area[2].x = rectWalls[i].area[0].x + 1;
rectWalls[i].area[2].y = rectWalls[i].area[0].y + 1;
rectWalls[i].area[3].x = rectWalls[i].area[0].x;
rectWalls[i].area[3].y = rectWalls[i].area[0].y + 1;
}
i = 0;
while ((rectWallsInMap(rectWalls, rectWallCount, &map) == false ||
overlapRectWalls(rectWalls, rectWallCount) ||
overlapRectWallsAndPath(rectWalls, rectWallCount, &path[0], pathSize)) &&
i < rectWallCount) {
// TODO Should find wrong specific rectWall and rand it.
rectWalls[i].area[0].x = randNum(i+randNum(0,i), mapWidth - 1);
rectWalls[i].area[0].y = randNum(i, mapHeight - 1);
rectWalls[i].area[1].x = rectWalls[i].area[0].x + 1;
rectWalls[i].area[1].y = rectWalls[i].area[0].y;
rectWalls[i].area[2].x = rectWalls[i].area[0].x + 1;
rectWalls[i].area[2].y = rectWalls[i].area[0].y + 1;
rectWalls[i].area[3].x = rectWalls[i].area[0].x;
rectWalls[i].area[3].y = rectWalls[i].area[0].y + 1;
i++;
if (i == rectWallCount) {
i = 0;
}
}
for (i = 0; i < rectWallCount; i++) { // each rectWalls
for (j = 0; j < 4; j++) { // each area
if (map.gridth(&map, rectWalls[i].area[j]) != NULL) {
printf("rect wall: %d, %d\n",
map.gridth(&map, rectWalls[i].area[j])->position.x,
map.gridth(&map, rectWalls[i].area[j])->position.y);
map.gridth(&map, rectWalls[i].area[j])->isBeWalkable = false;
}
}
}
free(rectWalls);
printf("%s start moving\n",guard.name);
map.gridth(&map, path[2])->isBeWalkable = false;
guard.move(&guard, path[1]);
map.gridth(&map, path[2])->isBeWalkable = true;
guard.move(&guard, path[2]);
map.gridth(&map, path[1])->isBeWalkable = false;
guard.move(&guard, path[3]);
map.gridth(&map, path[1])->isBeWalkable = true;
guard.move(&guard, path[4]);
return 0;
}