Hardware Reference
In-Depth Information
The showScore() method prints
the scores on the screen.
8
public void showScore() {
textSize(24);
text(topScore, 20, 40);
text(bottomScore, 20, height - 20);
}
Finally, moveBall() calls a the
resetBall() method, which resets the
ball at the end of each point.
8
void resetBall() {
// put the ball back in the center
ballPosV = height/2;
ballPosH = width/2;
ballInMotion = false;
delayCounter = millis();
}
The beauty of this server is that it doesn't
really care how many clients log into it;
everyone gets to play ping pong. There's
nothing in the server program that limits the response
time for any client, either. The server attempts to satisfy
everyone a soon as possible. This is a good habit to get
in. If there's as need to limit the response time in any
way, don't rely on the server of the network to do that.
Whenever possible, let the network and the server remain
dumb, fast, and reliable, and let the clients decide how fast
they want to send data across. Figure 5-19 shows a screen-
shot of the server with two clients.
Once you've got the clients speaking with the server,
try designing a new client of your own. Try to make the
ultimate ping pong paddle.
X
Figure 5-19
The output of the ping pong server sketch.
 
Search WWH ::




Custom Search