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.
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.
The race track is in a window 850 pixels by 650 pixels and uses the following code:
Color c1 = Color.green; g.setColor( c1 ); g.fillRect( 150, 200, 550, 300 ); Color c2 = Color.black; 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.
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:
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.
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.
In this phase we have two clients.
You will need to give careful thought on how to do this. We will ignore the issue of security.
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.
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.
Here we assume only one game (2 cars racing) at a time.
You can't have a client send a request and the server not respond. If you do, the application will lockup.