group1.model.gameobject
Class InvincibilityHandler

java.lang.Object
  extended by group1.model.gameobject.InvincibilityHandler

public class InvincibilityHandler
extends java.lang.Object

A singleton class that handles temporary invicincibility. Holds a set of invincible living game objects, which can be referenced whenever something might take damage. Invincibility is handled via a simple counter in the LivingObj class, based on the number of time clicks that pass. The Environment must tell this class when time clicks occur, and this info is passed to the appropriate living objects. This is actually a very important detail!!! Otherwise, objects would hit each other thousands of times in the span of mere seconds. On a side note, the reason that I'm making a spearate class for this: -- I can't put in GameObj because not all GameObjs can take damage, or even have appropriate code. -- I could put in the subclasses, but I would have to put it in the move() function of every subclass. Not good. -- I can't put it LivingObj because there's no clean way to decrement the counter every time click without class-casting left and right. But, here, I can manage a list of LivingObjs, so that no messing class-casting is required.


Method Summary
static InvincibilityHandler getInstance()
          Get an instance of this class.
static boolean setInvincible(LivingObj obj)
          Add a object to our list to make it invincible.
static void timeClick()
          Run a time click of invincibility counters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static InvincibilityHandler getInstance()
Get an instance of this class. (Singleton design pattern.)

Returns:
An instance of this class.

setInvincible

public static boolean setInvincible(LivingObj obj)
Add a object to our list to make it invincible.

Parameters:
obj - The oject to be added to the "invincible" list.
Returns:
true if it was successful, false if it was already there.

timeClick

public static void timeClick()
Run a time click of invincibility counters. (Decrement the counters of all currently invincible objects.)