static void buildMaze(int y, int x) { int numOffsets, offset, offsets[4]; while (1) { numOffsets = 0; maze[y][x].visited = true; if (y > 0 && !maze[y - 1][x].visited) offsets[numOffsets ++] = -width; if (y < height - 1 && !maze[y + 1][x].visited) offsets[numOffsets ++] = width; if (x > 0 && !maze[y][x - 1].visited) offsets[numOffsets ++] = -1; if (x < width - 1 && !maze[y][x + 1].visited) offsets[numOffsets ++] = 1; if (numOffsets > 0) { offset = offsets[rand() % numOffsets]; addFirst(dp, offset(x, y)); if (offset == -width) { maze[y - 1][x].bottom = false; buildMaze(y - 1, x); } else if (offset == width) { maze[y][x].bottom = false; buildMaze(y + 1, x); } else if (offset == -1) { maze[y][x - 1].right = false; buildMaze(y, x - 1); } else if (offset == 1) { maze[y][x].right = false; buildMaze(y, x + 1); } else abort(); } else if (numItems(dp) > 0) { offset = removeFirst(dp); x = xcoord(offset); y = ycoord(offset); } else break; } maze[height - 1][width - 1].right = false; }
int main() { int x, y; WINDOW *win; win = initscr(); curs_set(0); getmaxyx(win, y, x); width = x / 2 - 1; height = y / 2 - 1; createMaze(); do { clear(); refresh(); initMaze(); buildMaze(0, 0); printMaze(); solveMaze(); move(height * 2 + 1, 0); printw("Press 'q' to quit or any other key to run again."); refresh(); } while (getchar() != 'q'); clear(); refresh(); endwin(); return EXIT_SUCCESS; }
void newMatch(void) { buildMaze(glmaze, Graph_Space, tileSpace, Tilesize, Resources_Manager.texture("wall.tga"), Resources_Manager.texture("floor.tga"), Resources_Manager.texture("ceil.tga"), &Config_Info); restartMatch(); }
Maze::Maze(int width, int height, int trapChance, bool failSafe) { if (failSafe && (width*height) > 8649) throw std::exception("[ERR]Stack overflow possible at this size.\nKeep total nodes below 8649"); this->width = width; this->height = height; this->root = new MazeNode(); //default maze node this->trapChance = trapChance; buildMaze(); }
void ballSetStart() { if(sphereMesh.whichHole.last) { cout << "YOU WON!!!!!" << endl; NUMBER_OF_WINS ++; buildMaze( abs(boardMesh.initial_bound.second.z - boardMesh.initial_bound.first.z) - 1, abs(boardMesh.initial_bound.second.x - boardMesh.initial_bound.first.x) - 1); } else { cout << "AWWWWW!! TOO BAD!!!!!!" << endl; } cout << "NUMBER OF WINS: " << NUMBER_OF_WINS << endl; MOUSE_X = 0; MOUSE_Y = 0; DELTA_X_CHANGE = 0.0; DELTA_Y_CHANGE = 0.0; //for mouse movement stuff X_CHANGE = 0.05; Y_CHANGE = 0.05; boardMesh.initialize("board"); boardMesh.initial_bound = meshManager.getBounds("board"); boardMesh.current_position = boardMesh.initial_bound; sphereMesh.initialize("sphere"); sphereMesh.initial_bound = meshManager.getBounds("sphere"); sphereMesh.current_position = sphereMesh.initial_bound; //set the location of the ball on top of the start hole sphereMesh.offset.x = mazeHoles[0].offset.x; sphereMesh.offset.z = mazeHoles[0].offset.z; sphereMesh.offset.y = 3.0f; //translate to the start position and update the current positions sphereMesh.model=glm::translate(glm::mat4(1.0f), glm::vec3( sphereMesh.offset.x, sphereMesh.offset.y, sphereMesh.offset.z)); sphereMesh.current_position.first = sphereMesh.initial_bound.first + sphereMesh.offset; sphereMesh.current_position.second = sphereMesh.initial_bound.second + sphereMesh.offset; //set up the board and ball in the simulated physics world if(initPhysics == true) { myPhysics.makeBoard(boardMesh); myPhysics.makeBall(sphereMesh); myPhysics.makeWalls(myMaze); initPhysics = false; } else { myPhysics.resetMaze(sphereMesh, myMaze); } }
void CMazeGameEngine::setupWorld() { isWinScreenShowing = false; _endGameImg->setVisible(false); _sceneManager->clear(); _videoDriver->setFog(irr::video::SColor(0, 30, 20, 10), irr::video::EFT_FOG_LINEAR, 3, 10, .03f, true, false); buildMaze(); addFinishPoint(); loadAdditionalResources(); setupCamera(); setupPlayerViews(); hideMenu(); startOrientationScene(); }
int main(int argc, char** argv) { std::string input; std::stringstream ss; while (std::getline(std::cin, input)) { if (!input.empty()) ss << input << "!"; else ss << "!"; } std::vector<std::string> tokens = split(ss.str(), '!'); std::printf("%s", buildMaze(tokens).c_str()); return 0; }
void difficultyLevel(int id) { switch(id) { case 1: //beastly level = 2;//set level break; case 2: //not so beastly level = 1; break; case 3: //easy peasy level = 0; break; } NUMBER_OF_WINS = 0; //reset the number of wins buildMaze( abs(boardMesh.initial_bound.second.z - boardMesh.initial_bound.first.z) - 1, abs(boardMesh.initial_bound.second.x - boardMesh.initial_bound.first.x) - 1); ballSetStart(); }
void startMenu(int id) { switch(id) { case 1: //pause paused = true; break; case 2: //restart ballSetStart(); break; case 3://resume paused = false; break; case 4://new maze buildMaze( abs(boardMesh.initial_bound.second.z - boardMesh.initial_bound.first.z) - 1, abs(boardMesh.initial_bound.second.x - boardMesh.initial_bound.first.x) - 1); ballSetStart(); break; } }
int main() { int m, n; in = fopen("input.txt","r"); out = fopen("output.txt","w"); if (in == NULL || out == NULL) { printf("Error opening files\n"); return 0; } fscanf(in,"%d %d", &m, &n); int **maze = initMaze(m, n), a, b, c, d; int row = (m*ROW) - ( m - 1), col = (n*COL) - (n - 1), maxsec; buildMaze(in, maze,row, col); printMaze(out, maze, row, col); evalMaze(out, maze, row, col); fscanf(in, "%d %d %d %d", &a, &b, &c, &d); a *= 2; b *= 2; c *= 2; d *= 2; if(findPath(maze,a,b,c,d,row, col)){ printMaze(out, maze, row, col); }else{ fprintf(out, "No Path Found!\n"); } fclose(in); fclose(out); return 0; }
/* Este metodo e' chamado quando o a aplicacao arranca, ou quando o jogador carrega em "Novo" para re-gerar novo labirinto. */ void MainWindow::requestNewMaze() { int w, h; // Abrir a caixa de dialogo com os valores iniciais identicos aos do // labirinto agora aberto if( map == NULL ) { w = 25; h = 15; } else { w = (map->getWidth() - 1) / 2; h = (map->getHeight() - 1) / 2; } DialogNew d( this, w, h ); if( d.exec() == DialogNew::Accepted ) { resetStateNew(); buildMaze( d.getCorridorWidth()*2 + 1, d.getCorridorHeight()*2 + 1, d.getComplexity() ); } }
//--Main int main(int argc, char **argv) { //Initialize GLUT glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH); glutInitWindowSize(w, h); Lighting.Init();////////////// ADD // Name and create the Window glutCreateWindow("LABYRINTH PROGRAM"); //temp Mesh model Mesh tempMesh; //add the number of holes values numOfHoles.push_back(1); numOfHoles.push_back(3); numOfHoles.push_back(6); level = 0; //initialize textures char metal_file[] = "../textures/metal.png"; char white_marble_file[] = "../textures/MarbleWhite.png"; char black_marble_file[] = "../textures/gold.png"; char red_solid_file[] = "../textures/red.png"; char green_solid_file[] = "../textures/green.png"; char black_solid_file[] = "../textures/black.png"; char brown_solid_file[] = "../textures/brown.png"; //load textures Magick::InitializeMagick(*argv); loadTexture(metal_file, metal); loadTexture(black_marble_file, black_marble); loadTexture(white_marble_file, white_marble); loadTexture(red_solid_file, red_solid); loadTexture(black_solid_file, black_solid); loadTexture(green_solid_file, green_solid); loadTexture(brown_solid_file, brown_solid); GLenum status = glewInit(); //check glut status if( status != GLEW_OK) { std::cerr << "[F] GLEW NOT INITIALIZED: "; std::cerr << glewGetErrorString(status) << std::endl; return -1; } //Set all of the callbacks to GLUT that we need glutDisplayFunc(render); // Called when its time to display glutReshapeFunc(reshape); // Called if the window is resized glutIdleFunc(update); // Called if there is nothing else to do glutKeyboardFunc(keyboard); // Called if there is keyboard input glutMouseFunc(mouse); glutMotionFunc(mouseOnTheMove); //Initialize all of our resources shaderManager = new ShaderManager(); bool init = initialize(); //initialize shaders and load models //build mesh objects tempMesh.initialize("board"); tempMesh.initial_bound = meshManager.getBounds("board"); tempMesh.current_position = tempMesh.initial_bound; boardMesh = tempMesh; tempMesh.initialize("sphere"); tempMesh.initial_bound = meshManager.getBounds("sphere"); tempMesh.current_position = tempMesh.initial_bound; sphereMesh = tempMesh; //initialize maze buildMaze( abs(boardMesh.initial_bound.second.z - boardMesh.initial_bound.first.z) - 1, abs(boardMesh.initial_bound.second.x - boardMesh.initial_bound.first.x) - 1); //translate the ball to the start position ballSetStart(); //initialize menus createMenus(); if(init) { t1 = std::chrono::high_resolution_clock::now(); glutMainLoop(); } return 0; }