COSC 174 - Assignment #5
Grab - A Networked Game
Due date: Friday, April 3, 2009

This assignment involves the Grab applet and server discussed in class (and available on pascal in the directory /users/faculty/mikes/174/Grab ). I would suggest that you work in teams of two, with each team handing in one assignment with both names. This will make it much easier to test the networking features. However, if you wish to work alone, that is OK.

GOAL: Modify the Grab game to add some game features. In particular, you should add a "grab" command, issued by pressing "G" on the keyboard, which takes a coin which you are standing next to and facing (and does nothing if there is no such coin) and a "blast" command, issued by pressing "B" on the keyboard, which takes a block which you are standing next to and facing and removes the block from the board. Each player starts the game with 4 sticks of dynamite and uses one for each blast, so there should be a counter for each player making sure they don't blast more that 4 blocks. In each case these moves need to be sent to the server to check for legality and then reported back to both applets (so the displays stay synchronized). You should also display the scores (number of coins collected) for each player.

You should also add sound effects which are played by the applet whenever a coin is grabbed or a block is blasted. If you have the time, you could put in different sounds depending on whether you or your opponent grabbed a coin.

METHOD: The main thing you need to do here is understand how the demo game works and add in some new messages between the applets and the server. You'll need to be able to tell the server that a player is trying to grab or blast something and the server will need to be able to tell the players that a coin is gone, score has changed, or a block is gone. Of course, each of the server and applet will need to be changed to correctly react to the new messages.

You can find a variety of sound effects on pascal in the directory (not web address)

      /usr/demo/SOUND/sounds
Also there are some sound effects in the directory
      ~mikes/174/sounds

Things will get pretty messed up if everyone is using port 2001, so be sure and change the port number. Both the server and the applet need the same port number and any 4-digit number greater than 1024 is a good choice. The port number is mentioned in the HTML file, in Grab.java (default for applet), and in GameServer.java (default for server). It can be reset for the server with a command line argument.

If you're having trouble understanding the basic networking, remember that the pascal directory ~mikes/174/netdemo contains the stripped down client/server demo that we discussed in class.

Remember that to run the demos (either Grab or netdemo), you need to start the server (with the command "java GameServer&" - putting an ampersand "&" at the end of the line will put the server in the background and let you type new commands like appletviewer), then start two applets (in either a browser or appletviewer). Currently, the server will stop when the applets are closed, so you need to run the server every time.

EXTRA: Anything to improve the game. Things that occurred to me include checking for game over when all coins are picked up, announcing a winner, allowing more than two players.

HAND-IN: You should submit the Java code for your program (*.java), any other files which you need, and an HTML page which displays your applet (and explains any details of running the server and applet).