#pragma config(StandardModel, "EV3_REMBOT")
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

//Left Button =1; Right Button =3; Up Button =4; Down Button =5
//Maximum of 100 steps
int drive[100];

void recordSteps(int numberOfSteps)
{
	for(int i = 0; i < numberOfSteps; i++) //i = i + 1
	{
		while(getButtonPress(buttonAny) == 0)
		{
			//Wait for Any Button to be pressed
			sleep(10);
		}

		if(getButtonPress(buttonLeft) == 1)						drive[i] = 1;
		else if(getButtonPress(buttonRight) == 1)			drive[i] = 3;
		else if(getButtonPress(buttonUp) == 1)				drive[i] = 4;
		else if(getButtonPress(buttonDown) == 1)			drive[i] = 5;

		playSoundFile("Click");
		while(bSoundActive) sleep(10);

		while(getButtonPress(buttonAny) == 1)
		{
			//Wait for All Buttons to be released.
			sleep(10);
		}
	}
}

void playSteps(int numberOfSteps)
{
	for(int i = 0; i < numberOfSteps; i++)
	{
		if(drive[i] == 0)
		{
			//No Step Found, End Code.
			return;
		}

		else if(drive[i] == 1)
		{
			//Turn Left Code
			moveMotorTarget(motorC, 360, 50);
			waitUntilMotorStop(motorC);

		}
		else if(drive[i] == 3)
		{
			//Turn Right Code
			moveMotorTarget(motorB, 360, 50);
			waitUntilMotorStop(motorB);
		}
		else if(drive[i] == 4)
		{
			//Forward Code
			moveMotorTarget(motorB, 360, 50);
			moveMotorTarget(motorC, 360, 50);
			waitUntilMotorStop(motorB);
			waitUntilMotorStop(motorC);
		}
		else if(drive[i] == 5)
		{
			//Backward Code
			moveMotorTarget(motorB, -360, -50);
			moveMotorTarget(motorC, -360, -50);
			waitUntilMotorStop(motorB);
			waitUntilMotorStop(motorC);
		}
	}
}

task main()
{
	recordSteps(8);

	sleep(2000);
	playSoundFile("Go");
	while(bSoundActive) sleep(10);

	playSteps(8);

	playSoundFile("Game over");
	while(bSoundActive) sleep(10);
}
