private void TimerTick(object sender, ElapsedEventArgs e) { if (GameStage == "Countdown") //countdown to ball launch { counter++; if (counter == 50) //triggers every half second { countdown--; counter = 0; } if (countdown == -1) { ball.Launch(BoxWidth); GameStage = "Started"; } } if (GameStage == "Started") //round in play { leftPaddle.UpdatePosition(); rightPaddle.UpdatePosition(); ball.UpdatePosition(); if (ball.Xlocation <= 0 - ball.size) //right scores { rightScore++; ToCountdown(); } else if (ball.Xlocation <= 10 + leftPaddle.width && ball.Xlocation >= 10 && ball.Ylocation >= leftPaddle.Ylocation && ball.Ylocation <= leftPaddle.Ylocation + leftPaddle.height) { ball.Hit(leftPaddle); } if (ball.Xlocation >= BoxWidth) //left scores { leftScore++; ToCountdown(); } if (ball.Xlocation >= BoxWidth - 10 - rightPaddle.width - ball.size && ball.Xlocation <= BoxWidth - 10 - ball.size && ball.Ylocation >= rightPaddle.Ylocation && ball.Ylocation <= rightPaddle.Ylocation + rightPaddle.height) { ball.Hit(rightPaddle); } if (rightScore == WinScore) { clock.Enabled = false; Gameover("RIGHT"); } else if (leftScore == WinScore) { clock.Enabled = false; Gameover("LEFT"); } } PongBox.Invalidate(); }
public Pong() { InitializeComponent(); leftPaddle = new Paddle(true); rightPaddle = new Paddle(false); ball = new Ball(); leftScore = 0; rightScore = 0; GameStage = "Intro"; //start up screen PongBox.Invalidate(); }
public void Gameover(string winner) { winMessage = "THE WINNER IS " + winner; GameStage = "Over"; PongBox.Invalidate(); }