Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
C#
assets

# Pong

The classic Pong game -- the grandfather of all video games! Now over 45 years old!

Difficulty: Easy.

Objective: Retro gaming.

## How It Works

Surprisingly, this very simple game requires about as much code as the Space Invasion game.

In this game a single player plays against the BrainPad. The player uses the up and down buttons to move his paddle (on the right side of the screen) and tries to hit a moving ball across the net (the dashed line) to the other side of the court. You score points when the BrainPad misses the ball. The BrainPad scores when you miss the ball. The first player (you or the BrainPad) to get five points wins.

## An Exercise

Modify the code to so tilt (the accelerometer) is used instead of buttons. Hint: Use the Tilt Etch A Sketch for help.

## The Code in C#

```namespace ModifyThis {
class Program {
static void Main() {
double BallX = 10, BallY = 10, BallDX = 2.3, BallDY = 2.8;
int ScoreL = 0, ScoreR = 0;
int PlayerPos = 30;
int CompPos = 30;

while (true) {
// The Ball
BallX += BallDX;
BallY += BallDY;

if (BallX < 10) {
BallDX *= -1;

if (BallY >= CompPos - 1 && BallY <= CompPos + 12) {
// hit back
}
else {
//win
for (int i = 0; i < 3; i++) {
for (int f = 1000; f < 6000; f += 500) {
}
}
ScoreR++;
}
}

if (BallX > 115) {
BallDX *= -1;

if (BallY >= PlayerPos - 1 && BallY <= PlayerPos + 12) {
// hit back
}
else {
// Loss
for (int f = 2000; f > 200; f -= 200) {
}
ScoreL++;
}
}

if (BallY < 5 || BallY > 55) {
BallDY *= -1;
}

// The Field
for (var y = 0; y < 64; y += 10) {
// net
BrainPad.Display.DrawLine(64, y, 64, y + 5);
}

// Player
if (PlayerPos < 5) PlayerPos = 5;
if (PlayerPos > 50) PlayerPos = 50;

// Computer
if (BallY > CompPos + 10) CompPos += 2;
if (BallY < CompPos) CompPos -= 2;
if (CompPos < 5) CompPos = 5;
if (CompPos > 50) CompPos = 50;

// Score

if (ScoreL >= 5) {
BrainPad.Display.DrawScaledText(0, 40, "You Lose!", 3, 1);
}

if (ScoreR >= 5) {
BrainPad.Display.DrawScaledText(0, 40, "You Win!", 3, 1);