void editor::actNew() { if (levelLoaded) level.clear(); int wNew = QInputDialog::getInt(this, QString("Creating the map"), QString("Width:"), 0, 0, 1024); int hNew = QInputDialog::getInt(this, QString("Creating the map"), QString("Height:"), 0, 0, 1024); QString nameNew = QInputDialog::getText(this, QString("Creating the map"), QString("Name:")); QFile f("maps/"+nameNew+".snsmap"); f.open(QIODevice::WriteOnly); QDataStream out(&f); _map tmp; tmp.w=wNew; tmp.h=hNew; tmp.allocate(); for (int i=0; i<tmp.w; i++) for (int j=0; j<tmp.h; j++) { tmp[i][j].type = 0; qstrcpy(tmp[i][j].color, "#ffffff"); tmp[i][j].durability = 0; } out << tmp; readLevel("maps/"+nameNew+".snsmap"); }
void ConsoleGame::handlePerft(std::istringstream & iss) const { uint perftLevel = readLevel(iss); if (perftLevel == 0) return; doPerft(perftLevel); }
void ConsoleGame::handleDivide(std::istringstream & iss) const { uint perftLevel = readLevel(iss); if (perftLevel == 0) return; Perft perft(mBoard.get()); perft.divide(perftLevel); }
void editor::actOpen() { if (levelLoaded) level.clear(); QString file = QFileDialog::getOpenFileName(); readLevel(file); mapFilename = file; pixmap = new QPixmap(level.w*tilesize, level.h*tilesize); render(); levelLoaded = true; }
void set_current_profile(Profile* profile) { current_profile = profile; if(current_profile->id != 9) { if(current_profile->current_level > 0) { // Read the level printf("Reading map \n"); readLevel(brickmap->brickArray, current_profile->id); level = current_profile->current_level; }else { level = 1; } } return; }
int main(){ NME player; NME dumbOgres[MAX_NMES]; int numNMES; int inp; char level[MAX_H][MAX_W]; player.x = 19; player.y = 24; //making window large enough HWND console = GetConsoleWindow(); RECT r; GetWindowRect(console, &r); MoveWindow(console, r.left, r.top, 1280, 720, TRUE); genNewLvl(); readLevel (level); writeToFile(level); setStart (&player, level); numNMES = setNMES (dumbOgres, level); do{ printf("Past Here"); getch(); drawBoard(level, player, dumbOgres, numNMES); inp=getch(); useInp(&player, inp, level); movNMES(dumbOgres, numNMES, &player, level); }while(inp!=27); return 0; }
int main(int argc, char* argv[]) { unsigned int largeurNiveau = 0, hauteurNiveau = 0; unsigned int numLvl = 1; Niveau level; LevelError code_e; CoupsJoues pileDeCoups = NULL; Coup* coupDepile = NULL; PileCible pileDeCibles = NULL; char cheminFichierSolution[27] = {0}; FILE* fichierSolution = NULL; Position positionJoueur; unsigned int nbPoussee = 0, nbMvt = 0; char continuerBoucle = 1; SDLInitError sdl_e; SDL_Surface *ecran; SDL_Event event; SDL_Surface** tableauSprites = NULL; if(argc > 1) { numLvl = atoi(argv[1]); } code_e = readLevel(FICHIER_NIVEAUX, &level, numLvl, &largeurNiveau, &hauteurNiveau, &positionJoueur, &pileDeCibles); if(code_e != NoError) { fprintf(stderr, "(%d) Erreur de lecture du fichier de niveau \"%s\".\n", code_e, FICHIER_NIVEAUX); libererPileCible(&pileDeCibles); freeNiveau(&level, hauteurNiveau); exit(EXIT_FAILURE); } sdl_e = initSDL(&ecran); if(sdl_e != InitOk) { fprintf(stderr, "(%d) Erreur lors de initSDL(SDL_Surface**).\n", sdl_e); libererPileCible(&pileDeCibles); freeNiveau(&level, hauteurNiveau); freeSDL(NULL); exit(EXIT_FAILURE); } tableauSprites = (SDL_Surface**)malloc(NB_SPRITE * sizeof(SDL_Surface*)); if(tableauSprites == NULL) { fprintf(stderr, "Erreur d'allocation du tableau de sprites.\n"); libererPileCible(&pileDeCibles); freeNiveau(&level, hauteurNiveau); freeSDL(NULL); exit(EXIT_FAILURE); } sdl_e = loadSprites(&tableauSprites); if(sdl_e != InitOk) { fprintf(stderr, "(%d) Erreur de chargement des sprites dans le tableau de sprites.\n", sdl_e); libererPileCible(&pileDeCibles); freeNiveau(&level, hauteurNiveau); freeSDL(&tableauSprites); exit(EXIT_FAILURE); } printf("Niveau %d\n", numLvl); afficheNiveau(&level, largeurNiveau, hauteurNiveau); dessineEntete(ecran); dessineCompteurs(ecran, nbMvt, nbPoussee); dessineNiveau(&level, ecran, largeurNiveau, hauteurNiveau, &tableauSprites); while (continuerBoucle) { while(SDL_PollEvent(&event)) { switch(event.type) { case SDL_QUIT: continuerBoucle = 0; break; case SDL_KEYDOWN: switch (event.key.keysym.sym) { case SDLK_ESCAPE: continuerBoucle = 0; break; case SDLK_UP: arrowKeyDownHandler(HAUT, &level, &positionJoueur, &pileDeCoups, &nbMvt, &nbPoussee); break; case SDLK_DOWN: arrowKeyDownHandler(BAS, &level, &positionJoueur, &pileDeCoups, &nbMvt, &nbPoussee); break; case SDLK_RIGHT: arrowKeyDownHandler(DROITE, &level, &positionJoueur, &pileDeCoups, &nbMvt, &nbPoussee); break; case SDLK_LEFT: arrowKeyDownHandler(GAUCHE, &level, &positionJoueur, &pileDeCoups, &nbMvt, &nbPoussee); break; case SDLK_r: libererPile(&pileDeCoups); code_e = updateLevel(LevelReset, FICHIER_NIVEAUX, &level, &positionJoueur, &pileDeCibles, &numLvl, &largeurNiveau, &hauteurNiveau); if(code_e != NoError) { fprintf(stderr, "(%d) Erreur lors du redemarrage du niveau.\n", code_e); libererPileCible(&pileDeCibles); freeNiveau(&level, hauteurNiveau); freeSDL(&tableauSprites); exit(EXIT_FAILURE); } nbMvt = 0; nbPoussee = 0; break; case SDLK_e: libererPile(&pileDeCoups); code_e = updateLevel(LevelPrevious, FICHIER_NIVEAUX, &level, &positionJoueur, &pileDeCibles, &numLvl, &largeurNiveau, &hauteurNiveau); if(code_e != NoError) { fprintf(stderr, "(%d) Erreur lors du passage au niveau precedent.\n", code_e); libererPileCible(&pileDeCibles); freeNiveau(&level, hauteurNiveau); freeSDL(&tableauSprites); exit(EXIT_FAILURE); } nbMvt = 0; nbPoussee = 0; printf("Niveau %d\n", numLvl); afficheNiveau(&level, largeurNiveau, hauteurNiveau); break; case SDLK_t: sprintf(cheminFichierSolution, "./save/level%d.sol", numLvl); fichierSolution = fopen(cheminFichierSolution, "r"); if(fichierSolution != NULL) { fclose(fichierSolution); libererPile(&pileDeCoups); code_e = updateLevel(LevelNext, FICHIER_NIVEAUX, &level, &positionJoueur, &pileDeCibles, &numLvl, &largeurNiveau, &hauteurNiveau); if(code_e != NoError) { fprintf(stderr, "(%d) Erreur lors du passage au niveau suivant.\n", code_e); libererPileCible(&pileDeCibles); freeNiveau(&level, hauteurNiveau); freeSDL(&tableauSprites); exit(EXIT_FAILURE); } nbMvt = 0; nbPoussee = 0; printf("Niveau %d\n", numLvl); afficheNiveau(&level, largeurNiveau, hauteurNiveau); } break; case SDLK_w: /* NB: ceci est la version windows, allez savoir pourquoi SDL prend le clavier en qwerty */ if ((event.key.keysym.mod & KMOD_LCTRL) == KMOD_LCTRL) { coupDepile = depilerCoup(&pileDeCoups); if(coupDepile != NULL) { deplacerObjetRetour(&level, *coupDepile, &nbMvt, &nbPoussee); calculPosition(&positionJoueur, (*coupDepile).direction, Negatif); free(coupDepile); } } break; case SDLK_q: /* NB: ceci est la version windows, allez savoir pourquoi SDL prend le clavier en qwerty */ creerFichierSauvegarde(Sauvegarde, numLvl, &pileDeCoups); break; case SDLK_a: /* NB: ceci est la version windows, allez savoir pourquoi SDL prend le clavier en qwerty */ chargerFichierSauvegarde(numLvl, &pileDeCoups, &level, &positionJoueur, &pileDeCibles, &nbMvt, &nbPoussee); break; default: break; } if(toutesCiblesValidees(&pileDeCibles, &level) == CibleValidee) { printf("Niveau %d termine en %d mouvements et en %d poussees ! \n", numLvl, nbMvt, nbPoussee); creerFichierSauvegarde(Solution, numLvl, &pileDeCoups); libererPile(&pileDeCoups); code_e = updateLevel(LevelNext, FICHIER_NIVEAUX, &level, &positionJoueur, &pileDeCibles, &numLvl, &largeurNiveau, &hauteurNiveau); if(code_e != NoError) { fprintf(stderr, "(%d) Erreur lors du passage au niveau suivant.\n", code_e); libererPileCible(&pileDeCibles); freeNiveau(&level, hauteurNiveau); freeSDL(&tableauSprites); exit(EXIT_FAILURE); } nbMvt = 0; nbPoussee = 0; printf("Niveau %d\n", numLvl); afficheNiveau(&level, largeurNiveau, hauteurNiveau); } break; default: break; } } effacerNiveau(ecran); dessineEntete(ecran); dessineCompteurs(ecran, nbMvt, nbPoussee); dessineNiveau(&level, ecran, largeurNiveau, hauteurNiveau, &tableauSprites); SDL_Flip(ecran); SDL_Delay(20); } libererPile(&pileDeCoups); libererPileCible(&pileDeCibles); freeNiveau(&level, hauteurNiveau); freeSDL(&tableauSprites); return EXIT_SUCCESS; }
int test() { #ifdef CH_USE_HDF5 int error; HDF5Handle testFile; CH_assert(!testFile.isOpen()); error = testFile.open("data.h5", HDF5Handle::CREATE); if (error != 0) { if ( verbose ) pout() << indent2 << "File creation failed "<<error<<endl; return error; } CH_assert(testFile.isOpen()); Box domain(IntVect::Zero, 20*IntVect::Unit); DisjointBoxLayout plan1, plan2; { IntVectSet tags; IntVect center = 10*IntVect::Unit; setCircleTags(tags, 6, 1, center); //circle/sphere buildDisjointBoxLayout(plan1, tags, domain); tags.makeEmpty(); setCircleTags(tags, 5, 2, center); buildDisjointBoxLayout(plan2, tags, domain); } if ( verbose ) { pout() << "plan1: " << procID() << "...." << plan1 << endl; pout() << "plan2: " << procID() << "...." << plan2 << endl; } //test LayoutData<Real> specialization LayoutData<Real> specialReal(plan1); LayoutData<Moment> vlPlan(plan1); LevelData<BaseFab<int> > level1(plan1, 3, IntVect::Unit); LevelData<BaseFab<int> > level2; level2.define(level1); level2.define(plan2, 1); for (DataIterator i(level2.dataIterator()); i.ok(); ++i) { level2[i()].setVal(2); } level1.apply(values::setVal1); level2.apply(values::setVal2); HDF5HeaderData set1; Real dx=0.004; Box b1(IntVect(D_DECL6(1,2,1,1,2,1)), IntVect(D_DECL6(4,4,4,4,4,4))); Box b2(IntVect(D_DECL6(5,2,1,5,2,1)), IntVect(D_DECL6(12,4,4,12,4,4))); int currentStep = 2332; set1.m_string["name"] = "set1"; set1.m_real["dx"] = dx; set1.m_int["currentStep"] = currentStep; set1.m_intvect["some intvect or other"] = b1.smallEnd(); set1.m_box["b1"] = b1; set1.m_box["b2"] = b2; testFile.setGroupToLevel(1); error = write(testFile, plan1); if (error != 0) { if ( verbose ) pout() << indent2 << "box write failed "<<error<<endl; return error; } error = write(testFile, level1, "level1 state vector"); if (error != 0) { if ( verbose ) pout() << indent2 << "BoxLayoutData 1 write failed "<<error<<endl; return error; } testFile.setGroupToLevel(2); error = write(testFile, plan2); if (error != 0) { if ( verbose ) pout() << indent2 << "box2 write failed "<<error<<endl; return error; } error = write(testFile, level2, "level2 state vector"); if (error != 0) { if ( verbose ) pout() << indent2 << "BoxLayoutData 2 write failed "<<error<<endl; return error; } LevelData<FArrayBox> state(plan2, 3); state.apply(values::setVal3); testFile.setGroupToLevel(0); set1.writeToFile(testFile); error = write(testFile, plan2); if (error != 0) { if ( verbose ) pout() << indent2 << "box2 write failed "<<error<<endl; return error; } testFile.setGroup("/"); error = writeLevel(testFile, 0, state, 2, 1, 0.001, b2, 2); if (error != 0) { if ( verbose ) pout() << indent2 << "BoxLayoutData 2 write failed "<<error<<endl; return error; } set1.writeToFile(testFile); set1.writeToFile(testFile); testFile.close(); CH_assert(!testFile.isOpen()); // test the utility functions ReadUGHDF5 and WriteUGHDF5 WriteUGHDF5("UGIO.hdf5", plan2, state, domain); ReadUGHDF5("UGIO.hdf5", plan2, state, domain); //======================================================================== // // now, read this data back in // //======================================================================== BoxLayoutData<BaseFab<int> > readlevel1, readlevel2; error = testFile.open("data.h5", HDF5Handle::OPEN_RDONLY); if (error != 0) { if ( verbose ) pout() << indent2 << "File open failed "<<error<<endl; return error; } testFile.setGroupToLevel(2); Vector<Box> boxes; error = read(testFile, boxes); if (error != 0) { if ( verbose ) pout() << indent2 << "box read failed "<<error<<endl; return error; } boxes.sort(); Vector<int> assign; error = LoadBalance(assign, boxes); if (error != 0) { if ( verbose ) pout() << indent2 << "BoxLayout LoadBalance failed "<<error<<endl; return error; } BoxLayout readplan2(boxes, assign); readplan2.close(); error = read(testFile, readlevel2, "level2 state vector", readplan2); if (error != 0) { if ( verbose ) pout() << indent2 << "BoxLayoutData<BaseFab<int>> read failed "<<error<<endl; return error; } testFile.setGroupToLevel(1); error = read(testFile, boxes); if (error != 0) { if ( verbose ) pout() << indent2 << "box read failed "<<error<<endl; return error; } error = LoadBalance(assign, boxes); if (error != 0) { if ( verbose ) pout() << indent2 << "BoxLayout LoadBalance failed "<<error<<endl; return error; } BoxLayout readplan1(boxes, assign); readplan1.close(); if ( verbose ) { pout() << "readplan1: " << procID() << "...." << readplan1 << endl; pout() << "readplan2: " << procID() << "...." << readplan2 << endl; } error = read(testFile, readlevel1, "level1 state vector", readplan1); if (error != 0) { if ( verbose ) pout() << indent2 << "BoxLayoutData<BaseFab<int>> read failed "<<error<<endl; return error; } if ( verbose ) pout() << plan1<<readplan1<<endl; // real test of IO, make sure the data is the same coming and going DataIterator l1 = level1.dataIterator(); DataIterator rl1 = readlevel1.dataIterator(); DataIterator l2 = level2.dataIterator(); DataIterator rl2 = readlevel2.dataIterator(); if (level1.boxLayout().size() != readlevel1.boxLayout().size()) { if ( verbose ) pout() << indent2 << "level1.size() != readl1.size() read failed "<<error<<endl; return 1; } if (level2.boxLayout().size() != readlevel2.boxLayout().size()) { if ( verbose ) pout() << indent2 << "level2.size() != readl2.size() read failed "<<error<<endl; return 1; } // we can assume that BoxLayout IO is tested in HDF5boxIO BaseFab<int>* before, *after; for (; l1.ok(); ++l1, ++rl1) { before = &(level1[l1()]); after = &(readlevel1[rl1()]); for (int c=0; c<before->nComp(); ++c) { for (BoxIterator it(level1.box(l1())); it.ok(); ++it) { if ((*before)(it(), c) != (*after)(it(), c)) { if ( verbose ) pout() << indent2 << "l1 != readl1 read failed "<<error<<endl; return 2; } } } } for (; l2.ok(); ++l2, ++rl2) { before = &(level2[l2()]); after = &(readlevel2[rl2()]); for (int c=0; c<before->nComp(); ++c) { for (BoxIterator it(level2.box(l2())); it.ok(); ++it) { if ((*before)(it(), c) != (*after)(it(), c)) { if ( verbose ) pout() << indent2 << "level2 != readlevel2 read failed "<<error<<endl; return 3; } } } } LevelData<FArrayBox> readState; Real dt, time; int refRatio; testFile.setGroup("/"); error = readLevel(testFile, 0, readState, dx, dt, time, b2, refRatio); if (error != 0) { if ( verbose ) pout() << indent2 << "readLevel failed "<<error<<endl; return error; } #ifndef CH_MPI // OK, now try to read one FArrayBox at a time // problem with DataIterator and running the out-of-core in parallel, so // have to think about that for now BVS. FArrayBox readFAB; Interval interval(1,2); testFile.setGroup("/"); int index=0; for (DataIterator dit(state.dataIterator()); dit.ok(); ++index,++dit) { FArrayBox& fab = state[dit()]; readFArrayBox(testFile, readFAB, 0, index, interval); for (BoxIterator it(state.box(dit())) ; it.ok() ; ++it) { if (readFAB(it(), 0) != fab(it(), 1)) { if ( verbose ) pout() << indent2 << "state != after for out-of-core "<<error<<endl; return 3; } } } #endif testFile.close(); CH_assert(!testFile.isOpen()); #endif // CH_USE_HDF5 return 0; }
// controller initialization void Controller::init(std::ifstream &infd) { readLevel(infd); createWindow(); }
void NetManager::readServerPacket(ENetEvent& event) { if(event.packet->flags & ENET_PACKET_FLAG_RELIABLE) { size_t position = 0; if(mClientRecievedId == false) { mClientRecievedId = true; size_t playerId; readFromPacket(event.packet, position, playerId); FAWorld::World::get()->getCurrentPlayer()->mId = playerId; return; } int32_t typeHeader; readFromPacket(event.packet, position, typeHeader); switch(typeHeader) { case ReliableMessageKind::Level: { readLevel(event.packet, position); FAWorld::World::get()->setLevel(0); break; } case ReliableMessageKind::Sprite: { readSpriteResponse(event.packet, position); break; } } } else { FAWorld::World& world = *FAWorld::World::get(); size_t position = 0; ServerPacketHeader header; readFromPacket(event.packet, position, header); if(header.tick > mLastServerTickProcessed) { for(size_t i = 0; i < header.numPlayers; i++) { int32_t classId; int32_t actorId; readFromPacket(event.packet, position, classId); readFromPacket(event.packet, position, actorId); FAWorld::Actor* actor = world.getActorById(actorId); if(actor == NULL) { actor = dynamic_cast<FAWorld::Actor*>(FAWorld::NetObject::construct(classId)); actor->mId = actorId; } actor->readFrom(event.packet, position); } } } }
void levelClass::setLevel(std::list<eventClass*>& listEvent, std::list<characterClass*>& listEnemy, std::map<std::pair<int, int>, itemClass*>& mapLevel, int& endOfLevel, int& heightLevel, std::string& typeLevel, lightManagerClass& lightManager, int poseXPlayer) { readLevel("level/" + nameCurrentLevel, listEvent, listEnemy, mapLevel, endOfLevel, heightLevel, typeLevel, poseXPlayer, lightManager); }
const LevelData* LevelSet::levelData(int levelNum) const { LevelData* data = m_levelCache.value(levelNum, 0); return data ? data : readLevel(levelNum); }