// the starting point of the program
task main()
{
  // prompt the user for a delay at the start of autonomous
	selectTime();
  // prompt whether the robot should wait for FCS to start
  // They can disable it when testing the program at practice.
	startSelect();
  // wait for FCS to start if the user has chosen to
	if(waitSelected)
	{
		waitForStart();
	}
  // perform the aforementioned delay
	wait1Msec(1000*waitTime);
  //holds which beacon the robot is at
	int beacon = 0;
	//holds the IR sensor value
	int i = 0;

	//loops until the sensor finds the beacon or until it gets to the final beacon.
	while(i != 5 && beacon < 4)
	{
		i=0;
		//this section prevents the reading of random IR values and makes sure the value is constant.
		//when the value is the constant we want, the beacon is in front of the sensor.
		for(int a = 0; a <100; a++)
		{
			if(a == 0)
			{
				//gets original ir value
				i  = SensorValue[IR];
			}
			else
			{
				int b = SensorValue[IR];
				if(b != i)
				{
					//if a different value is sensed, then the original value was not constant; thus, we restart the checking
					//to try and gete a constant value.
					i = 0;
					a = 0;
				}
			}
		}
		if(i != 5)
		{
			if(beacon == 0)
			{
				//the distance to get to the first beacon
				ModForward(2200,35);
				motor[Right] = 0;
				motor[Left] = 0;
				wait1Msec(1000);
			}
			else if(beacon == 1)
			{
				//the distance to get to the second beacon
				ModForward(900,35);
				motor[Right] = 0;
				motor[Left] = 0;
				wait1Msec(1000);
			}
			else if(beacon == 2)
			{
				//the distance to get to the third beacon
				ModForward(1600,35);
				motor[Right] = 0;
				motor[Left] = 0;
				wait1Msec(1000);
			}
			else if(beacon == 3)
			{
				//the distance to get to the fourth beacon
				ModForward(1000,35);
				motor[Right] = 0;
				motor[Left] = 0;
				wait1Msec(1000);
			}
			beacon++;
		}
	}

	//code that runs after  we stop in front of a beacon.
	servo[AutoHook] = 255;	//dispenses the cube
	wait1Msec(900);
	servo[AutoHook] = 0;
	wait1Msec(1000);

	//pick where to  go based on beacon #.
	//if the robot is at rings 1 or 4, it turns, goes back, then turns to face the ramp.
	//if the robots is at rings 2 or 3, it goes backwards, turns, goes backwards again, and then turns to face the ramp.
	if(beacon == 1) //beacon was on first box
	{
		//goes forward from the box
		ModForward(5200,50);
		motor[Right] = 0;
		motor[Left] = 0;
		wait1Msec(500);

		//turns to be parallel to the ramp
		ModTurn(2040, 100, right);
		motor[Right] = 0;
		motor[Left] = 0;
		wait1Msec(500);

		//goes backwards and towards the ramp
		ModBackward(4000,50);
		motor[Right] = 0;
		motor[Left] = 0;
		wait1Msec(500);

		//turns towards the ramp
		ModTurn(2100,100,left);
		motor[Right] = 0;
		motor[Left] = 0;
		wait1Msec(500);

		//goes onto the ramp
		ModBackward(4500,80);
	}
	else if (beacon == 2) //beacon was on second box
	{
		//goes forward from the box
		ModForward(4300,50);
		motor[Right] = 0;
		motor[Left] = 0;
		wait1Msec(500);

		//turns to be parallel to the ramp
		ModTurn(2040, 100, right);
		motor[Right] = 0;
		motor[Left] = 0;
		wait1Msec(500);

		//goes backwards and towards the ramp
		ModBackward(4000,50);
		motor[Right] = 0;
		motor[Left] = 0;
		wait1Msec(500);

		//turns towards the ramp
		ModTurn(2100,100,left);
		motor[Right] = 0;
		motor[Left] = 0;
		wait1Msec(500);

		//goes onto the ramp
		ModBackward(4500,80);
	}
	else if (beacon == 3) //beacon was on third box
	{
		//goes forward from the box
		ModForward(2700,50);
		motor[Right] = 0;
		motor[Left] = 0;
		wait1Msec(500);

		//turns to be parallel to the ramp
		ModTurn(2040, 100, right);
		motor[Right] = 0;
		motor[Left] = 0;
		wait1Msec(500);

		//goes backwards and towards the ramp
		ModBackward(4000,50);
		motor[Right] = 0;
		motor[Left] = 0;
		wait1Msec(500);

		//turns towards the ramp
		ModTurn(2100,100,left);
		motor[Right] = 0;
		motor[Left] = 0;
		wait1Msec(500);

		//goes onto the ramp
		ModBackward(4500,80);
	}
	else if (beacon == 4) //beacon was on fourth ring
	{
		//goes forward from the box
		ModForward(1560,50);
		motor[Right] = 0;
		motor[Left] = 0;
		wait1Msec(500);

		//turns to be parallel to the ramp
		ModTurn(1940, 100, right);
		motor[Right] = 0;
		motor[Left] = 0;
		wait1Msec(500);

		//goes backwards and towards the ramp
		ModBackward(4000,50);
		motor[Right] = 0;
		motor[Left] = 0;
		wait1Msec(500);

		//turns towards the ramp
		ModTurn(2100,100,left);
		motor[Right] = 0;
		motor[Left] = 0;
		wait1Msec(500);

		//goes onto the ramp
		ModBackward(4500,100);
	}
}
Exemple #2
0
task main()
{
	 selectTime();
	 startSelect();
	 while(true)
	 {
	   counter();
	  if(programCounter == 1)
		{
	    nxtDisplayCenteredTextLine(2, "Regular Autonomous");
	    if(nNxtButtonPressed == 3)
	    {
	        PlaySound(soundBlip);
	        if(waitSelected){waitForStart();}
	        wait1Msec(waitTime*1000);

	        Auto_Encoder();

	        wait1Msec(500);
	    }
	  }
	  else if(programCounter == 2)
	  {
	    nxtDisplayCenteredTextLine(2, "FA to FR");
	    if(nNxtButtonPressed == 3)
	    {
	        PlaySound(soundBlip);
	        if(waitSelected){waitForStart();}
	        wait1Msec(waitTime*1000);

	        Auto_Front_Ramp();

	        wait1Msec(500);
	    }
	  }
	  else if(programCounter == 3)
	  {
	    nxtDisplayCenteredTextLine(2, "FA to BR");
	    if(nNxtButtonPressed == 3)
	    {
	        PlaySound(soundBlip);
	        if(waitSelected){waitForStart();}
	        wait1Msec(waitTime*1000);

	        Auto_Back_Ramp();

	        wait1Msec(500);
	    }
	  }
	  else if(programCounter == 4)
	  {
	    nxtDisplayCenteredTextLine(2, "Hardcoded Autonomous()");
	    if(nNxtButtonPressed == 3)
	    {
	        PlaySound(soundBlip);
	        Hardcoded_Autonomous();

	        if(waitSelected){waitForStart();}
	        wait1Msec(waitTime*1000);



	        wait1Msec(500);
	    }
	  }
	  else if(programCounter  == 5)
	  {
	  	nxtDisplayCenteredTextLine(2, "Hardcoded Reverse");
	  	if(nNxtButtonPressed == 3)
	  	{
	  		PlaySound(soundBlip);
	  		if(waitSelected){waitForStart();}
	  		wait1Msec(waitTime * 1000);

	  		Hardcoded_Reverse();

	  		wait1Msec(500);
	  	}
	  }
	  //else if(programCounter == 5)
	  //{
	  //  nxtDisplayCenteredTextLine(2, "Reverse Autonomous");
	  //  if(nNxtButtonPressed == 3)
	  //  {
	  //      PlaySound(soundBlip);
	  //      if(waitSelected){waitForStart();}
	  //      wait1Msec(waitTime*1000);

	  //      Reverse_Autonomous();

	  //      wait1Msec(500);
	  //  }
	  //}
	  //else if(programCounter == 6)
	  //{
	  //  nxtDisplayCenteredTextLine(2, "RA to FR");
	  //  if(nNxtButtonPressed == 3)
	  //  {
	  //      PlaySound(soundBlip);
	  //      if(waitSelected){waitForStart();}
	  //      wait1Msec(waitTime*1000);

	  //      Reverse_Auto_Front_Ramp();

	  //      wait1Msec(500);
	  //  }
	  //}
	  //else if(programCounter == 7)
	  //{
	  //	nxtDisplayCenteredTextLine(2, "RA to BR");
	  //	if(nNxtButtonPressed == 3)
	  //	{
	  //  		PlaySound(soundBlip);
	  //  		if(waitSelected) {waitForStart();}
	  //  		wait1Msec(waitTime * 1000);

	  //  		Reverse_Auto_Back_Ramp();

	  //  		wait1Msec(500);
	  //	}
	  //}
	}
}
Exemple #3
0
int main()
{
	srand(time(0));
	ResourceHolder<sf::Font, Fonts::ID> fonts;
	ResourceHolder<sf::Texture, Textures::ID> textures;
	//ResourceHolder<sf::SoundBuffer, Sounds::ID> sounds;
	try
	{
		fonts.load(Fonts::WhiteRabbit, "Assets/whiterabbit.ttf");
		textures.load(Textures::Buttons, "Assets/buttons.png");
		textures.load(Textures::Timtam, "Assets/cmcquiz.png");
	}
	catch(std::runtime_error &e)
	{
		//would be better off using a log file for release code.
		return 1;
	}

	Window mainWindow(sf::Vector2f(800, 600), "Soft Eng Game");

	
	Button mainPlayButton(textures.get(Textures::Buttons), sf::Vector2f(250,  75), sf::Vector2f(25, 500),
		sf::IntRect(0, 0, 250, 75), sf::IntRect(0, 75, 250,  75));
	Button mainQuitButton(textures.get(Textures::Buttons), sf::Vector2f(250,  75), sf::Vector2f(525, 500),
		sf::IntRect(0, 150, 250, 75), sf::IntRect(0, 225, 250,  75));

	//QuizSelect stuff
	Button quizMenuContinue(textures.get(Textures::Buttons), sf::Vector2f(250, 75), sf::Vector2f(250, 500),
		sf::IntRect(0, 300, 250, 75), sf::IntRect(0, 375, 250, 75));

	sf::Text selectQuiz("Select Quiz", fonts.get(Fonts::WhiteRabbit), 24);
	selectQuiz.setPosition(150, 150);
	sf::Text selectTime("Select Time", fonts.get(Fonts::WhiteRabbit), 24);
	selectTime.setPosition(500, 150);

	std::vector<QuestionButton> quizButtons;
	std::vector<std::string> quizFilenames;
	Util::getFilenamesInDir(quizFilenames, "Quizes");
	for(int i = 0; i < quizFilenames.size(); i++)
	{
		quizButtons.push_back(QuestionButton(quizFilenames[i], fonts.get(Fonts::WhiteRabbit), 24, sf::Vector2f(200, 100), sf::Vector2f(100, 200 +( i * 100)), sf::Color(116, 40, 148, 255), sf::Color(181, 103, 214, 255)));
	}

	std::vector<QuestionButton> timerButtons;
	timerButtons.push_back(QuestionButton("15", fonts.get(Fonts::WhiteRabbit), 48, sf::Vector2f(200, 100), sf::Vector2f(500, 200), sf::Color(116, 40, 148, 255), sf::Color(181, 103, 214, 255)));
	timerButtons.push_back(QuestionButton("25", fonts.get(Fonts::WhiteRabbit), 48, sf::Vector2f(200, 100), sf::Vector2f(500, 300), sf::Color(116, 40, 148, 255), sf::Color(181, 103, 214, 255)));
	timerButtons.push_back(QuestionButton("35", fonts.get(Fonts::WhiteRabbit), 48, sf::Vector2f(200, 100), sf::Vector2f(500, 400), sf::Color(116, 40, 148, 255), sf::Color(181, 103, 214, 255)));

	//EndMenu Stuff
	Button endRetry(textures.get(Textures::Buttons), sf::Vector2f(250, 75), sf::Vector2f(25, 500),
		sf::IntRect(0, 450, 250, 75), sf::IntRect(0, 525, 250, 75)); 
	Button endQuit(textures.get(Textures::Buttons), sf::Vector2f(250,  75), sf::Vector2f(525, 500),
		sf::IntRect(0, 150, 250, 75), sf::IntRect(0, 225, 250,  75));

	sf::Vector2f endLogoPos(100, 0);

	std::vector<QuestionButton> endAnswers;
	endAnswers.push_back(QuestionButton("", fonts.get(Fonts::WhiteRabbit), 24, sf::Vector2f(640, 120), sf::Vector2f(80, 120), sf::Color(116, 40, 148, 255), sf::Color(116, 40, 148, 255)));
	endAnswers.push_back(QuestionButton("", fonts.get(Fonts::WhiteRabbit), 24, sf::Vector2f(640, 120), sf::Vector2f(80, 250), sf::Color::Green, sf::Color::Green));
	endAnswers.push_back(QuestionButton("", fonts.get(Fonts::WhiteRabbit), 24, sf::Vector2f(640, 120), sf::Vector2f(80, 380), sf::Color::Red, sf::Color::Red));

	
	


	//MAIN MENU
	Menu startMenu(mainWindow.getWindow(), mainPlayButton, mainQuitButton, 10, 20, 15, 45, textures.get(Textures::Timtam),
		sf::Vector2f(75, 200));
		

	bool play = startMenu.run();
	
	
	while(play)
	{
		play = false;
		//quiz reader, gets a list of quizes from a dir and displays them.
		//pick one and return with that number.

		//pick a filename / quiz file.
		std::string quizFile;

		//QUIZ CHOICE AND TIMER MENU
		QuizMenu quizMenu(mainWindow.getWindow(), quizMenuContinue, selectQuiz, selectTime, quizButtons, timerButtons, 
			textures.get(Textures::Timtam), sf::Vector2f(100, 0));

		int timeToAns = 0;
		timeToAns = quizMenu.run(quizFile);
		//use the quiz at that index.

		if(timeToAns == 15 || timeToAns == 25 || timeToAns == 35)
		{
			//get the list of Q's
			Quiz quiz = Util::getQuiz("Quizes/" + quizFile, timeToAns);

			std::vector<QuestionButton> questionButtons;
			questionButtons.push_back(QuestionButton("", fonts.get(Fonts::WhiteRabbit), 18, sf::Vector2f(640, 120), sf::Vector2f(80, 210), sf::Color(116, 40, 148, 255), sf::Color(116, 40, 148, 255)));
			questionButtons.push_back(QuestionButton("", fonts.get(Fonts::WhiteRabbit), 18, sf::Vector2f(300, 120), sf::Vector2f(80, 340), sf::Color(116, 40, 148, 255), sf::Color(181, 103, 214, 255)));
			questionButtons.push_back(QuestionButton("", fonts.get(Fonts::WhiteRabbit), 18, sf::Vector2f(300, 120), sf::Vector2f(80, 470), sf::Color(116, 40, 148, 255), sf::Color(181, 103, 214, 255)));
			questionButtons.push_back(QuestionButton("", fonts.get(Fonts::WhiteRabbit), 18, sf::Vector2f(300, 120), sf::Vector2f(420, 340), sf::Color(116, 40, 148, 255), sf::Color(181, 103, 214, 255)));
			questionButtons.push_back(QuestionButton("", fonts.get(Fonts::WhiteRabbit), 18, sf::Vector2f(300, 120), sf::Vector2f(420, 470), sf::Color(116, 40, 148, 255), sf::Color(181, 103, 214, 255)));

			std::vector<AnswerCombo> answers;


		
			Game game(&mainWindow.getWindow(), quiz, questionButtons, 
				sf::Sprite(textures.get(Textures::Timtam), 
				sf::IntRect(0, 0, textures.get(Textures::Timtam).getSize().x, textures.get(Textures::Timtam).getSize().y)),
				fonts.get(Fonts::WhiteRabbit),
				32,
				sf::Color::Black);
			answers = game.run();

			if(answers.size() > 0)
			{
				//takes in answers.
				EndMenu endMenu(&mainWindow.getWindow(), endRetry, endQuit, textures.get(Textures::Timtam), endLogoPos,
					answers, endAnswers);
				play = endMenu.run();
			}
		}
	}
	

	return 0;
}