Computer Science Department, Bucknell University

Project #1 Race Car Track
CSCI 355 - Distributed Computing
By Professor Dan Hyde - Spring 2007

This project will be in several phases with each phase having it's own due date. This handout covers all three phases.

The ultimate goal of the project is to allow one person to drive his or her car on one Linux workstation and the other person drive his or her car on a second workstation while both individuals can view both cars on their screens.

Phase 1: Design Your Cars - Due Wednesday February 7, 2007

Using a tool such as GIMP, create a JPEG or GIF image, 50 pixels by 50 pixels, of a race car viewed from the top. You should create 16 versions of the image rotated around its center, i. e., one for every 22.5 degrees around the circle. Hint: create each new image from the original and NOT from a previously rotated image. Multiple rotations will mess up the image.

Reference: Chapters 11, 12 and 21 of Java text.

You will need two racing cars with the same 16 views. Make sure you can distinguish the two cars. Be creative in the design of your cars!

Write a Java application that spins your two cars. You can see my solution by running:

        cd ~cs355/Racecar
        java Spin 50

where 50 is the time in milliseconds for the animation delay. I suggest you try different values of this command line argument.

Hand in: You should hand in a print of the working Java code and a snap shot of the output.

Phase 2: Start the Race Track - Due Wednesday February 14, 2007

In the second phase, create a Java application for a race track where you can "drive" your two cars on one workstation.

The race track is in a window 850 pixels by 650 pixels and uses the following code:

        Color c1 =;
	g.setColor( c1 );
	g.fillRect( 150, 200, 550, 300 );

	Color c2 =;
	g.setColor( c2 );
	g.drawRect(50, 100, 750, 500);  // outer edge
	g.drawRect(150, 200, 550, 300); // inner edge

        Color c3 = Color.yellow;
	g.setColor( c3 );
	g.drawRect( 100, 150, 650, 400 );

        Color c4 = Color.white;
	g.setColor( c4 );
	g.drawLine( 425, 500, 425, 600 );

to create the track. To see the track, run the following:

        cd ~cs355/Racecar
        java Track

Select four keys for each of the two players. Two keys are used to change the direction of their car. A key press turns the car 22.5 degrees left or right. The other two keys are to change the speed of their car. The speed is an integer value from 0 to 100. One press of a key either increases the speed by 10 or decreases the speed by 10. The screen motion of a car is defined to be speed/10 pixels per 100 milliseconds of animation.

Write a Java application that allows two people to drive the two cars around the racetrack. You may add additional graphical features to the track to make it visually more interesting.

You should add collision detection between a car and the walls of the racetrack and between the two cars. In the event of a collision of a wall, the car crashes and its speed becomes 0. The other car can proceed. In the event that both cars collide, both cars crash and there is no winner. Add a Restart option as a menu item to allow the race to start over.

You may add sounds to your animation if you would like.

Hand in: Hand in a print of the working Java code and snap shots of the output.

Phase 3: Race Cars on Two Workstations - Due Tuesday February 27, 2004

The idea here is to have a server and two clients to allow each player to drive his or her race car on a different Linux workstation.

Purpose: To design a client/server application.

This phase is written in the context of many client/server applications. Many design issues are asked when designing a client/server application. Below are some.

General Client/Server Design Issues:

  1. What functionally is performed on the server? Does the server need to interact with a database or legacy software? Does it provide centralized services?

    In this phase you are to use as much of Phase 2 as possible. Therefore, the two clients perform most of the functionality. The server only provides the communication pipe between the two clients.

  2. What functionally is performed on the client? What user interface needs to be provided?

    A user can only control his or her own car with four keys. When one person drives his or her car, the motion of the car should appear on both workstation's screens. If the two cars collide, the game is over and both clients need to be notified. Allow either player to restart or exit the game from a menu.

  3. How many clients? And what categories of clients?

    In this phase we have two clients.

  4. What message protocols are needed? What does each type of message look like? What events cause a message? Does the application need a secure channel?

    You will need to give careful thought on how to do this. We will ignore the issue of security.

  5. How to get the application started? Is authentication of clients/users needed?

    You will need to start the server first. Allow either client to connect first. After both clients have connected and the imagess of the cars are loaded, you will need a way to start the race.

  6. How to close the application down?

    If a user exits in the middle of a race, the client should inform the server then the server can inform the other client to exit as well.

  7. How many applications can run simultaneously?

    Here we assume only one game (2 cars racing) at a time.

  8. How to coordinate the server and the clients?

    You can't have a client send a request and the server not respond. If you do, the application will lockup.

We will try out our race cars in our class's lab on Tuesday February 27th. I will grade them then. Hand in the Java code for the client and the server.

Page maintained by Dan Hyde, hyde at Last update January 31, 2007

Back to CSCI 355 Home Page.