Exemple #1
0
void DisplayBothUnits::slot_unitRight( int num )
{
	manageClick( 1, num );
}
//Begins the bulk loop for the program
void MainInterface::run() {
	//establish timing setup for speedometer
	int reps = 0;
	clock_t lastClock = clock();
	std::queue<double long> timeBuffer = std::queue<double long>();
	for (int i = 0; i < 60; i++) timeBuffer.push(0);

	while (window->isOpen()) {//main loop runs while the window isn't closed
		sf::Event event;
		while (window->pollEvent(event)) {//check for events
			if (event.type == sf::Event::Closed) window->close(); //exit if the window get's "x'd out"
			if (event.type == sf::Event::MouseButtonPressed) manageClick(event.mouseButton.x, event.mouseButton.y);//user mouse input sent to internal function
		}

		if (status == RUNNING) {//if the solver is active, automatically step
			if(solver->step()) {
				FileManager::saveSolution(solver, reps);
				//FEATURE: puase solver if the option is implemented and checked
			}
			reps++;

			//update solver clock;
			double long temp = timeBuffer.front();
			timeBuffer.pop();
			lastClock = clock();
			timeBuffer.push(lastClock);
			speedometer.setString("Steps per second: " + std::to_string(60000/(lastClock - temp))); //calculates average time over 60 steps

		}
		else speedometer.setString("");//don't display the speedometer if the solver isn't running.

		
		//prepare for display sequence
		window->clear(sf::Color(63,63,63,255));
		//draw board
		if (solver != 0) {
			for (int i = 0; i < solver->getBoard()->getDepth(); i++) window->draw(*(boardSpace+i));//draw the base of the board

			int w = solver->getBoard()->getDepth() -1;
			for (w; w >= 0; w--){//for each level...
				int v = solver->getBoard()->getHeight() - 1;
				for (v; v >= 0; v--) {//for each row...
					int u = solver->getBoard()->getWidth() - 1;
					for (u; u >= 0; u--) {//for each column...
						//make a square that matches the color on the board at that position
						sf::RectangleShape temp = sf::RectangleShape(sf::Vector2f(zoomSize,zoomSize));
						temp.setFillColor(solver->colorAt(u,v,w));
						temp.setOutlineColor(sf::Color::Black);
						temp.setOutlineThickness(1);

						//move that square to the proper position on the screen
						temp.setPosition((400-(solver->getBoard()->getWidth()+1)*solver->getBoard()->getDepth()*zoomSize/2+(solver->getBoard()->getWidth()+1)*w*zoomSize + zoomSize/2)+u*zoomSize,
										200-(solver->getBoard()->getHeight())*zoomSize/2+v*zoomSize);
						
						//draw that square
						window->draw(temp);
					}
				}
			}
		}
		if (status != RUNNING) { //unless the solver is running, draw the "load" button
			window->draw(*loadButton);
			window->draw(loadText);
		}
		// FEATURE hidden //window->draw(*testBlockButton);
		if (status == PAUSED) { //if a puzzle is loaded but not being solved, display the "Step" button.
			window->draw(*stepButton);
			window->draw(stepText);
		}
		if (status != WAITING) { //if a puzzle is loaded at all, display the play/pause button
			window->draw(*playPauseButton);
			window->draw(playPauseText);
		}
		window->draw(speedometer);
		window->display();
		//std::cout<<reps<<std::endl;
	}
}
Exemple #3
0
void DisplayBothUnits::slot_unitLeft( int num )
{
	manageClick( 0, num );
}