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, KeyboardFocusManager.getCurrentKeyboardFocusManager().upFocusCycle(); is called to make sure the JFrame, not the button has the focus of the key events.

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.

Show off to your instructor by beating your partner handily.