I am trying to get the correct values for the card health, but it seems to be displaying the wrong value.
For example, the "ogre" card has a cost of 6, an attack of 6 and a health of 7.
However, the program is showing that it has only 5 health.
Even if theoretically the card is attacking itself (the losehealth method), it should only have one HP.
import greenfoot.*;
/**
* Write a description of class Ogre here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Cards extends Actor
{
private static Cards attacker;
SomeDice dice = new SomeDice();
int health;
int cost;
int attack;
int number;
boolean click;
boolean Selected;
public GreenfootSound[] CardSounds = { new GreenfootSound("KittyPlaySound.mp3"),
new GreenfootSound("HoundPlaySound.mp3"),
new GreenfootSound("OgrePlaySound.mp3"),
new GreenfootSound("RaptorPlaySound.mp3"),
new GreenfootSound("MurlocPlaySound.mp3"),
new GreenfootSound("GrommashPlaySound.mp3")};
public static final GreenfootImage[] CardImages = { new GreenfootImage("Kitty.png"),
new GreenfootImage("Hound.png"),
new GreenfootImage("Ogre.png"),
new GreenfootImage("Raptor.png"),
new GreenfootImage("Murloc.png"),
new GreenfootImage("Grommash.png")};
private boolean visible;
public GreenfootImage BackCard = new GreenfootImage("CardBack.png");
boolean Grab = false;
boolean MouseHover = false;
boolean Deployment = false;
boolean OnBoard = false;
boolean Dep = false;
boolean val = false;
boolean battleposition;
boolean initialized = false;
boolean attacked;
boolean Grabbed;
int NormalHeight = CardImages[number].getHeight();
int NormalWidth = CardImages[number].getWidth();
int position;
int limit;
int Cardvalue;
public void act()
{
int x = getX();
int y = getY();
String HP = Integer.toString(health);
if (click == false)
{
Generation();
click = true;
}
mouseDragging();
Deployment();
if(!Dep && Deployment)
{
Position();
position++;
Dep = true;
}
if(Deployment && Greenfoot.mouseClicked(this))
{
getWorld().showText(HP, x, y);
if (attacker == null) attacker = this;
else if(attacker != this)
{
loseHealth(attacker.attack);
if (health <= 0)
{
getWorld().removeObject(this);
}
attacker = null;
}
else attacker = null;
}
}
public void CardImage()
{
if(getY() > 400)
{
for (Object PlayerCards: getObjectsInRange(100, Cards.class))
{
Cards a = (Cards) PlayerCards;
a.setImage(BackCard);
}
}
if(getY() < 400)
{
for (Object PlayerCards: getObjectsInRange(100, Cards.class))
{
Cards a = (Cards) PlayerCards;
a.setImage(BackCard);
}
}
}
public int Generation()
{
number = dice.Roll(number);
CardImages[number].scale(NormalWidth / 2, NormalHeight / 2);
setImage(CardImages[number]);
switch(number)
{
case 0:
cost = 0;
attack = 1;
health = 1;
return cost;
case 1:
cost = 7;
attack = 9;
health = 5;
return cost;
case 2:
cost = 7;
attack = 9;
health = 5;
return cost;
case 3:
cost = 6;
attack = 6;
health = 7;
return cost;
case 4:
cost = 2;
attack = 3;
health = 2;
return cost;
case 5:
cost = 1;
attack = 2;
health = 1;
return cost;
}
return 10;
}
public void setVisible(boolean state)
{
visible = state;
if(!Deployment)
{
if(visible == true)
{
setImage(CardImages[number]);
}
else if (visible == false)
{
setImage(BackCard);
}
}
}
public void show()
{
setVisible(true);
}
public void hide()
{
setVisible(false);
}
public boolean isVisible()
{
return visible;
}
public void mouseDragging()
{
if (Greenfoot.mousePressed(this) && !Grab)
{
Grab = true;
return;
}
if ((Greenfoot.mouseDragged(this)) && Grab)
{
MouseInfo Mouse = Greenfoot.getMouseInfo();
setLocation(Mouse.getX(), Mouse.getY());
return;
}
if (Greenfoot.mouseDragEnded(this) && Grab)
{
Grab = false;
Grabbed = true;
return;
}
}
public void Deployment()
{
if(Deployment) return;
if (!MouseHover && Greenfoot.mouseMoved(this))
{
CardImages[number].scale(NormalWidth, NormalHeight);
MouseHover = true;
}
if (MouseHover && Greenfoot.mouseMoved(null) && ! Greenfoot.mouseMoved(this))
{
CardImages[number].scale(NormalWidth / 2, NormalHeight / 2);
MouseHover = false;
}
if(MouseHover && Greenfoot.mouseMoved(null) && Greenfoot.mouseMoved(this) && getY() < 400 && Grabbed)
{
MouseHover = false;
CardImages[number].scale(NormalWidth / 2, NormalHeight / 2);
Deployment = true;
}
}
public boolean DeploymentBoolean()
{
return Deployment;
}
public void Position()
{
if(limit < 8)
{
setLocation(130, 300);
while (isTouching(Cards.class)) move(50);
CardSounds[number].play();
limit++;
}
}
public void loseHealth(int damage)
{
health -= damage;
}
}

