I am wondering how to check if a certain card has been "deployed" on a board.
On my card class, I have this:
On my player class, I have this:
What happens is that if a player drags a card into the field, it gets "deployed".
I want to reduce the CurrentMana variable by a certain amount depending on the cost of the card.
Can anyone please tell me how to do it?
import greenfoot.*;
/**
* Write a description of class Ogre here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Cards extends Actor
{
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;
int NormalHeight = CardImages[number].getHeight();
int NormalWidth = CardImages[number].getWidth();
int position = 1;
int val;
public void act()
{
//CardImage();
if (click == false)
{
Generation();
click = true;
}
if(visible == true && getY() > 285)
{
mouseDragging();
Deployment();
}
if(visible == true && getY() < 285)
{
mouseDragging();
Deployment();
}
}
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 = 8;
attack = 4;
health = 9;
return 8;
case 1:
cost = 0;
attack = 1;
health = 1;
return 0;
case 2:
cost = 7;
attack = 9;
health = 5;
return 7;
case 3:
cost = 6;
attack = 6;
health = 7;
return 6;
case 4:
cost = 2;
attack = 3;
health = 2;
return 2;
case 5:
cost = 1;
attack = 2;
health = 1;
return 1;
}
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 Mousey = Greenfoot.getMouseInfo();
setLocation(Mousey.getX(), Mousey.getY());
return;
}
if (Greenfoot.mouseDragEnded(this) && Grab)
{
Grab = false;
return;
}
}
public void Deployment()
{
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)
{
MouseHover = false;
CardImages[number].scale(NormalWidth / 2, NormalHeight / 2);
Deployment = true;
}
if(Deployment)
{
if(position == 6) return;
setLocation(43 + (50*(position+1)^2), 300);
position++;
CardSounds[number].play();
OnBoard = true;
return;
}
}
public boolean DeploymentBoolean()
{
return Deployment;
}
}
public void Deployment()
{
//What do I fill here?
for (Cards Card : playerCards) Card.DeploymentBoolean();
}