Is there a better way to do this:
That's a method that I'm working on for my compsci class... anyone know a more efficient way to do that? mainly just the
part, but any help or pointers with the rest would be appreciated too.
Code:
// attackable[] is a array of Country objects. it is variable in length
public boolean canAttack(Country c)
{
int x;
for(x = 0; (attackable[x] != c)&&(x < attackable.length); x++){};
if((x < attackable.length) && (attackable[x] == c))
{
if(c.getOwner() == owner)
return false;
else
return true;
} else
return false;
}
Code:
int x;
for(x = 0; (attackable[x] != c)&&(x < attackable.length); x++){};
if((x < attackable.length) && (attackable[x] == c))
Comment