本文整理汇总了C++中mazewarinstance::Ptr::xlocIs方法的典型用法代码示例。如果您正苦于以下问题:C++ Ptr::xlocIs方法的具体用法?C++ Ptr::xlocIs怎么用?C++ Ptr::xlocIs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mazewarinstance::Ptr
的用法示例。
在下文中一共展示了Ptr::xlocIs方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: NewPosition
void NewPosition(MazewarInstance::Ptr m)
//void NewPosition(MazewarInstance *m)
{
Loc newX(0);
Loc newY(0);
Direction dir(0); /* start on occupied square */
while (M->maze_[newX.value()][newY.value()]) {
/* MAZE[XY]MAX is a power of 2 */
newX = Loc(random() & (MAZEXMAX - 1));
newY = Loc(random() & (MAZEYMAX - 1));
/* In real game, also check that square is
unoccupied by another rat */
}
/* prevent a blank wall at first glimpse */
if (!m->maze_[(newX.value())+1][(newY.value())]) dir = Direction(NORTH);
if (!m->maze_[(newX.value())-1][(newY.value())]) dir = Direction(SOUTH);
if (!m->maze_[(newX.value())][(newY.value())+1]) dir = Direction(EAST);
if (!m->maze_[(newX.value())][(newY.value())-1]) dir = Direction(WEST);
m->xlocIs(newX);
m->ylocIs(newY);
m->dirIs(dir);
}
示例2: _backward
void _backward()
{
register int tx = MY_X_LOC;
register int ty = MY_Y_LOC;
switch(MY_DIR) {
case NORTH: if (!M->maze_[tx-1][ty]) tx--; break;
case SOUTH: if (!M->maze_[tx+1][ty]) tx++; break;
case EAST: if (!M->maze_[tx][ty-1]) ty--; break;
case WEST: if (!M->maze_[tx][ty+1]) ty++; break;
default:
MWError("bad direction in Backward");
}
if ((MY_X_LOC != tx) || (MY_Y_LOC != ty)) {
M->xlocIs(Loc(tx));
M->ylocIs(Loc(ty));
updateView = TRUE;
}
}
示例3: forward
/* ----------------------------------------------------------------------- */
void forward(void)
{
bool allow = true;
register int tx = MY_X_LOC;
register int ty = MY_Y_LOC;
switch(MY_DIR) {
case NORTH:
{
for (int i = 0; i < 8 ; i++)
{
if(rat_array[i] != NULL)
{
if (M->mazeRats_[i].x.value() == MY_X_LOC+1 && MY_Y_LOC == M->mazeRats_[i].y.value())
{
allow = false;
break;
}
}
}
break;
}
case SOUTH:
{
for (int i = 0; i < 8 ; i++)
{
if(rat_array[i] != NULL)
{
if (M->mazeRats_[i].x.value() == MY_X_LOC-1 && MY_Y_LOC == M->mazeRats_[i].y.value())
{
allow = false;
break;
}
}
}
break;
}
case EAST:
{
for (int i = 0; i < 8 ; i++)
{
if(rat_array[i] != NULL)
{
if (M->mazeRats_[i].x.value() == MY_X_LOC && MY_Y_LOC+1 == M->mazeRats_[i].y.value())
{
allow = false;
break;
}
}
}
break;
}
case WEST:
{
for (int i = 0; i < 8 ; i++)
{
if(rat_array[i] != NULL)
{
if (M->mazeRats_[i].x.value() == MY_X_LOC && MY_Y_LOC-1 == M->mazeRats_[i].y.value())
{
allow = false;
break;
}
}
}
break;
}
default:
exit(0);
}
if (allow){
switch(MY_DIR) {
case NORTH: if (!M->maze_[tx+1][ty]) tx++; break;
case SOUTH: if (!M->maze_[tx-1][ty]) tx--; break;
case EAST: if (!M->maze_[tx][ty+1]) ty++; break;
case WEST: if (!M->maze_[tx][ty-1]) ty--; break;
default:
MWError("bad direction in Forward");
}
if ((MY_X_LOC != tx) || (MY_Y_LOC != ty)) {
M->xlocIs(Loc(tx));
M->ylocIs(Loc(ty));
updateView = TRUE;
}
}
}