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 Game::checkBorders() { checkLeft(); checkRight(); checkTop(); checkBottom(); }
int main() // Main function { low(26); low(27); int irLeft, irRight; // Add startup code here. int leftDist, rightDist; while(1) { drive_setRampStep(10); drive_ramp(64, 64); while(1) { irLeft = checkLeft(); irRight = checkRight(); irRight = ping_cm(8); print ("left = %d, right = %d \n", irLeft, irRight); if(irLeft == 1) { high(26); } else { low(26); } if(ping_cm(8)<=10) { high(27); } else { low(27); } if(irLeft == 1) { drive_ramp(0, 0); turnLeftH(); print (" Left empty hall detected"); break; } if (ping_cm(8)<=9) { drive_ramp(0, 0); turnBack(); print (" End of the line"); break; } } } }
bool BoundingBox::pointInBounds(int xp, int yp) { // Check if the point is in between the top bottom and side lines (all return 0 or negative) if(checkTop(xp,yp)<= 0 && checkBottom(xp,yp) <= 0 && checkLeft(xp,yp)<=0 && checkRight(xp,yp) <= 0) return true; return false; }
void Character::moveRight(RMTiledMap *tiledMap){ if(this->getPosition().x == WIDTH - 1 && this->getPosition().y == 13){ this->setPosAgian(ccp(0, 13), (CCLayer*)this->getSprite()->getParent(), tiledMap); this->setRunCurrent(1); } else if(checkRight(tiledMap, this->position)){ this->spr->runAction(CCMoveBy::create(this->getVelocity(), ccp(tiledMap->getTiledMap()->getTileSize().width, 0))); this->position = ccp(this->position.x + 1, this->position.y); this->setRunCurrent(1); } }
//判断上下左右 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 msasSysReset(int confd,ltMsgHead *ltMsgPk,lt_shmHead *lt_MMHead) { char sIp[24]; char strUserName[64]; char caMsg[256]; memset(sIp,0,sizeof(sIp)); memset(strUserName,0,sizeof(strUserName)); if(checkRight(confd,ltMsgPk,MSAS_RIGHT_SYSADMIN,lt_MMHead)==-1){ return -1; } ltMsgGetSomeNVar(ltMsgPk,2,"clientip", LT_TYPE_STRING, 19, sIp,"manageruser",LT_TYPE_STRING, 32,strUserName); sprintf(caMsg,"%s reboot system success.",strUserName); logWrite(ltMsgPk,caMsg,9); system("/app/msa/bin/msasshutdownall"); system("/sbin/reboot"); system("/sbin/reboot"); return 0; }
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 BoundingBox::calculateResize(int xp, int yp,bool locked, int corner, double *ans) { double xn = 0, yn = 0, dh = 0, dw = 0, xO1 = 0, yO1 = 0; if(corner == CBL) { // Find intersection (xn, yn) of two lines // bottom of element and perpendicular line going through (xp, yp) xn = (mainSlope * xp - sideSlope * xO - yp + yO) / (mainSlope - sideSlope); yn = mainSlope * (xn - xp) + yp; // Calculate the change in width and height (dw, dh) dh = sqrt( pow((xO - xn),2) + pow((yO - yn),2) ); dw = sqrt( pow((xp - xn),2) + pow((yp - yn),2) ); // If the point is inside the box (negative value from checkLeft/Bottom) // The size is getting smaller if(checkLeft(xp, yp) < 0) dw = dw * -1; if(checkBottom(xp, yp) < 0) dh = dh * -1; // if width/ height is negative invert the dw/dh if(width < 0) dw = dw*-1; if(height < 0) dh = dh*-1; // If the aspect ratio is locked choose the bigger change and scale the other appropriately if(locked) { if(fabs(dw) > fabs(dh)) { // Use dw, scale height proportionaly to find dh double scale = (double)(dw+width)/width; double h = height*scale; // The new dh dh = h - height; }else { double scale = (double)(dh+height)/height; double w = width*scale; // The new dw dw = w - width; } } // New origin is (xp,yp) xO1 = xp; yO1 = yp; } if(corner == CBR) { // Find intersection (xn, yn) of two lines // bottom of element and perpendicular line going through (xp, yp) xn = (mainSlope * xp - sideSlope * xBR - yp + yBR) / (mainSlope - sideSlope); yn = mainSlope * (xn - xp) + yp; // Calculate the change in width and height (dw, dh) dh = sqrt( (xBR - xn)*(xBR - xn) + (yBR - yn)*(yBR - yn) ); dw = sqrt( (xp - xn)*(xp - xn) + (yp - yn)*(yp - yn) ); // If the point is inside the right or bottom then the shape is getting smaller dw/dh should be negative if(checkRight(xp, yp) < 0) dw = dw * -1; if(checkBottom(xp, yp) < 0) dh = dh * -1; // if width/ height is negative invert the dw/dh if(width < 0) dw = dw*-1; if(height < 0) dh = dh*-1; // If the aspect ratio is locked choose the bigger change and scale the other appropriately if(locked) { if(fabs(dw) > fabs(dh)) { // Use dw, scale height proportionaly to find dh double scale = (double)(dw+width)/width; double h = height*scale; // The new dh dh = h - height; }else { double scale = (double)(dh+height)/height; double w = width*scale; // The new dw dw = w - width; } } // Calculate the new origin (xO1, yO1) xO1 = xO + dh * cos(angle - PI/2); // angle minus 90 degrees yO1 = yO + dh * sin(angle - PI/2); // angle minus 90 degrees } if(corner == CTR) { // Find intersection (xn, yn) of two lines // bottom of element and perpendicular line going through (xp, yp) xn = (mainSlope * xp - sideSlope * xTR - yp + yTR) / (mainSlope - sideSlope); yn = mainSlope * (xn - xp) + yp; // Calculate the change in width and height (dw, dh) dh = sqrt( (xTR - xn)*(xTR - xn) + (yTR - yn)*(yTR - yn) ); dw = sqrt( (xp - xn)*(xp - xn) + (yp - yn)*(yp - yn) ); // Retain the direction of the change // Acts opposite if angle is below the x axis if(checkRight(xp, yp) < 0)// && angle > 0 && angle < 180 || checkRight(xp, yp) > 0 && angle >180) dw = dw * -1; if(checkTop(xp, yp) < 0 )//&& angle > 0 && angle < 180) dh = dh * -1; // if width/ height is negative invert the dw/dh if(width < 0) dw = dw*-1; if(height < 0) dh = dh*-1; // If the aspect ratio is locked choose the bigger change and scale the other appropriately if(locked) { if(fabs(dw) > fabs(dh)) { // Use dw, scale height proportionaly to find dh double scale = (double)(dw+width)/width; double h = height*scale; // The new dh dh = h - height; }else { double scale = (double)(dh+height)/height; double w = width*scale; // The new dw dw = w - width; } } // Origin remains the same xO1 = xO; yO1 = yO; } if(corner == CTL) { // Find intersection (xn, yn) of two lines // bottom of element and perpendicular line going through (xp, yp) xn = (sideSlope * xTL - mainSlope * xp + yp - yTL) / (sideSlope - mainSlope); yn = yp - mainSlope * (xp - xn); // Calculate the change in width and height (dw, dh) dh = sqrt( (xn - xTL)*(xn - xTL) + (yn - yTL)*(yn - yTL) ); dw = sqrt( (xp - xn)*(xp - xn) + (yp - yn)*(yp - yn) ); // If the point is inside the box (negative value from checkLeft/Top) // The size is getting smaller if(checkLeft(xp, yp) < 0) dw = dw * -1; if(checkTop(xp, yp) < 0) dh = dh * -1; // if width/ height is negative invert the dw/dh if(width < 0) dw = dw*-1; if(height < 0) dh = dh*-1; // If the aspect ratio is locked choose the bigger change and scale the other appropriately if(locked) { if(fabs(dw) > fabs(dh)) { // Use dw, scale height proportionaly to find dh double scale = (double)(dw+width)/width; double h = height*scale; // The new dh dh = h - height; }else { double scale = (double)(dh+height)/height; double w = width*scale; // The new dw dw = w - width; } } // Calculate the new origin (xO1, yO1) xO1 = xO + dw * cos(angle + PI); // 180 plus angle yO1 = yO + dw * sin(angle + PI); // 180 plus angle } /// final new origin width and height ans[0] = xO1; ans[1] = yO1; ans[2] = width + dw; ans[3] = height + dh; }
void FloorGenerator::assignDown(bool room) { int temp = rand() % 8; int posX = start.front().getX(); int posY = start.front().getY(); const int ONEU = 0, TWOV = 1, TWOUL= 2, TWOUR = 3, THREEU = 4, THREEL = 5, THREER = 6, FOUR = 7; switch(temp) { case ONEU: { bool down, left, right; if(posX+2 > LIMIT-1) down = true; else down = !checkDown2(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(down && left && right) { if(room) pushRoom(posX+1, posY, roomoneU, room); else pushCor(posX+1, posY, oneU, room); }else assignDown(room); break; } case TWOV: { if(posX + 2 > LIMIT-1) { assignDown(room); break; }else { bool down, left, right; if(posX+2 > LIMIT-1) down = false; else down = checkDown(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(down && left && right) { if(room) pushRoom(posX+1, posY, roomtwoV, room); else pushCor(posX+1, posY, twoV, room); break; }else assignDown(room); } break; } case TWOUL: { if(posY-1 < 0) { assignDown(room); break; }else { bool down, left, right; if(posX+2 > LIMIT-1) down = true; else down = !checkDown2(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); if(down && left && right) { if(room) pushRoom(posX+1, posY, roomtwoUL, room); else pushCor(posX+1, posY, twoUL, room); }else assignDown(room); } break; } case TWOUR: { if(posY+1 > LIMIT-1) { assignDown(room); break; }else { bool down, left, right; if(posX+2 > LIMIT-1) down = true; else down = !checkDown2(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); if(down && left && right) { if(room) pushRoom(posX+1, posY, roomtwoUR, room); else pushCor(posX+1, posY, twoUR, room); }else assignDown(room); } break; } case THREEU: { if(posY-1 < 0) { assignDown(room); break; }else if(posY+1 > LIMIT-1) { assignDown(room); break; }else { bool down, left, right; if(posX+2 > LIMIT-1) down = true; else down = !checkDown2(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(down && left && right) { if(room) pushRoom(posX+1, posY, roomthreeU, room); else pushCor(posX+1, posY, threeU, room); }else assignDown(room); } break; } case THREEL: { if(posY-1 < 0) { assignDown(room); break; }else if(posX+2 > LIMIT-1) { assignDown(room); break; }else { bool down, left, right; if(posX+2 > LIMIT-1) down = false; else down = checkDown(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); if(down && left && right) { if(room) pushRoom(posX+1, posY, roomthreeL, room); else pushCor(posX+1, posY, threeL, room); }else assignDown(room); } break; } case THREER: { if(posY+1 > LIMIT-1) { assignDown(room); break; }else if(posX+2 > LIMIT-1) { assignDown(room); break; }else { bool down, left, right; if(posX+2 > LIMIT-1) down = false; else down = checkDown(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); if(down && left && right) { if(room) pushRoom(posX+1, posY, roomthreeR, room); else pushCor(posX+1, posY, threeR, room); }else assignDown(room); } break; } case FOUR: { if(posY+1 > LIMIT-1) { assignDown(room); break; }else if(posY-1 < 0) { assignDown(room); break; }else if(posX+2 > LIMIT-1) { assignDown(room); break; }else { bool down, left, right; if(posX+2 > LIMIT-1) down = false; else down = checkDown(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(down && left && right) { if(room) pushRoom(posX+1, posY, roomfour, room); else pushCor(posX+1, posY, four, room); }else assignDown(room); } break; } }//end switch }
void StringTestCase::testRight() { checkRight(Sid::String(), 0, Sid::String()); checkRight(Sid::String(), 1, Sid::String()); checkRight(Sid::String(), -1, Sid::String()); checkRight(Sid::String(4), 0, ""); checkRight(Sid::String(4), 1, ""); checkRight(Sid::String(4), -1, ""); checkRight("f", 0, ""); checkRight("f", 1, "f"); checkRight("f", -1, "f"); checkRight("f", 999, "f"); checkRight("foobajooba", 2, "ba"); checkRight("foobajooba", 7, "bajooba"); checkRight("foobajooba", -1, "foobajooba"); checkRight("foobajooba", 10, "foobajooba"); }
//return how many lifing cels are around a position in field. int totalAround(uint8_t *field, int position){ int around = checkUpper(field, position)+checkLower(field, position)+checkLeft(field, position)+checkRight(field, position)+checkUpperLeft(field, position)+checkUpperRight(field, position)+checkLowerLeft(field, position)+checkLowerRight(field, position); return around; }
void Cat::autoRun(RMTiledMap* tileMap){ if(this->getRunCurrent() == 1){ if(this->checkBelow(tileMap, this->getPosition()) || this->checkUpward(tileMap, this->getPosition())){ int randNumber = rand() % 4; if(!checkRight(tileMap, this->getPosition())){ randNumber = rand() % 2; } switch (randNumber) { case 3: setRunValue(1); break; case 2: setRunValue(1); break; case 1: if(checkUpward(tileMap, this->getPosition())){ setRunValue(4); } else if (checkBelow(tileMap, this->getPosition())){ setRunValue(3); } break; case 0: if(this->checkBelow(tileMap, this->getPosition())){ setRunValue(4); } else if (checkUpward(tileMap, this->getPosition())){ setRunValue(3); } break; default: break; } } else if(!checkRight(tileMap, this->getPosition())){ setRunValue(2); } } else if(this->getRunCurrent() == 2){ if(this->checkBelow(tileMap, this->getPosition()) || this->checkUpward(tileMap, this->getPosition())){ int randNumber = rand() % 4; if(!checkLeft(tileMap, this->getPosition())){ randNumber = rand() % 2; } switch (randNumber) { case 3: setRunValue(2); break; case 2: setRunValue(2); break; case 1: if(checkUpward(tileMap, this->getPosition())){ setRunValue(4); } else if (checkBelow(tileMap, this->getPosition())){ setRunValue(3); } break; case 0: if(this->checkBelow(tileMap, this->getPosition())){ setRunValue(4); } else if (checkUpward(tileMap, this->getPosition())){ setRunValue(3); } break; default: break; } } else if(!checkLeft(tileMap, this->getPosition())){ setRunValue(1); } } else if(this->getRunCurrent() == 3){ if(this->checkLeft(tileMap, this->getPosition()) || this->checkRight(tileMap, this->getPosition())){ int randNumber = rand() % 4; if(!checkUpward(tileMap, this->getPosition())){ randNumber = rand() % 2; } switch (randNumber) { case 3: setRunValue(3); break; case 2: setRunValue(3); break; case 1: if(checkRight(tileMap, this->getPosition())){ setRunValue(1); } else if (checkLeft(tileMap, this->getPosition())){ setRunValue(2); } break; case 0: if(this->checkLeft(tileMap, this->getPosition())){ setRunValue(2); } else if (checkRight(tileMap, this->getPosition())){ setRunValue(1); } break; default: break; } } else if(!checkUpward(tileMap, this->getPosition())){ setRunValue(4); } } else if(this->getRunCurrent() == 4){ if(this->checkLeft(tileMap, this->getPosition()) || this->checkRight(tileMap, this->getPosition())){ int randNumber = rand() % 4; if(!checkBelow(tileMap, this->getPosition())){ randNumber = rand() % 2; } switch (randNumber) { case 3: setRunValue(4); break; case 2: setRunValue(4); break; case 1: if(checkRight(tileMap, this->getPosition())){ setRunValue(1); } else if (checkLeft(tileMap, this->getPosition())){ setRunValue(2); } break; case 0: if(this->checkLeft(tileMap, this->getPosition())){ setRunValue(2); } else if (checkRight(tileMap, this->getPosition())){ setRunValue(1); } break; default: break; } } else if(!checkBelow(tileMap, this->getPosition())){ setRunValue(3); } } }
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 }
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 DeleteVM::Do() { String logContent; log.write("begin DeleteVM::Do().", Log::INFO); //参数检查 log.write("begin process parameter.", Log::INFO); if( getPara() == false) { ackCode = "ACK:DELETE VM:RETN=4,DESC=parameters error"; return; } log.write("end process parameter.", Log::INFO); //检测虚拟机是否存在 if( isVMExist() == false) { ackCode = "ACK:DELETE VM:RETN=1001,DESC=vm is not exist"; return; } //鉴权 if( checkRight( vmID ) == false ) { ackCode = "ACK:DELETE VM:RETN=14,DESC=no right"; return; } if( isVMStarted() == true ) { ackCode = "ACK:DELETE VM:RETN=1002,DESC=vm is running,please close it first"; return; } if( getNFSInfo() == false ) { ackCode = "ACK:DELETE VM:RETN=8,DESC=system internal error"; return; } if( mountNFS() == 1 ) { ackCode = "ACK:DELETE VM:RETN=8,DESC=system internal error"; return; } if ( deleteNATRule() == false ) { ackCode = "ACK:DELETE VM:RETN=8,DESC=system internal error,delete nat rule failed."; return; } if( delVMFile() == false ) { ackCode = "ACK:DELETE VM:RETN=8,DESC=system internal error,delete vm files error."; return; } if( applySC2FreeDisk() == false ) { ackCode = "ACK:DELETE VM:RETN=8,DESC=system internal error,free disk space error."; return; } delVMFromDB(); ackCode = "ACK:DELETE VM:RETN=0,DESC=success"; }