Chris Pollett > Old Classes > PIC20B ( Print View ) Enrollment info Course Info:
|
HW#5 --- last modified January 16 2019 00:35:19..Due date: June 6 ========= Files to be submitted: p20bhw5file1.zip ====================== HW5 Purpose: To gain familiarity with network sockets and UDP and TCP ============ transmission. Specification: ============== For this homework you will make client and server programs to play Pong over the internet. Note: to play the game on one computer you might have to keep clicking back and forth between two windows then hitting the direction key you want. In the PIC lab you can always log into two machines and play between them. Recall Pong is the 1972 video ping-pong game from Atari (although see http://www.emuunlim.com/doteaters/play1sta1.htm for a 1958-9 version of pong played on a modified oscillascope). You can see a screen shot of Pong here http://www.emuunlim.com/doteaters/play1sta2.htm . Like the Tic-tac-toe game in the book the server should have two player threads to handle the communication with each player. Initially, while waiting for two players the client uses stream sockets. It assigns the first player that connects to the paddle on the left hand side of the screen. This player uses the keys 1 and 2 for up and down. The second player to connect gets the right hand paddle and uses keys 9 and 0 to move. After both players have connected it sends a message to both players that a round (for this discussion, a round will mean a competition for a point) is to begin. The client programs should use a JTextfield and a JButton called Connect to get the URL of the server to connect to. They should also have a screen showing the current picture of the game. During a round the server uses a timer to send datagrams to each player every 100ms. This datagram consists of three pieces of information: (1) the x,y position of the ball on the screen (4 bytes), (2) the y position of the first player (2 bytes) and (3) the y position of the second player (2 bytes). Meanwhile each client uses a KeyListener to listen for the keys corresponding to its paddle. When one of these keys is pressed it sends over its stream socket with its corresponding server player thread one byte 0 for down 255 for up. The server's player thread then updates the position of the player according to the move it receives. When the ball goes out of bounds, the server sends using its stream sockets that the round is over, followed by the current score. If no person has scored 10 yet then after a 3 second delay a new round signal byte is sent by the server. Otherwise, a game over disconnect signal is sent and the connections are closed. If the clients each click on Connect they can start a new game. Point Breakdown for HW5 ======================= Documentation..........................1pt Client application has a JTextfield and button which work as described...1pt Client windows displays current paddles and and ball correctly.......1pt Server uses timer to send datagrams....1pt Server has two player threads which works as described..............1pt Client key presses send stream socket data as described above to Server.....1pt Server updates player position according to keypresses received......1pt Server correctly ends round when ball goes out of bounds....................1pt There is a three second minimum delay between rounds........................1pt Server correctly end games when someone gets 10 points........................1pt Total.................................10pts |