ballwar.model.strategy
Class ExplodeStrategy

java.lang.Object
  extended by ballwar.model.strategy.ANoOpStrategy
      extended by ballwar.model.strategy.ExplodeStrategy
All Implemented Interfaces:
IUpdateStrategy

public class ExplodeStrategy
extends ANoOpStrategy

An ANoOpStrategy-based strategy that, upon colliding with another ball, may replace its context with a number of smaller balls with the same strategy, unless the context's radius is below a minumum length, upon which the context is simply killed. The size and masses of the new balls are calculated to conservere total area and mass before and after the collision..


Field Summary
private static int _MinRadius
          The minimum radius that will explode.
private static int _NBalls
          The number of balls to explode into.
private static double _Prob
          The probability of explosion.
private static int _RadiusDivider
          The divisor of the radius when the ball explodes.
 
Fields inherited from interface ballwar.model.IUpdateStrategy
NullObject
 
Constructor Summary
ExplodeStrategy()
           
 
Method Summary
 void updateCollision(Ball context, Ball target)
          With a given probability, explodes the context ball into a number of smaller balls, unless the context's radius is below a minimum length, upon which the context is killed and no more balls are made.
 
Methods inherited from class ballwar.model.strategy.ANoOpStrategy
init, kill, updateState
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_Prob

private static double _Prob
The probability of explosion.


_MinRadius

private static int _MinRadius
The minimum radius that will explode. smaller radius will simply kill its context ball.


_NBalls

private static int _NBalls
The number of balls to explode into.


_RadiusDivider

private static int _RadiusDivider
The divisor of the radius when the ball explodes. Equals the square root of the number of balls in order to conserve area and hence, mass.

Constructor Detail

ExplodeStrategy

public ExplodeStrategy()
Method Detail

updateCollision

public void updateCollision(Ball context,
                            Ball target)
With a given probability, explodes the context ball into a number of smaller balls, unless the context's radius is below a minimum length, upon which the context is killed and no more balls are made.

Specified by:
updateCollision in interface IUpdateStrategy
Overrides:
updateCollision in class ANoOpStrategy
Parameters:
context - The strategy's context
target - The ball the context collided with.