bool CampoMinas::colocaMinas(Mina** m){ bool bien=true; Coordenada c,c2; int i,j,cont=0; while(m[cont]!=NULL)cont++; //if(Aplicacion::getInstancia()!=NULL) cont=Aplicacion::getInstancia()->getNumMinas();No funciona for(j=0;((j<cont)&&(bien==true));j++){ i=0; do{ i++; c=c.getCoordenadaAleatoria(getDimX(),getDimY()); }while((hasMina(c))&&(i<MAX_INTENTOS)); if (!hasMina(c)){ getCasilla(c).setMina(*m[j]); } else{ cerr<<"Error al colocar las minas (Colocaminas)"<<endl; bien=false; } } for(i=1;((i<=getDimX())&&(bien==true));i++){ for(j=1;j<=getDimY();j++){ c2.setCoordX(i); c2.setCoordY(j); setNumMinasAlrededorCasilla(c2); } } return(bien); }
CampoMinas::~CampoMinas(){ int i; bool control=true; for (i=0;((i<getDimX())&&(control==true));i++) { if(casilla[i]){ delete[]casilla[i]; } else{ control=false; } } delete[]casilla; casilla=NULL; dimx=0; dimy=0; }
/* check if a move is valid */ int validMove(int fromX, int fromY, int toX, int toY) { int dimX = getDimX(), dimY = getDimY(); if (toX >= dimX || toY >= dimY || toY < 0 || toX < 0) { return 0; } char next = getTile(toX, toY); if (next == WALL) { return 0; } if (next == BOX || next == BOX_ON_TARGET) { int newMovableY = toY+(toY-fromY); int newMovableX = toX+(toX-fromX); char newMovablePos = getTile(newMovableX, newMovableY); if (newMovablePos == WALL || newMovablePos == BOX || newMovablePos == BOX_ON_TARGET) { return 0; } } return 1; }
int CampoMinas::calculaPuntos(){ int puntos=0,i,j; Coordenada coord; for(i=0;i<getDimX();i++){ for(j=0;j<getDimY();j++){ coord.setCoordX(i+1); coord.setCoordY(j+1); if(getCasilla(coord).getMarcada()){ if(hasMina(coord)){ puntos=puntos+(getCasilla(coord).getMina()->getPuntos()); } else{ puntos--; } } } } if(puntos<0) puntos=0; return(puntos); }
bool CampoMinas::marcaCasilla(const Coordenada &c){ bool res; if ((c.getCoordX()>getDimX())||(c.getCoordY()>getDimY())||(c.getCoordX()<1)||(c.getCoordY()<1)){ res=false; } else{ if (getCasilla(c).getDescubierta()){ res=false; } else{ if (getCasilla(c).getMarcada()){ res=false; } else{ getCasilla(c).setMarcada(); res=true; } } } return(res); }
void CampoMinas::setNumMinasAlrededorCasilla(Coordenada &c){ int x=c.getCoordX(), y=c.getCoordY(),minas=0; if ((x-1)<1){ if((y+1)>getDimY()){ if((casilla[x][y-1]).getMina()!=NULL) minas++; if((casilla[x][y-2]).getMina()!=NULL) minas++; if((casilla[x-1][y-2]).getMina()!=NULL) minas++; } else{ if((y-1)<1){ if((casilla[x-1][y]).getMina()!=NULL) minas++; if((casilla[x][y]).getMina()!=NULL) minas++; if((casilla[x][y-1]).getMina()!=NULL) minas++; } else{ if((casilla[x][y-1]).getMina()!=NULL) minas++; if((casilla[x][y-2]).getMina()!=NULL) minas++; if((casilla[x-1][y-2]).getMina()!=NULL) minas++; if((casilla[x-1][y]).getMina()!=NULL) minas++; if((casilla[x][y]).getMina()!=NULL) minas++; } } } else{ if ((x+1)>getDimX()){ if((y+1)>getDimY()){ if((casilla[x-2][y-1]).getMina()!=NULL) minas++; if((casilla[x-2][y-2]).getMina()!=NULL) minas++; if((casilla[x-1][y-2]).getMina()!=NULL) minas++; } else{ if((y-1)<1){ if((casilla[x-1][y]).getMina()!=NULL) minas++; if((casilla[x-2][y]).getMina()!=NULL) minas++; if((casilla[x-2][y-1]).getMina()!=NULL) minas++; } else{ if((casilla[x-2][y-1]).getMina()!=NULL) minas++; if((casilla[x-2][y-2]).getMina()!=NULL) minas++; if((casilla[x-1][y-2]).getMina()!=NULL) minas++; if((casilla[x-1][y]).getMina()!=NULL) minas++; if((casilla[x-2][y]).getMina()!=NULL) minas++; } } } else{ if((y+1)>getDimY()){ if((casilla[x-2][y-1]).getMina()!=NULL) minas++; if((casilla[x-2][y-2]).getMina()!=NULL) minas++; if((casilla[x-1][y-2]).getMina()!=NULL) minas++; if((casilla[x][y-1]).getMina()!=NULL) minas++; if((casilla[x][y-2]).getMina()!=NULL) minas++; } else{ if((y-1)<1){ if((casilla[x-1][y]).getMina()!=NULL) minas++; if((casilla[x-2][y]).getMina()!=NULL) minas++; if((casilla[x-2][y-1]).getMina()!=NULL) minas++; if((casilla[x][y]).getMina()!=NULL) minas++; if((casilla[x][y-1]).getMina()!=NULL) minas++; } else{ if((casilla[x-2][y-1]).getMina()!=NULL) minas++; if((casilla[x-2][y-2]).getMina()!=NULL) minas++; if((casilla[x-1][y-2]).getMina()!=NULL) minas++; if((casilla[x][y-1]).getMina()!=NULL) minas++; if((casilla[x][y-2]).getMina()!=NULL) minas++; if((casilla[x-1][y]).getMina()!=NULL) minas++; if((casilla[x-2][y]).getMina()!=NULL) minas++; if((casilla[x][y]).getMina()!=NULL) minas++; } } } } casilla[x-1][y-1].setNumMinasAlrededor(minas); }
bool VolumeFileSink::writeRawData(char* data, uint xMin, uint yMin, uint zMin, uint xMax, uint yMax, uint zMax, uint variable, uint timeStep) { uint width = xMax-xMin+1; uint height = yMax-yMin+1; uint depth = zMax-zMin+1; uint j,k; bool ret = false; if (!m_VolumeFile) return ret; if (width == m_VolumeFile->getDimX()) { // this is the fast case for writes. // because the width of the volume being written is the same as // the file's width, we can write in slice sized increments. // (bigger writes are better, for the most part) switch (m_VolumeFile->getVariableType(variable)) { case VolumeFile::Char: { // loop through each slice for (k=0; k<depth; k++) { // write a slice ret = m_VolumeFile->writeCharData( (unsigned char*)data+(k*width*height), (zMin+k)*getDimX()*((Q_ULLONG)getDimY()) + yMin*getDimX(), width*height, variable, timeStep); } break; } case VolumeFile::Short: { // loop through each slice for (k=0; k<depth; k++) { // write a slice ret = m_VolumeFile->writeShortData( (unsigned short*)data+(k*width*height), (zMin+k)*getDimX()*((Q_ULLONG)getDimY()) + yMin*getDimX(), width*height, variable, timeStep); } break; } case VolumeFile::Long: { // loop through each slice for (k=0; k<depth; k++) { // write a slice ret = m_VolumeFile->writeLongData( (unsigned int*)data+(k*width*height), (zMin+k)*getDimX()*((Q_ULLONG)getDimY()) + yMin*getDimX(), width*height, variable, timeStep); } break; } case VolumeFile::Float: { // loop through each slice for (k=0; k<depth; k++) { // write a slice ret = m_VolumeFile->writeFloatData( (float*)data+(k*width*height), (zMin+k)*getDimX()*((Q_ULLONG)getDimY()) + yMin*getDimX(), width*height, variable, timeStep); } break; } case VolumeFile::Double: { // loop through each slice for (k=0; k<depth; k++) { // write a slice ret = m_VolumeFile->writeDoubleData( (double*)data+(k*width*height), (zMin+k)*getDimX()*((Q_ULLONG)getDimY()) + yMin*getDimX(), width*height, variable, timeStep); } break; } default: break; } } else { // this is the catch all version // it works just fine, but it calls writeData() way more than the previous // version. switch (m_VolumeFile->getVariableType(variable)) { case VolumeFile::Char: { // loop through each slice for (k=0; k<depth; k++) { // loop through each line for (j=0; j<height; j++) { // write a line ret = m_VolumeFile->writeCharData( (unsigned char*)data+(k*width*height + j*width), (zMin+k)*getDimX()*((Q_ULLONG)getDimY())+((yMin+j)*getDimX())+xMin, width, variable, timeStep); } } break; } case VolumeFile::Short: { // loop through each slice for (k=0; k<depth; k++) { // loop through each line for (j=0; j<height; j++) { // write a line ret = m_VolumeFile->writeShortData( (unsigned short*)data+(k*width*height + j*width), (zMin+k)*getDimX()*((Q_ULLONG)getDimY())+((yMin+j)*getDimX())+xMin, width, variable, timeStep); } } break; } case VolumeFile::Long: { // loop through each slice for (k=0; k<depth; k++) { // loop through each line for (j=0; j<height; j++) { // write a line ret = m_VolumeFile->writeLongData( (unsigned int*)data+(k*width*height + j*width), (zMin+k)*getDimX()*((Q_ULLONG)getDimY())+((yMin+j)*getDimX())+xMin, width, variable, timeStep); } } break; } case VolumeFile::Float: { // loop through each slice for (k=0; k<depth; k++) { // loop through each line for (j=0; j<height; j++) { // write a line ret = m_VolumeFile->writeFloatData( (float*)data+(k*width*height + j*width), (zMin+k)*getDimX()*((Q_ULLONG)getDimY())+((yMin+j)*getDimX())+xMin, width, variable, timeStep); } } break; } case VolumeFile::Double: { // loop through each slice for (k=0; k<depth; k++) { // loop through each line for (j=0; j<height; j++) { // write a line ret = m_VolumeFile->writeDoubleData( (double*)data+(k*width*height + j*width), (zMin+k)*getDimX()*((Q_ULLONG)getDimY())+((yMin+j)*getDimX())+xMin, width, variable, timeStep); } } break; } default: // shouldn't get here. ret remains unchanged. break; } } return ret; }