In this assignment you are going to construct a networked two-player pong game based on the game physics code I showed in lecture. In the two player game the two players will each control a paddle and will be able to move that paddle vertically but not horizontally. The object of the game is to keep the ball from striking the wall behind your paddle - each time it does that your opponent scores a point.
In this application most of the important work is going to be done by the server application. It will keep track of the game state, such as the location of the ball and the locations of the player paddles, and also run a thread that updates the ball's location several times each second. The server will also watch for collisions between the ball and the paddles or walls: when the ball strikes a wall behind a player the server will give their opponent a point.
The client applications will watch for player inputs and display the current state of the game. When a player presses an arrow key on the keyboard to move up or down the client will send a request to the server asking it to move that player's paddle. The client application will also be running an update thread that checks in with the server several times every second to get the current game state and update the locations of the game objects on the screen.
Once you have written your server and client applications you will want to test the application. The ideal way to test the game is to set up an arrangement where the server and one of the clients runs one laptop and the other client runs on a different laptop. The client running on the other laptop will need to modify its code slightly, since it will be connecting to a server running on a different machine.
The code we have been using to establish a socket from the client to the server looks like
Socket socket = new Socket("localhost", 8000);
For the second client you will have to update this to look like
Socket socket = new Socket("143.44.42.34", 8000);
Where "143.44.42.34" gets replace with the IP address of the laptop that the server is running on. If you don't know how to determine the IP address of that machine, please ask me for assistance.
If you are running a firewall on the server's laptop you will also need to tell the firewall to allow connections on port 8000. If you need assistance in doing this, please see me.
Once again, this is a partner project.