Game Development Reference
In-Depth Information
// Update the display.
updateDisplay();
// Fire the flamethrower using a Timer object.
gameTimer.start();
}
The GasTankSimulator class declares an inner class named GameUpdater . The Timer is set up
to call the actionPerformed method declared in the GameUpdater class every 0.1 seconds to
update the temperature distribution inside the gas tank. Because there is a closed-form solution to
the 1-D heat conduction equation, there is no need to use an ODE solver in this simulation. The
time value is incremented, and then the inner wall temperature of the tank at this time is deter-
mined by calling the getTemperature method on the GasTank object.
class GameUpdater implements ActionListener {
public void actionPerformed(ActionEvent event) {
// Compute the new inner wall temperature.
double timeIncrement = 0.1;
time = time + timeIncrement;
innerWallTemp = tank.getTemperature(tank.getThickness(),time);
The display is updated with the new time and inner wall temperature values. If the inner
wall temperature exceeds the ignition temperature of gasoline, the simulation stops.
// Update the display.
updateDisplay();
// Update the output data textfields.
timeTextField.setText(""+(float)time);
innerTempTextField.setText(""+(int)innerWallTemp);
// If the inner wall temperature exceeds the ignition
// temperature of gasoline, stop the simulation.
if ( innerWallTemp > 550.0 ) {
gameTimer.stop();
}
}
}
Play around with different flame temperatures and tank thicknesses and see how the vari-
ations affect the time it takes the gas tank to explode. You will notice that initially the inner wall
temperature remains at 300 K . After a short time, the rate of change of inner wall temperature
increases fairly rapidly before tapering off again. The user has two options for tank material.
Aluminum is a good conductor with a thermal diffusivity of 9.975 e - 5 m 2 /s . Concrete, on the other
hand, is a fairly good insulator and has a much lower thermal diffusivity value of 6.6 e - 7 m 2 /s . If you
select a concrete gas tank, you will notice that it takes significantly longer for the inner tank
temperature to begin to rise than it does with an aluminum tank.
Search WWH ::




Custom Search