Homework Assignment 7 (Servlet project 1)

Deadline: 13/6.

What to submit: For both of the following exercises you are expected to submit a WAR file that can be placed in the webapps folder of Tomcat and run automatically. Inside the file you should also include your source code.

1. Live Paint.

For this exercise you are allowed (and expected) to re-use your code for Paint. Alternatively, you can use the code posted on the class web page.

The objective of this exercise is to create a cooperative drawing application. You will program a web site on which more than one users may connect simultaneously. All connected users will see an interface similar to that of the drawing program of previous homeworks. The difference is that the picture being edited will be shared, that is, any change made by one user must become automatically visible to the others.

To achieve this you need to program both a server-side and a client-side application. The two will communicate asychronously to periodically update the shown picture for each user.

Requirements:

  1. You only need to implement the easy drawing tools: line, rectangle and cycle. No freehand pencil or select tool are required for this exercise.
  2. Updates should be visible to other users even before a user finalizes an addition (i.e. before releasing the mouse button to fix the size of a rectangle/line/cycle).
  3. As before, users should be able to pick colors and line thickness.
  4. Implement an all-clear button. When a user clicks on it the image is cleared for everyone.
  5. Implement undo/redo buttons. Here, when a user clicks on undo/redo, only the actions that this user has performed should be affected.

Advice: you already have a version of the drawing program that can "understand" a drawing's description in an XML format. It will therefore be easier to program the server side to periodically send the description of the current image to the client using this XML format.

2. Live Pong

For this exercise you need to develop a web version of the Pong game you have already written in javascript. You must now build a server-side app to which users can connect and play online. Each connected user can decide which of the two paddles to control. Play is to be done using the left and right arrow keys.

Advice: you have already programmed a version of Pong. Probably, you are storing the game state (positions of paddles, ball speed and position, etc.) in some large global object. The state of this object must now be moved to the server side. The client will then communicate with the server periodically to receive updates on the current state.

Advice2: You will probably need to program the server side to periodically advance the game state. In javascript we achieve this with the setInterval function. In Java, the standard way to do this is to use the Timer class.