void AGOSEngine_Feeble::inventoryUp(WindowBlock *window) { _marks = 0; checkUp(window); animate(4, 9, 21, 0 ,0, 0); while (_currentBoxNum == 0x7FFB && getBitFlag(89)) { checkUp(window); delay(1); } waitForMark(2); checkUp(window); sendSync(922); waitForMark(1); checkUp(window); }
void Map::setBonus() { checkRight(); checkLeft(); checkUp(); checkDown(); }
void testNavigate(){ int check, nextX, nextY; initDir(); //start by getting the initial direction solution = createStack(); push(solution, current); // add the starting square to the stack while (current->val != 'F'){ // the maze sloving loop printf("current position: (%d, %d)\ncurrent direction: %c\n",current->x, current->y,dir); switch(dir){ case 'n': check = checkUp(); nextX = current->x; nextY = current->y - 1; break; case 's': check = checkDown(); nextX = current->x; nextY = current->y + 1; break; case 'e': check = checkRight(); nextX = current->x + 1; nextY = current->y; break; case 'w': check = checkLeft(); nextX = current->x - 1; nextY = current->y; break; } if (check == 1){ // if you can move, the next space is not a wall printf("the square ahead is not a wall!\n"); if (maze[nextX][nextY]->wasHere == 1){ //we have been there already printf("we have been here before!\n"); if (otherOptions(nextX, nextY) == 1){ // there are other options printf("we have other options, lets turn\n"); changeDir(); printf("new direction: %c\n",dir); } else { // no other options will need to go back to where we have been printf("we have no other options we must go this way\n"); pop(solution); // pop from stack current->deadEnd = 1; current = maze[nextX][nextY]; // move } } else { printf("we have not been here before, lets go!\n"); current = maze[nextX][nextY]; // move current-> wasHere = 1; push(solution, current); // add to stack } } else { printf("the square ahead is a wall, we must change directions\n"); changeDir(); printf("new direction: %c\n",dir); } char c = getchar(); } }
//判断上下左右 void RootEngine::checkFourSides(StarModel* model) { if (checkedBlocks->containsObject(model)) { return; }else { checkedBlocks->addObject(model); } checkUp(model); checkDown(model); checkLeft(model); checkRight(model); }
void navigate(){ int check, nextX, nextY; initDir(); //start by getting the initial direction solution = createStack(); push(solution, current); // add the starting square to the stack while (current->val != 'F'){ // the maze sloving loop switch(dir){ case 'n': check = checkUp(); nextX = current->x; nextY = current->y - 1; break; case 's': check = checkDown(); nextX = current->x; nextY = current->y + 1; break; case 'e': check = checkRight(); nextX = current->x + 1; nextY = current->y; break; case 'w': check = checkLeft(); nextX = current->x - 1; nextY = current->y; break; } if (check == 1){ // if you can move, the next space is not a wall if (maze[nextX][nextY]->wasHere == 1){ //we have been there already if (otherOptions(nextX, nextY) == 1){ // there are other options changeDir(); } else { // no other options will need to go back to where we have been pop(solution); // pop from stack current->deadEnd = 1; current = maze[nextX][nextY]; // move } } else { current = maze[nextX][nextY]; // move current-> wasHere = 1; push(solution, current); // add to stack } } else { changeDir(); } } }
int checkScrollDirection(int prevX, int prevY, int x, int y) { int badmove = 1; moveRight = 0, moveLeft = 0, moveDown = 0, moveUp = 0; /* Check the 8 possible move combinations to ensure correct bounds checking If the move is possible call the corresponding direction checks that update scrolling values If move is not possible we return badmove and the x and y values are fixed*/ if(prevX < x && prevY < y) /* move right and down */ { if (screenRight < MAP_WIDTH - 1 && screenBottom < MAP_HEIGHT - 1) { checkRight(); checkDown(); } else { return badmove; } } else if(prevX < x && prevY > y) /* move right and up */ { if (screenRight < MAP_WIDTH - 1 && screenTop > 0) { checkRight(); checkUp(); } else { return badmove; } } else if(prevX > x && prevY < y) /* move left and down */ { if(screenLeft > 0 && screenBottom < MAP_HEIGHT - 1) { checkLeft(); checkDown(); } else { return badmove; } } else if(prevX > x && prevY > y) /* move left and up */ { if (screenTop > 0 && screenLeft > 0) { checkLeft(); checkUp(); } else { return badmove; } } else if(prevX < x) /* move right */ { if (screenRight < MAP_WIDTH - 1) { checkRight(); } else { return badmove; } } else if(prevX > x) //moveLeft { if (screenLeft > 0) { checkLeft(); } else { return badmove; } } else if(prevY < y) //moveDown { if (screenBottom < MAP_HEIGHT - 1) { checkDown(); } else { return badmove; } } else if(prevY > y) //moveUp { if (screenTop > 0) { checkUp(); } else { return badmove; } } /* copy necessary map rows and/or columns to the background buffer */ if (moveLeft) { CopyColumnToBackground(screenLeft, nextColumn, mapTop, mapBottom, starmapscrn_Map, bg0map, MAP_COLUMNS); } if (moveRight) { CopyColumnToBackground(screenRight, nextColumn, mapTop, mapBottom, starmapscrn_Map, bg0map, MAP_COLUMNS); } if (moveUp) { CopyRowToBackground(screenTop, nextRow, mapLeft, mapRight, starmapscrn_Map, bg0map, MAP_COLUMNS); } if (moveDown) { CopyRowToBackground(screenBottom, nextRow, mapLeft, mapRight, starmapscrn_Map, bg0map, MAP_COLUMNS); } return 0; }
void FloorGenerator::assignUp(bool room) { //8 different types of Corridors can be assigned int temp = rand() % 8; int posX = start.front().getX(); int posY = start.front().getY(); const int ONED = 0, TWOV = 1, TWODR = 2, TWODL = 3, THREED = 4, THREEL = 5, THREER = 6, FOUR = 7; switch(temp) { case ONED: { //create temp variables to store checks bool up, left, right; //determine whether or not to check for up, left, right due to limits if(posX-2 < 0) up = true; else up = !checkUp2(posX-2, posY); if(posY-1 < 0) left = true; else left = !checkLeft2(posX-1, posY-1); if(posY+1 > LIMIT-1) right = true; else right = !checkRight2(posX-1, posY+1); if(up && left && right) { if(room) pushRoom(posX-1, posY, roomoneD, room); else pushCor(posX-1, posY, oneD, room); }else assignUp(room); break; } case TWOV: { //check for available position above where this piece is placed if(posX - 2 < 0) { //can't push assign a new piece assignUp(room); break; }else { //create temp variables to store checks bool up, left, right; //determine whether or not to check for up, left, right due to limits if(posX-2 < 0) up = false; else up = checkUp(posX-2, posY); if(posY-1 < 0) left = true; else left = !checkLeft2(posX-1, posY-1); if(posY+1 > LIMIT-1) right = true; else right = !checkRight2(posX-1, posY+1); //check for compatibility if(up && left && right) { //create a twoV corridor to push if(room) pushRoom(posX-1, posY, roomtwoV, room); else pushCor(posX-1, posY, twoV, room); }else assignUp(room); } break; } case TWODR: { //check right for availability if((posY+1) > LIMIT-1) { //can't push right, assign a new piece assignUp(room); break; }else { //create temp variables to store checks bool up, left, right; //determine whether or not to check for up, left, right due to limits if(posX-2 < 0) up = true; else up = !checkUp2(posX-2, posY); if(posY-1 < 0) left = true; else left = !checkLeft2(posX-1, posY-1); if(posY+1 > LIMIT-1) right = false; else right = checkRight(posX-1, posY+1); //check for existing areas for compatibility if(up && left && right) { if(room) pushRoom(posX-1, posY, roomtwoDR, room); else pushCor(posX-1, posY, twoDR, room); }else assignUp(room); } break; } case TWODL: { //Check left for availability if((posY-1) < 0) { //can't assign left, assign a new piece assignUp(room); break; }else { //create temp variables to store checks bool up, left, right; //determine whether or not to check for up, left, right due to limits if(posX-2 < 0) up = true; else up = !checkUp2(posX-2, posY); if(posY-1 < 0) left = false; else left = checkLeft(posX-1, posY-1); if(posY+1 > LIMIT-1) right = true; else right = !checkRight2(posX-1, posY+1); //check existing areas for compatibility if(up && left && right) { //push twoDL corridor to the queue if(room) pushRoom(posX-1, posY, roomtwoDL, room); else pushCor(posX-1, posY, twoDL, room); }else assignUp(room); } break; } case THREED: { //check left and right for edges if((posY - 1) < 0) { //can't assign left, assign a new piece assignUp(room); break; } else if(posY +1 > LIMIT) { //can't assign right, assign a new piece assignUp(room); break; } else { //create temp variables to store checks bool up, left, right; //determine whether or not to check for up, left, right due to limits if(posX-2 < 0) up = true; else up = !checkUp2(posX-2, posY); if(posY-1 < 0) left = false; else left = checkLeft(posX-1, posY-1); if(posY+1 > LIMIT-1) right = false; else right = checkRight(posX-1, posY+1); //check for existing areas for compatibility if( up && left && right) { //push threeD corridor onto the queue if(room) pushRoom(posX-1, posY, roomthreeD, room); else pushCor(posX-1, posY, threeD, room); }else assignUp(room); } break; } case THREEL: { //check left and top if((posY-1) < 0) { //can't assign left, assign a new piece assignUp(room); break; } if((posX-2) < 0) { assignUp(room); break; } else { //create temp variables to store checks bool up, left, right; //determine whether or not to check for up, left, right due to limits if(posX-2 < 0) up = false; else up = checkUp(posX-2, posY); if(posY-1 < 0) left = false; else left = checkLeft(posX-1, posY-1); if(posY+1 > LIMIT-1) right = true; else right = !checkRight2(posX-1, posY+1); //check existing areas if(up && left && right) { if(room) pushRoom(posX-1, posY, roomthreeL, room); else pushCor(posX-1, posY, threeL, room); break; }else assignUp(room); } break; } case THREER: { //check top and right if((posX-2) < 0) { assignUp(room); break; }else if(posY + 1 > LIMIT-1) { assignUp(room); break; }else { //create temp variables to store checks bool up, left, right; //determine whether or not to check for up, left, right due to limits if(posX-2 < 0) up = false; else up = checkUp(posX-2, posY); if(posY-1 < 0) left = true; else left = !checkLeft2(posX-1, posY-1); if(posY+1 > LIMIT-1) right = false; else right = checkRight(posX-1, posY+1); //check top and right for compatibility if(up && left && right) { //push threeR corridor onto the queue if(room) pushRoom(posX-1, posY, roomthreeR, room); else pushCor(posX-1, posY, threeR, room); break; }else assignUp(room); } break; } case FOUR: { //check up, left and right if(posY -1 < 0) { assignUp(room); break; }else if(posY+1 > LIMIT-1) { assignUp(room); break; }else if(posX-2 < 0) { assignUp(room); break; }else { //create temp variables to store checks bool up, left, right; //determine whether or not to check for up, left, right due to limits if(posX-2 < 0) up = false; else up = checkUp(posX-2, posY); if(posY-1 < 0) left = false; else left = checkLeft(posX-1, posY-1); if(posY+1 > LIMIT-1) right = false; else right = checkRight(posX-1, posY+1); if(up && left && right) { if(room) pushRoom(posX-1, posY, roomfour, room); else pushCor(posX-1, posY, four, room); }else assignUp(room); } break; } }//end switch }
void FloorGenerator::assignRight(bool room) { int temp = rand() % 8; int posX = start.front().getX(); int posY = start.front().getY(); const int ONEL = 0, TWOH = 1, TWOUL= 2, TWODL = 3, THREEU = 4, THREED = 5, THREEL = 6, FOUR = 7; switch(temp) { case ONEL: { bool up, down, right; if(posX-1 < 0) up = true; else up = !checkUp2(posX-1, posY+1); if(posX+1 > LIMIT-1) down = true; else down = !checkDown2(posX+1, posY+1); if(posY+2 > LIMIT-1) right = true; else right = !checkRight2(posX, posY+2); if(up && down && right) { if(room) pushRoom(posX, posY+1, roomoneL, room); else pushCor(posX, posY+1, oneL, room); }else assignRight(room); break; } case TWOH: { if(posY+2 > LIMIT-1) { assignRight(room); break; }else { bool up, down, right; if(posX-1 < 0) up = true; else up = !checkUp2(posX-1, posY+1); if(posX+1 > LIMIT-1) down = true; else down = !checkDown2(posX+1, posY+1); if(posY+2 > LIMIT-1) right = false; else right = checkRight(posX, posY+2); if(up && down && right) { if(room) pushRoom(posX, posY+1, roomtwoH, room); else pushCor(posX, posY+1, twoH, room); }else assignRight(room); } break; } case TWOUL: { if(posX-1 < 0) { assignRight(room); break; }else { bool up, down, right; if(posX-1 < 0) up = false; else up = checkUp(posX-1, posY+1); if(posX+1 > LIMIT-1) down = true; else down = !checkDown2(posX+1, posY+1); if(posY+2 > LIMIT-1) right = true; else right = !checkRight2(posX, posY+2); if(up && down && right) { if(room) pushRoom(posX, posY+1, roomtwoUL, room); else pushCor(posX, posY+1, twoUL, room); }else assignRight(room); } break; } case TWODL: { if(posX+1 > LIMIT-1) { assignRight(room); break; }else { bool up, down, right; if(posX-1 < 0) up = true; else up = !checkUp2(posX-1, posY+1); if(posX+1 > LIMIT-1) down = false; else down = checkDown(posX+1, posY+1); if(posY+2 > LIMIT-1) right = true; else right = !checkRight2(posX, posY+2); if(up && down && right) { if(room) pushRoom(posX, posY+1, roomtwoDL, room); else pushCor(posX, posY+1, twoDL, room); }else assignRight(room); } break; } case THREEU: { if(posX-1 < 0) { assignRight(room); break; }else if(posY+2 > LIMIT-1) { assignRight(room); break; }else { bool up, down, right; if(posX-1 < 0) up = false; else up = checkUp(posX-1, posY+1); if(posX+1 > LIMIT-1) down = true; else down = !checkDown2(posX+1, posY+1); if(posY+2 > LIMIT-1) right = false; else right = checkRight(posX, posY+2); if(up && down && right) { if(room) pushRoom(posX, posY+1, roomthreeU, room); else pushCor(posX, posY+1, threeU, room); }else assignRight(room); } break; } case THREED: { if(posX+1 > LIMIT-1) { assignRight(room); break; }else if(posY+2 > LIMIT-1) { assignRight(room); break; }else { bool up, down, right; if(posX-1 < 0) up = true; else up = !checkUp2(posX-1, posY+1); if(posX+1 > LIMIT-1) down = false; else down = checkDown(posX+1, posY+1); if(posY+2 > LIMIT-1) right = false; else right = checkRight(posX, posY+2); if(up && down && right) { if(room) pushRoom(posX, posY+1, roomthreeD, room); else pushCor(posX, posY+1, threeD, room); }else assignRight(room); } break; } case THREEL: { if(posX+1 > LIMIT-1) { assignRight(room); break; }else if(posX-1 < 0) { assignRight(room); break; }else { bool up, down, right; if(posX-1 < 0) up = false; else up = checkUp(posX-1, posY+1); if(posX+1 > LIMIT-1) down = false; else down = checkDown(posX+1, posY+1); if(posY+2 > LIMIT-1) right = true; else right = !checkRight2(posX, posY+2); if(up && down && right) { if(room) pushRoom(posX, posY+1, roomthreeL, room); else pushCor(posX, posY+1, threeL, room); }else assignRight(room); } break; } case FOUR: { if(posX + 1 > LIMIT-1) { assignRight(room); break; }else if(posX -1 < 0) { assignRight(room); break; }else if(posY+2 > LIMIT-1) { assignRight(room); break; }else { bool up, down, right; if(posX-1 < 0) up = false; else up = checkUp(posX-1, posY+1); if(posX+1 > LIMIT-1) down = false; else down = checkDown(posX+1, posY+1); if(posY+2 > LIMIT-1) right = false; else right = checkRight(posX, posY+2); if(up && down && right) { if(room) pushRoom(posX, posY+1, roomfour, room); else pushCor(posX, posY+1, four, room); }else assignRight(room); } break; } } }
void FloorGenerator::assignLeft(bool room) { int temp = rand() % 8; int posX = start.front().getX(); int posY = start.front().getY(); const int ONER = 0, TWOH = 1, TWOUR= 2, TWODR = 3, THREEU = 4, THREED = 5, THREER = 6, FOUR = 7; switch(temp) { case ONER: { bool up, down, left; if(posX-1 < 0) up = true; else up = !checkUp2(posX-1, posY-1); if(posX+1 > LIMIT-1) down = true; else down = !checkDown2(posX+1, posY-1); if(posY-2 < 0) left = true; else left = !checkLeft2(posX, posY-2); if(up && down && left) { if(room) pushRoom(posX, posY-1, roomoneR, room); else pushCor(posX, posY-1, oneR, room); }else assignLeft(room); break; } case TWOH: { if(posY-2 < 0) { assignLeft(room); break; }else { bool up, down, left; if(posX-1 < 0) up = true; else up = !checkUp2(posX-1, posY-1); if(posX+1 > LIMIT-1) down = true; else down = !checkDown2(posX+1, posY-1); if(posY-2 < 0) left = false; else left = checkLeft(posX, posY-2); if(up && down && left) { if(room) pushRoom(posX, posY-1, roomtwoH, room); else pushCor(posX, posY-1, twoH, room); }else assignLeft(room); } break; } case TWOUR: { if(posX-1 < 0) { assignLeft(room); break; }else { bool up, down, left; if(posX-1 < 0) up = false; else up = checkUp(posX-1, posY-1); if(posX+1 > LIMIT-1) down = true; else down = !checkDown2(posX+1, posY-1); if(posY-2 < 0) left = true; else left = !checkLeft2(posX, posY-2); if(up && down && left) { if(room) pushRoom(posX, posY-1, roomtwoUR, room); else pushCor(posX, posY-1, twoUR, room); }else assignLeft(room); } break; } case TWODR: { if(posX+1 > LIMIT-1) { assignLeft(room); break; }else { bool up, down, left; if(posX-1 < 0) up = true; else up = !checkUp2(posX-1, posY-1); if(posX+1 > LIMIT-1) down = false; else down = checkDown(posX+1, posY-1); if(posY-2 < 0) left = true; else left = !checkLeft2(posX, posY-2); if(up && down && left) { if(room) pushRoom(posX, posY-1, roomtwoDR, room); else pushCor(posX, posY-1, twoDR, room); }else assignLeft(room); } break; } case THREEU: { if(posX-1 < 0) { assignLeft(room); break; }else if(posY-2 < 0) { assignLeft(room); break; }else { bool up, down, left; if(posX-1 < 0) up = false; else up = checkUp(posX-1, posY-1); if(posX+1 > LIMIT-1) down = true; else down = !checkDown2(posX+1, posY-1); if(posY-2 < 0) left = false; else left = checkLeft(posX, posY-2); if(up && down && left) { if(room) pushRoom(posX, posY-1, roomthreeU, room); else pushCor(posX, posY-1, threeU, room); }else assignLeft(room); } break; } case THREED: { if(posX+1 > LIMIT-1) { assignLeft(room); break; }else if(posY-2 < 0) { assignLeft(room); break; }else { bool up, down, left; if(posX-1 < 0) up = true; else up = !checkUp2(posX-1, posY-1); if(posX+1 > LIMIT-1) down = false; else down = checkDown(posX+1, posY-1); if(posY-2 < 0) left = false; else left = checkLeft(posX, posY-2); if(up && down && left) { if(room) pushRoom(posX, posY-1, roomthreeD, room); else pushCor(posX, posY-1, threeD, room); }else assignLeft(room); } break; } case THREER: { if(posX+1 > LIMIT-1) { assignLeft(room); break; }else if(posX-1 < 0) { assignLeft(room); break; }else { bool up, down, left; if(posX-1 < 0) up = false; else up = checkUp(posX-1, posY-1); if(posX+1 > LIMIT-1) down = false; else down = checkDown(posX+1, posY-1); if(posY-2 < 0) left = true; else left = !checkLeft2(posX, posY-2); if(up && down && left) { if(room) pushRoom(posX, posY-1, roomthreeR, room); else pushCor(posX, posY-1, threeR, room); }else assignLeft(room); } break; } case FOUR: { if(posX+1 > LIMIT-1) { assignLeft(room); break; }else if(posX-1 < 0) { assignLeft(room); break; }else if(posY-2 < 0) { assignLeft(room); break; }else { bool up, down, left; if(posX-1 < 0) up = false; else up = checkUp(posX-1, posY-1); if(posX+1 > LIMIT-1) down = false; else down = checkDown(posX+1, posY-1); if(posY-2 < 0) left = false; else left = checkLeft(posX, posY-2); if(up && down && left) { if(room) pushRoom(posX, posY-1, roomfour, room); else pushCor(posX, posY-1, four, room); }else assignLeft(room); } break; } } }