Hello.
I was wondering how to assign a value to a card so that when the player selects a card, he can only do something with it if it's their OWN card.
This is my cards class:
This is my player class:
How do I make it so that a player can only select their own card once the Deployed variable is true?
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()
{
if (click == false)
{
Generation();
click = true;
}
mouseDragging();
Deployment();
if(!Dep && Deployment)
{
Position();
position++;
Dep = true;
}
/*if(Deployment && Dep)
{
if(Greenfoot.mouseClicked(this))
{
initialized = true;
}
if(initialized && Greenfoot.mouseClicked(null))
{
MouseInfo mouse = Greenfoot.getMouseInfo();
Actor mouseActor = mouse.getActor();
if(mouseActor!= null && mouseActor instanceof Cards)
{
setLocation(50,50);
}
}
}*/
if(Deployment && Greenfoot.mouseClicked(this))
{
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 = 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 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;
}
}
import greenfoot.*;
import javax.swing.JOptionPane;
import java.util.ArrayList;
import java.util.List;
/**
* Write a description of class Player here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Player extends Actor
{
boolean cardPossessed[] = new boolean[2];
//int[] Cards = new int[2];
private boolean click = false;
int health = 30;
SomeDice playerdice = new SomeDice();
int count = 0;
int number;
boolean button;
int position;
int CurrentMana;
int MaxMana;
int CardValue;
GreenfootImage[] playerImages ;
Cards[] playerCards = {new Cards(),new Cards(),new Cards(),new Cards(),new Cards(),new Cards()};
boolean dep;
public Player()
{
int CurrentMana = 0;
int MaxMana = 0;
}
public void CardSelect()
{
CurrentMana ++;
MaxMana++;
int number = 0;
int value = Greenfoot.getRandomNumber(6-position);
if (position == 6) return;
Cards card = playerCards[value];
if(getY() > 400)
{
getWorld().addObject(card, 40 + (50*(position+1)^2), getY()+60);
}
if(getY() < 400)
{
getWorld().addObject(card, 40 + (50*(position+1)^2), getY() -40);
}
position++;
playerCards[value] = playerCards[6-position];
playerCards[6-position] = card;
}
public void act()
{
String manaDisplay = Integer.toString(CurrentMana);
String mana = Integer.toString(MaxMana);
getWorld().showText(manaDisplay, 600, 550);
getWorld().showText("/" + mana, 620, 550);
}
public void hideCards()
{
for (Cards Card : playerCards) Card.hide();
}
public void showCards()
{
for (Cards Card : playerCards) Card.show();
}
}
