I have a CardSelect() method for my hearthstone clone that adds a random card into the field.
However, when this method is called in act(), it runs it multiple times per second.
This is my Cards class:
Here is how I call cardselect:
Now, if I don't do the if statement when I try to call CardSelect, it gives me multiple images. When I do the if statement, it does not give me an image at all.
So how can I make it so that it only gives me one image and stays there? Without the if statement in the act method, it loops and gives me a whole bunch of images for one card.
public void CardSelect()
{
if(getY() > 400 && Greenfoot.mouseClicked(this))
{
int value = Greenfoot.getRandomNumber(5);
getWorld().addObject(playerCards[value], 150 * value^2, 320);
return;
}
} public void act()
{
Generation();
}
public void Generation(){
number = dice.Roll(number);
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")};
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")};
setImage(CardImages[number]);
//CardSounds[number].play();
}public void act()
{
if (Greenfoot.mouseClicked(this))
{
if (click == false){
CardSelect();
click = true;
}
}
}
