So I am having a problem. My program is a very Fire Emblem-esque type game, similar to chess with stats. The Enemies and Allies have to Intersect on the board for one of them to be able to attack. I have 2 subclasses, Enemies and Allies, each with many subclasses of their own. Each subclass of those two, or units, have two unique stats, Health and Attack. I have gotten it to the point where it will return the unit(enemy) an ally is intersecting, but I cant figure out how to subtract the two stats. The is what I am having trouble with specifically.
(all the rest of the code)
Thanks so much in advance!!!!
if( "yes".equals(WillAttack))
{
getIntersectingEnemies().Health - MasterSwordsman.Attack;
}public class MasterSwordsman extends Allies
{
public void act()
{
if(Greenfoot.isKeyDown("0"))
{
askaction();
}
}
public int Health = 17;
public int Attack = 19;
String Action;
Actor Enemy;
public void askaction()
{
Action = Greenfoot.ask("What would you like the swordsman to do?");
if ("move".equals(Action) &! "attack".equals(Action))
{
String MovementSpace = Greenfoot.ask("how many spaces would you like to move the swordsman?");
int moveAmount = Integer.parseInt(MovementSpace);
String MoveDirection = Greenfoot.ask("What direction? (up, left, right, or down)");
if( "up".equals(MoveDirection))
{
setLocation(getX(), getY() - moveAmount);
}
if( "left".equals(MoveDirection))
{
move(-moveAmount);
}
if( "down".equals(MoveDirection))
{
setLocation(getX(), getY() + moveAmount);
}
if( "right".equals(MoveDirection))
{
move(moveAmount);
}
if("move".equals(Action) && "attack".equals(Action))
{
if (canAttack() != false)
{
String WillAttack = Greenfoot.ask("Would you like to attack the unit?");
if( "yes".equals(WillAttack))
{
getIntersectingEnemies().Health - MasterSwordsman.Attack;
}
}
}
Greenfoot.stop();
}
}
public Actor getIntersectingEnemy()
{
Actor Enemy = getOneIntersectingObject(Enemies.class);
return(Enemies)getOneIntersectingObject(Enemies.class);
}
public boolean canAttack()
{
boolean unit = isTouching(Enemies.class);
if(unit != false)
{
return true;
}
else
{
return false;
}
}
