I was wondering how a player makes an object attack one another.
Let's say that a card has a certain attack value.
I want it so that once the cards are "deployed", you can attack another card by clicking both of them.
However, I can't find a way to make it attack because I don't know how to reduce their health by the attack variable.
This is my cards class. Each player will have different sets of cards. Friendly fire is okay, so I'm wondering how to make them attack.
How can I make it so that they are able to attack one another once "deployed"?
Any help would be greatly appreciated.
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;
int limit;
public void act()
{
//CardImage();
if (click == false)
{
Generation();
click = true;
}
if(visible == true && getY() > 285)
{
mouseDragging();
Deployment();
}
if(visible == true && getY() < 285)
{
mouseDragging();
Deployment();
}
if(!Dep && Deployment)
{
Position();
position++;
Dep = true;
}
}
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;
}
}
public boolean DeploymentBoolean()
{
return Deployment;
}
public void Position()
{
if(limit < 8)
{
setLocation(130, 300);
while (isTouching(Cards.class)) move(50);
CardSounds[number].play();
limit++;
}
}
}
