Okay, I'm trying to streamline my different ores by making a parent class called ore with all the common functions. I'm testing it using my copper class so I can revert it back if things don't go well.
How can I call two+ different classes from the same function in the parent class of ore? If any of that did not make any sense, I apologize. If you need clarification feel free to ask, I'd be more than happy to further explain.
Ore
Copper
/**
* Tell us how much ore is left in this vein.
*/
public void checkAmount(String oreType, Object oreType2)
{
MouseInfo mouse = Greenfoot.getMouseInfo();
if(ore > 999){
oreDisp = String.format("%.02f",(ore/1000)) + "k";
}else{
oreDisp = Integer.toString((int) ore);
}
if (checkHitBox(oreType2) && info == null)
{
info = new Label("\n " + oreType + ": " + oreDisp + " \n ", 24);
getWorld().addObject(info, mouse.getX(), mouse.getY()-20);
}
else if (checkHitBox(oreType2) == false)
{
getWorld().removeObject(info);
info = null;
}
else if (Greenfoot.isKeyDown("f") && checkHitBox(oreType2))
{
getWorld().removeObject(info);
info = null;
info = new Label("\n " + oreType + ": " + oreDisp + " \n ", 24);
getWorld().addObject(info, mouse.getX(), mouse.getY()-20);
}
}
/**
* Making sure the mouse is within the bounds of the ore.
*/
private boolean checkHitBox(Object oreType2){
MouseInfo mouse = Greenfoot.getMouseInfo();
if(mouse == null){
return false;
}
if(ore < 11){
return false;
}
if(
mouse.getX() >= iron.getX()-(SIZE/2) &&
mouse.getY() >= iron.getY()-(SIZE/2) &&
mouse.getX() <= iron.getX()+(SIZE/2) &&
mouse.getY() <= iron.getY()+(SIZE/2)
){
return true;
}else{
return false;
}
}/**
* Tell us how much ore is left in this vein.
*/
public void act(){
super.checkAmount("Copper", this);
}



