/** * Moves a NonPlayer according to a random choice. */ void NonPlayer::update() { TCODRandom * gen = TCODRandom::getInstance(); int choice = gen->getInt(0,7); switch (choice) { case 0: moveSouth(1); break; case 1: moveNorth(1); break; case 2: moveEast(1); break; case 3: moveWest(1); break; case 4: moveSouth(1); moveEast(1); break; case 5: moveSouth(1); moveWest(1); break; case 6: moveNorth(1); moveEast(1); break; case 7: moveNorth(1); moveWest(1); break; } }
void Player::updatePlayer() { if (movecounter > 0) { //Ignore all keyboard inputs this cycle. DO NOT change facing. if (facing == 'W') { moveWest(); } else if (facing == 'E') { moveEast(); } else if (facing == 'N') { moveNorth(); } else if (facing == 'S') { moveSouth(); } movecounter--; } else if (movecounter == 0) { // DO change facing, and get the movecounter going. oldy = y; oldx = x; oldcx = coordx; oldcy = coordy; if (keys[RIGHT]) { facing = 'E'; coordx++; moveEast(); movecounter = 5; } else if (keys[LEFT]) { facing = 'W'; coordx--; moveWest(); movecounter = 5; } else if (keys[UP]) { facing = 'N'; coordy--; moveNorth(); movecounter = 5; } else if (keys[DOWN]) { facing = 'S'; coordy++; moveSouth(); movecounter = 5; } } } // END updatePlayer
void print_directions(char** maze, int w, int h) { int currW = 0; int currH = 0; while(maze[currH][currW] != ' ') { currW++; } Karl karl = Karl_construct(currH, currW, maze, h, w); moveSouth(&karl); }
void moveWestNorthSouth(Karl *k, int *moves) { if(canMoveNorth(*k)) { //printf("W %d L: (%d,%d)\n", *moves, (*k).h, (*k).w); printf("W %d\n", *moves); moveNorth(k); *moves = 0; } if(canMoveSouth(*k)) { //*moves != 0 ? printf("W %d L: (%d,%d)\n", *moves, (*k).h, (*k).w) : 0; *moves != 0 ? printf("W %d\n", *moves) : 0; moveSouth(k); *moves = 0; } }
void Mazer::goAhead() //声明向当前方向前进的方法 { switch(forward) { case NORTH: moveNorth(); break; case WEST: moveWest(); break; case SOUTH: moveSouth(); break; case EAST: moveEast(); break; default: cout << "方向不明,无法前进。" << endl; } drawPerson(); if(MazeMap::checkMazeDoor(m_iPosX, m_iPosY)) { gotoxy(0,10); cout << "哈哈,终于出来啦!" << endl; outOrNot = true; } }
/* * 函数名称:goAhead * 函数功能:朝当前的前方走一步 * 返回内容:无 */ void MazePerson::goAhead() { switch(forward) { case NORTH: moveNorth(); break; case WEST: moveWest(); break; case SOUTH: moveSouth(); break; case EAST: moveEast(); break; default: cout << "方向不明,无法前进。" << endl; } //形成动画 drawPerson(); //检测是否到达出口 //如果到达出口,则提示 if(MazeMap::checkMazeDoor(positionX, positionY)) { gotoxy(0,22); cout << "哈哈,终于出来啦!" << endl; outOrNot = true; } }