case 7:
digitalWrite(display1,LOW);
digitalWrite(display2,LOW);
digitalWrite(display3,LOW);
digitalWrite(display4,HIGH);
digitalWrite(display5,HIGH);
digitalWrite(display6,HIGH);
digitalWrite(display7,HIGH);
break;
case 8:
digitalWrite(display1,LOW);
digitalWrite(display2,LOW);
digitalWrite(display3,LOW);
digitalWrite(display4,LOW);
digitalWrite(display5,LOW);
digitalWrite(display6,LOW);
digitalWrite(display7,LOW);
break;
case 9:
digitalWrite(display1,LOW);
digitalWrite(display2,LOW);
digitalWrite(display3,LOW);
digitalWrite(display4,LOW);
digitalWrite(display5,HIGH);
digitalWrite(display6,LOW);
digitalWrite(display7,LOW);
break;
}
/////////////////////////////////////////////////////////////////////////////////////
CheckEndGame();
DetermineNextPosition();
MoveBallToNextPosition();
previousMillis = currentMillis;
}
}
void ListenForInput()
{
buttonStatePlayerOne = digitalRead(buttonPlayerOne);
buttonStatePlayerTwo = digitalRead(buttonPlayerTwo);
if (buttonStatePlayerOne != lastButtonStatePlayerOne && isInputAllowed)
{
if (buttonStatePlayerOne == 1)
{
if (currentPosition == playerOne)
{
ToggleBallDirection();
IncreaseSpeed();
}
else
{
ScoreForPlayer(2);
}
}
lastButtonStatePlayerOne = buttonStatePlayerOne;
}
if (buttonStatePlayerTwo != lastButtonStatePlayerTwo && isInputAllowed)
{
if (buttonStatePlayerTwo == 1)
{
if (currentPosition == playerTwo)
{
ToggleBallDirection();
IncreaseSpeed();
}
else
{
ScoreForPlayer(1);
}
}
lastButtonStatePlayerTwo = buttonStatePlayerTwo;
}
}
void ToggleBallDirection()
{
willTheBallGoTowardsPlayerTwo = !willTheBallGoTowardsPlayerTwo;
isInputAllowed = false; //Only one direction change per frame is allowed for consistent gameplay.
}
void IncreaseSpeed()
62