void Swan::move(Floor& floor){ location deltaPos, current, next; int input; current = getPos(); do{ deltaPos.r = 0; deltaPos.c = 0; next = current; input = rand()%4; if(input == 0){ deltaPos.r--; } else if(input == 1){ deltaPos.c--; } else if(input == 2){ deltaPos.r++; } else if(input == 3){ deltaPos.c++; } next.r += deltaPos.r; next.c += deltaPos.c; }while(invalidMove(next, floor)); floor.setTile(current.r, current.c, getTileBelow()); if(getTileBelow() == 'P') floor.setTile(current.r, current.c, ' '); setTileBelow(floor.getTile(next.r, next.c)); setPos(next); floor.setTile(next.r, next.c, 'S'); }
bool Swan::invalidMove(location next, Floor floor){ location floorSize = floor.getSize(); char nextTile = floor.getTile(next.r, next.c); if(nextTile == '#'){ return true; } if(nextTile == 'D'){ return true; } if(nextTile == 'E'){ return true; } if(next.r<0 || next.c<0 || next.r>floorSize.r || next.c>floorSize.c){ return true; } return false; }
void KServer::recv_landscape( vce::VSint32 floorID, vce::VSint32 x1,vce::VSint32 y1,vce::VSint32 x2,vce::VSint32 y2) { if( !m_authenticationSuccess )return; if( !m_pc )return; Floor *fl = World::getFloor(floorID); if(!fl)return; TileType data[4000]; int ind = 0; for(int y=y1; y < y2; y++ ){ for(int x=x1; x < x2; x++){ data[ind++] = fl->getTile(Coord(x,y)).typeID; if( ind == ARRAYLEN(data)) break; } if( ind == ARRAYLEN(data)) break; } send_landscapeResult( floorID, x1,y1,x2,y2, data, ind ); }