To achieve an effect today, each object may have several effects of blood reduction, that is, a blood reduction value is floating up
Vector is the first choice because the maximum value is unknown.
Paste the basic code first:
/***//**
* Administrators with reduced blood Effects
* @ Author OK
*
*/
Public class decbloodmanager ...{
Vector vbloods;
Public decbloodmanager (tank )...{
Vbloods = new vector ();
}
/***//**
* Render all blood loss
* @ Param g
* @ Param ox
* @ Param Oy
*/
Public void render (Graphics g, int ox, int Oy )...{
Decblood DB = NULL;
For (INT I = vbloods. Size (); -- I> = 0 ;)...{
DB = (decblood) vbloods. elementat (I );
DB. Render (G, ox, Oy );
}
}
Public void add (decblood dB )...{
Vbloods. addelement (db );
}
Public void remove (decblood dB )...{
Vbloods. removeelement (db );
}
Public void clear ()...{
Vbloods. removeallelements ();
}
}
/***//**
* Blood Reduction Effect
* @ Author OK
*
*/
Public class decblood ...{
Decbloodmanager dBm;
Private int X, Y;
Private int lifecounter;
Public decblood (decbloodmanager dBm )...{
This. DBM = dBm;
}
Public void setposition (INT wx, int WY )...{
X = wx;
Y = WY;
}
Public void setlifecounter (INT max )...{
Lifecounter = max;
}
Public void render (Graphics g, int ox, int Oy )...{
// Render
// Update
If (-- lifecounter <0 )...{
// Life over
DBm. Remove (this );
}
}
}
The basic idea is as follows:
Render all subnodes in the Manager, and update the status when each subnode is rendered. If the subnode reaches the specified time, it is automatically destroyed; that is, remove yourself from the manager;
However, after the vector operation is removed, the vector. Size () will be reduced immediately. Therefore, it may cause dislocation.
In this case, if ++ is used,
For (INT I = 0; I <v. Size (); I ++ );
This may cause potential risks;
However, if we use --, after removing one, we will only move the elements behind this index forward, and these elements are already round-robin, the previous elements that do not need to be moved are just the nodes that we haven't checked in this cycle;
It seems that sometimes "--" must be used!