www.pudn.com > MobiCraft_src.rar > Force.java
// style: tabs, tabsize=4, style=ANSI
//+----------------------------------------------------------------------+
// Copyright (c) 2006 Company Name
// Made by Andrew and Zahar
//+----------------------------------------------------------------------+
// Filename: Force.java
//+----------------------------------------------------------------------+
// Comment: Force container. has 8 units
//+----------------------------------------------------------------------+
package battle;
import java.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
public class Force
{
// First line counting from up. Then second line counting from up
public Unit[] mUnit;
// Если войско слева - то true, если справа, то false.
public boolean bLeft;
public Force()
{
mUnit = new Unit[8];
for (int i=0; i<8; i++)
mUnit[i] = new Unit();
}
public void Init( boolean bleft)//, Battle mBattle)
{
bLeft = bleft;
//for (int i=0; i<8; i++)
//mUnit[0].Init(Unit.UNIT_P_DARK, !bLeft, mBattle.mUnitAnimator);
}
//20061205 Black Всюду добавил проверку на неNULLевость юнита
public void Draw(Graphics g, int x, int y)
{
if (bLeft)
{
for (int i=0; i<4; i++)
if (mUnit[i] != null) {mUnit[i].Draw(g, x+40, y+i*40);}
for (int i=4; i<8; i++)
if (mUnit[i] != null) {mUnit[i].Draw(g, x, y+(i-4)*40);}
}
else
{
for (int i=0; i<4; i++)
if (mUnit[i] != null) {mUnit[i].Draw(g, x, y+i*40);}
for (int i=4; i<8; i++)
if (mUnit[i] != null) {mUnit[i].Draw(g, x+40, y+(i-4)*40);}
}
}
// To let to free memory in UnitStorage
public void Destroy()
{
for (int i=0; i<8; i++)
if (mUnit[i] != null) {mUnit[i].Destroy();}
}
public void DoTimeStep(long dt)
{
for (int i=0; i<8; i++)
if (mUnit[i] != null)
{
mUnit[i].DoTimeStep(dt);
}
}
}