IC211: Lab 12 - The last of Tron
This lab is to be done in pairs.
You should be familiar from class with the code for the moving dots.
Links to the code can be found here:
This code shows you how you can use components to launch threads, and
how those threads can maintain a simple animation.
I have enhanced this code slightly to make it even cooler:
You should compare the new version to the old. Note that in
Thing.java, in the constructor I load an image object, and in paint(),
instead of drawing a boring circle, it draws the image.
In Ex3.java, we now only initialize 2 Things. It also adds
StartActionListener as a "keyListener" to the JFrame.
In StartActionListener.java, the class now implements KeyListener as
well as ActionListener. See how the method keyReleased() adds a new
Thing to the ArrayList. Note how I could have also don't this in
keyPressed() or keyTyped(). See when running the program that hitting
most keys generates keyPressed() and keyReleased() events, but some
keys (like the arrow keys) do not generate keyTyped events. Finally,
notice how when the start buton is pressed,
is called to make sure the JFrame, not the button has the focus of the
Now you know enough to write a real game.
Realtime Tron Lightcycle game!!!
Write a striaghtforward Tron game (two players, both lightcycles,
always start in the same place) that is realtime and not turnbased.
Use the keylistener to get input from the players.
- Player 1 uses a,s,d,w, where a is left, s is down, d is up, and w is right.
- Player 2 uses j,k,l,i.
- If the player selects a direction he is already going, or a direction in the opposite of the direction he is going, nothing happens.
- Player 1 leaves a yellow trail.
- Player 2 leaves a blue trail.
- Each player will be represented by an appropriate gif or jpg.
- Like the example program, a start button will start/stop the game.
- The control panel area should also display the score in terms of
the number of times each player has won.
Show off to your instructor by beating your partner handily.